Missing changes

This commit is contained in:
2026-07-24 16:10:44 +02:00
parent 52bc694ffa
commit 65983ec6be
5 changed files with 77 additions and 6 deletions
+27 -4
View File
@@ -115,6 +115,23 @@ func wikiTargetHref(target string) string {
return b.String()
}
// wikiFileHref converts a wiki target to a URL href for the raw file: each
// segment is percent-encoded and, unlike wikiTargetHref, no trailing slash is
// appended. Used for image-embed click-through so the href points straight at
// the file (companion click-interception skips anything ending in "/").
func wikiFileHref(target string) string {
target = normalizeWikiTarget(target)
if target == "/" {
return "/"
}
var b strings.Builder
for _, seg := range strings.Split(strings.TrimPrefix(target, "/"), "/") {
b.WriteByte('/')
b.WriteString(url.PathEscape(seg))
}
return b.String()
}
// wikiTargetExists reports whether the on-disk path backing the target exists
// under root. Any existing path — file or folder — counts as resolved; only a
// missing path is treated as broken.
@@ -148,13 +165,20 @@ func (r *wikiLinkRenderer) render(w util.BufWriter, source []byte, node ast.Node
return ast.WalkContinue, nil
}
n := node.(*wikiLinkNode)
target := string(n.Target)
writeWikiLink(w, r.root, string(n.Target), string(n.Display))
return ast.WalkContinue, nil
}
// writeWikiLink renders a wiki-link anchor for target with an optional display
// override. An empty display falls back to the target's last segment; a target
// that does not resolve on disk gets the `broken` class. Shared by the wiki-link
// renderer and the embed renderer's link fallback.
func writeWikiLink(w util.BufWriter, root, target, display string) {
href := wikiTargetHref(target)
display := string(n.Display)
if display == "" {
display = wikiDefaultDisplay(target)
}
broken := !wikiTargetExists(r.root, target)
broken := !wikiTargetExists(root, target)
w.WriteString(`<a href="`)
w.WriteString(href)
@@ -165,7 +189,6 @@ func (r *wikiLinkRenderer) render(w util.BufWriter, source []byte, node ast.Node
w.WriteString(`>`)
w.Write(util.EscapeHTML([]byte(display)))
w.WriteString(`</a>`)
return ast.WalkContinue, nil
}
type wikiLinkExt struct{ root string }