module

Hwaro::Utils::MarkdownCode

Instance methods

strip(content : String) : String

Markdown links inside fenced code blocks or inline code spans are documentation examples (e.g. a ![Diagram](/images/diagram.png) snippet demonstrating image syntax), not real links. Strip them before scanning so check-links doesn't report false-positive dead links — mirrors the code-stripping the scaffold link-integrity spec already performs.

Fences are tracked line-by-line, CommonMark-style: a fence opens with 3+ backticks/tildes (up to 3 spaces of indent) and only closes on a fence of the same character at least as long. The old non-greedy /[\s\S]*?/ mispaired nested fences — a 4-backtick example wrapping a 3-backtick fence desynchronized every fence after it, resurrecting example links as false positives. Also stripped: HTML comments and indented (4-space/tab) code blocks. Both hold example markup that is not a link — a <!-- <img src="/old.png"> --> note and an indented <a href="/example/"> demo were each reported dead.

Indented code is recognized conservatively, per CommonMark: a run only counts as code when it follows a blank line AND no list item is open. Without the list guard a 4-space list-item continuation would be swallowed, which is exactly the failure that made the sibling validator give up on indented blocks entirely.

Source