docmd icon indicating copy to clipboard operation
docmd copied to clipboard

[Bug]: validate reports links with a title and links inside code blocks as broken

Open vishalhabib99 opened this issue 1 month ago • 2 comments

docmd version

0.9.7 (main at fdae951)

Node.js version

v24.20.0

OS/Browser

macOS (CLI/MCP, no browser involved)

Description

validate_docs (MCP) and docmd validate report two kinds of valid content as broken links:

  1. A link with a title, e.g. [install guide](guides/install.md "Install docmd"). The title is treated as part of the path.
  2. Links inside fenced code blocks. Example links in a code sample get checked as real links.

Cause (at fdae951): validateLinks in packages/core/src/commands/mcp.ts:128-131 matches each line with /\[([^\]]+)\]\(([^)]+)\)/g and uses the whole (...) content as the target, so guides/install.md "Install docmd" is resolved as a file name. Lines are checked one by one with no fence tracking, so lines inside ``` blocks are not skipped. docmd validate uses the same function (packages/core/src/commands/validate.ts:40).

Suggested fix:

  • Take the target as the text before the first whitespace (and strip <...> around it), which drops an optional "title" / 'title'.
  • Track ``` / ~~~ fence state while iterating lines and skip lines inside a fence.

Open PR #256 (for #250 and #251) changes the regex on line 128. Should this be folded into #256, or handled separately after it lands?

Steps to Reproduce

  1. docs/guides/install.md exists.
  2. docs/index.md:
# Home

See the [install guide](guides/install.md "Install docmd") for setup.

Also see [usage](guides/usage.md).

```md
Example of a link in a code sample: [my page](./not-a-real-page.md)
```
  1. Run docmd validate, or call the MCP tool validate_docs {}.

Output:

Validation errors found:
[docs/index.md:3] -> guides/install.md "Install docmd" (Broken link: target resolved to docs/guides/install.md "Install docmd" does not exist)
[docs/index.md:8] -> ./not-a-real-page.md (Broken link: target resolved to docs/not-a-real-page.md does not exist)

Expected Behavior

No errors. Line 3 points to an existing file (the title is not part of the path), and line 8 is inside a code block.

vishalhabib99 avatar Oct 12 '26 23:10 vishalhabib99

Thanks for the detailed report @vishalhabib99! The related MCP stdout fix has landed in v0.9.8 via PR #260.

The two bugs here are still open for a follow-up fix:

  • Link title stripping — e.g. [text](page.md "Title") falsely flagging the title as part of the path.
  • Code-fence skipping — links inside ```` blocks should not be validated.

PR #256 already addressed the empty alt-text regex on the same code path. These two remaining items will be tracked for the next patch release.

mgks avatar Oct 14 '26 08:10 mgks

Resolved in commit e0e77858 (with follow-up cleanup in 5a64a6f1). Both link title stripping and fenced code-block skipping are now implemented in the link validator with comprehensive regression tests.

mgks avatar Oct 14 '26 09:10 mgks