Update wikilink syntax

This prevents interference with markdown tables
This commit is contained in:
2026-05-07 07:55:33 +02:00
parent dc79557bdb
commit 0a30325b96
3 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -93,7 +93,7 @@
onSelect: function (path, kind) { onSelect: function (path, kind) {
if (kind === 'folder') { if (kind === 'folder') {
promptDisplayText(sel, function (display) { promptDisplayText(sel, function (display) {
insertAtCursor(display ? '[[' + path + '|' + display + ']]' : '[[' + path + ']]'); insertAtCursor(display ? '[[' + path + '::' + display + ']]' : '[[' + path + ']]');
}); });
} else { } else {
var name = path.split('/').pop(); var name = path.split('/').pop();
+2 -2
View File
@@ -147,7 +147,7 @@ func validateAndNormalizeNewPath(raw string) (string, error) {
} }
// rewriteWikiLinks returns (newContent, changed). Any [[target]] or // 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. // has its target rewritten to the corresponding position under newPath.
func rewriteWikiLinks(content []byte, oldPath, newPath string) ([]byte, bool) { func rewriteWikiLinks(content []byte, oldPath, newPath string) ([]byte, bool) {
changed := false changed := false
@@ -170,7 +170,7 @@ func rewriteWikiLinks(content []byte, oldPath, newPath string) ([]byte, bool) {
changed = true changed = true
suffix := "" suffix := ""
if len(parts[2]) > 0 { if len(parts[2]) > 0 {
suffix = string(parts[2]) suffix = "::" + string(parts[2])
} }
return []byte("[[" + newTarget + suffix + "]]") return []byte("[[" + newTarget + suffix + "]]")
}) })
+5 -4
View File
@@ -16,14 +16,15 @@ import (
"github.com/yuin/goldmark/util" "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 // of the current inline reader. Target and display forbid newlines and
// brackets; target additionally forbids the pipe separator. // brackets; the target is non-greedy so the first `::` separates target from
var wikiLinkRe = regexp.MustCompile(`^\[\[([^\[\]\|\n]+)(?:\|([^\[\]\n]+))?\]\]`) // display when both are present.
var wikiLinkRe = regexp.MustCompile(`^\[\[([^\[\]\n]+?)(?:::([^\[\]\n]+))?\]\]`)
// wikiLinkPattern matches wiki-link tokens anywhere in a markdown source. // wikiLinkPattern matches wiki-link tokens anywhere in a markdown source.
// Used by the move-endpoint rewriter; not by the goldmark parser. // 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. // wikiLinkNode is the AST node produced by wikiLinkParser.
type wikiLinkNode struct { type wikiLinkNode struct {