From 0a30325b96fa34fd0922b5581b9be8a944b9b955 Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 7 May 2026 07:55:33 +0200 Subject: [PATCH] Update wikilink syntax This prevents interference with markdown tables --- assets/editor.js | 2 +- moves.go | 4 ++-- wikilinks.go | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/editor.js b/assets/editor.js index 390b3e1..4be5a5f 100644 --- a/assets/editor.js +++ b/assets/editor.js @@ -93,7 +93,7 @@ onSelect: function (path, kind) { if (kind === 'folder') { promptDisplayText(sel, function (display) { - insertAtCursor(display ? '[[' + path + '|' + display + ']]' : '[[' + path + ']]'); + insertAtCursor(display ? '[[' + path + '::' + display + ']]' : '[[' + path + ']]'); }); } else { var name = path.split('/').pop(); diff --git a/moves.go b/moves.go index b07de55..4515819 100644 --- a/moves.go +++ b/moves.go @@ -147,7 +147,7 @@ func validateAndNormalizeNewPath(raw string) (string, error) { } // rewriteWikiLinks returns (newContent, changed). Any [[target]] or -// [[target|display]] whose target equals oldPath or begins with oldPath+"/" +// [[target::display]] whose target equals oldPath or begins with oldPath+"/" // has its target rewritten to the corresponding position under newPath. func rewriteWikiLinks(content []byte, oldPath, newPath string) ([]byte, bool) { changed := false @@ -170,7 +170,7 @@ func rewriteWikiLinks(content []byte, oldPath, newPath string) ([]byte, bool) { changed = true suffix := "" if len(parts[2]) > 0 { - suffix = string(parts[2]) + suffix = "::" + string(parts[2]) } return []byte("[[" + newTarget + suffix + "]]") }) diff --git a/wikilinks.go b/wikilinks.go index e8e7518..a88b2c2 100644 --- a/wikilinks.go +++ b/wikilinks.go @@ -16,14 +16,15 @@ import ( "github.com/yuin/goldmark/util" ) -// wikiLinkRe matches [[target]] and [[target|display]] anchored at the start +// wikiLinkRe matches [[target]] and [[target::display]] anchored at the start // of the current inline reader. Target and display forbid newlines and -// brackets; target additionally forbids the pipe separator. -var wikiLinkRe = regexp.MustCompile(`^\[\[([^\[\]\|\n]+)(?:\|([^\[\]\n]+))?\]\]`) +// brackets; the target is non-greedy so the first `::` separates target from +// display when both are present. +var wikiLinkRe = regexp.MustCompile(`^\[\[([^\[\]\n]+?)(?:::([^\[\]\n]+))?\]\]`) // wikiLinkPattern matches wiki-link tokens anywhere in a markdown source. // Used by the move-endpoint rewriter; not by the goldmark parser. -var wikiLinkPattern = regexp.MustCompile(`\[\[([^\[\]\n\|]+)(\|[^\[\]\n]+)?\]\]`) +var wikiLinkPattern = regexp.MustCompile(`\[\[([^\[\]\n]+?)(?:::([^\[\]\n]+))?\]\]`) // wikiLinkNode is the AST node produced by wikiLinkParser. type wikiLinkNode struct {