Skip to content

fix(links): ignore [[ ]] wiki-link syntax inside code blocks#1202

Merged
perber merged 1 commit into
perber:mainfrom
mvanhorn:fix/1200-wikilink-codeblock-exclusion
Jun 25, 2026
Merged

fix(links): ignore [[ ]] wiki-link syntax inside code blocks#1202
perber merged 1 commit into
perber:mainfrom
mvanhorn:fix/1200-wikilink-codeblock-exclusion

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

extractWikiLinksFromMarkdown in internal/links/helpers.go ran the [[Target]] wiki-link regex over the entire raw page content with no awareness of code blocks. As a result, bash [[ ... ]] test expressions inside fenced or inline code were parsed as wiki-links and produced spurious "Broken links" records.

This change excludes code spans and code blocks from wiki-link extraction by reusing the goldmark-AST exclusion machinery that already exists in the same package for the link-rewrite engine.

Why this matters

Saving a page whose body contains a bash code block such as:

if [[ -n "$computed_hash" && -n "$src_hash" ]]; then

previously generated false "Broken links" entries pointing at fragments like -n "$computed_hash" && -n "$src_hash" and "$src_hash" == sha256-* (reported in #1200). These are shell test expressions, not wiki-links, and should never have been indexed.

Changes

  • internal/links/helpers.go: extractWikiLinksFromMarkdown now computes excluded code ranges once via NewMarkdownRefactorEngine().collectExcludedRanges(content) (the existing goldmark walk over *ast.CodeSpan / *ast.FencedCodeBlock / *ast.CodeBlock), switches from FindAllStringSubmatch to FindAllStringSubmatchIndex, and skips any match whose [[ start offset falls inside an excluded range via isExcludedOffset. Trimming, empty-skip, ordering, and dedup behavior for real wiki-links outside code is unchanged.
  • internal/links/link_service_test.go: added regression tests for fenced bash code blocks (the exact error comes with certain text #1200 repro), inline code spans, mixed real-link-plus-code-block bodies, and indented code blocks.

Testing

go vet ./internal/links/...
go build ./...
go test ./internal/links/...

All pass. The new tests fail before the fix (the #1200 bash snippet yields two false targets) and pass after.

Note: this addresses the backend "Broken links" false-positive half of #1200. The separate client-side KaTeX preview parse error is rendered in the React/KaTeX frontend and is out of scope for this Go change.

Refs #1200

@mvanhorn
mvanhorn requested a review from perber as a code owner June 25, 2026 11:58
@mvanhorn

Copy link
Copy Markdown
Contributor Author

This addresses the backend half of #1200: bash [[ ... ]] test expressions inside fenced or inline code blocks were being parsed as broken wiki-links. The fix reuses the package's existing goldmark code-exclusion machinery so only real [[Title]] links outside code are indexed. The client-side KaTeX preview parse error noted in the issue is separate (frontend) and out of scope here.

@perber

perber commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@mvanhorn Thanks for you PR. I guess I missed it. I will merge it. It should be part of the upcoming v0.11.2 release with the frontend fix.

@perber
perber merged commit 0704e83 into perber:main Jun 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants