fix(links): ignore [[ ]] wiki-link syntax inside code blocks#1202
Merged
perber merged 1 commit intoJun 25, 2026
Conversation
Contributor
Author
|
This addresses the backend half of #1200: bash |
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
approved these changes
Jun 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extractWikiLinksFromMarkdownininternal/links/helpers.goran 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:
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:extractWikiLinksFromMarkdownnow computes excluded code ranges once viaNewMarkdownRefactorEngine().collectExcludedRanges(content)(the existing goldmark walk over*ast.CodeSpan/*ast.FencedCodeBlock/*ast.CodeBlock), switches fromFindAllStringSubmatchtoFindAllStringSubmatchIndex, and skips any match whose[[start offset falls inside an excluded range viaisExcludedOffset. 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
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