Skip to content

fix: skip link syntax inside code when extracting links - #49

Open
radish-miyazaki wants to merge 2 commits into
okfcli:mainfrom
radish-miyazaki:fix/skip-code-in-link-extraction
Open

radish-miyazaki wants to merge 2 commits into
okfcli:mainfrom
radish-miyazaki:fix/skip-code-in-link-extraction

Conversation

@radish-miyazaki

Copy link
Copy Markdown

What

extractLinks now scans a copy of the body masked by maskCode, so [text](target) inside inline code spans and fenced code blocks is no longer treated as a link.

Why

Go code that calls a generic function with an explicit type argument, such as errors.AsType[*E](err), has the [...](...) shape. When it appears in documentation, validate reported it as okf/links/broken (an ERROR before #33, a WARN since). See #48 for the repro.

#33 added maskCode so that footnote scanning skips code (#26). This change applies the same masking to link extraction.

How

  • extractLinks finds [, ], ( and ) in the masked copy. maskCode preserves byte offsets, so text and target are still sliced from the original body. A link whose text contains code, such as [`cfg`](cfg.md), keeps its original text.
  • graph and backlinks call ExtractLinks, so they stop seeing these false links too.
  • Updated the maskCode doc comment and added one sentence to the README's validation section.

Tests

Regression tests, written first and failing before the fix:

  • TestExtractLinks_IgnoresCode: inline code and a fenced block yield no links; a real link and a link with code in its text are still extracted with their original text.
  • TestValidate_LinkInCodeIgnored: no broken link finding for code-only link syntax.

Local checks:

gofmt -l .            # no output
go vet ./...
go build ./...
go test -race ./...
golangci-lint run     # v2.15.0, 0 issues
govulncheck ./...     # No vulnerabilities found.

Closes #48

Drafted with Claude Code, reviewed and tested locally.

🤖 Generated with Claude Code

radish-miyazaki and others added 2 commits November 25, 2026 04:43
extractLinks scanned the raw body for [text](target), so Go code such as
errors.AsType[*E](err) inside an inline code span or a fenced code block
was reported as a broken link. Scan a copy masked by maskCode, the same
masking footnote scanning has used since okfcli#33. maskCode preserves byte
offsets, so text and target are still sliced from the original body.

graph and backlinks call ExtractLinks, so they stop seeing these false
links too.

Closes okfcli#48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also shorten the extractLinks doc comment; maskCode's comment already
explains why code is masked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

validate: Markdown links are extracted from inside code spans and fenced code blocks

1 participant