Skip to content

Commit 2bfaf1d

Browse files
committed
issue-379: only treat standalone ``` lines as code fences
The previous heuristic `line.lstrip().startswith("```")` matched escaped inline-code constructs such as `` ``` `code-span` `` `` (used in req/README.md to document forbidden anchor formatting), causing the fence state machine to flip mid-file and silently skip the rest of the document from link validation. Replace with `FENCE_LINE_RE = ^\s*```[A-Za-z0-9_-]*\s*$` so that only lines consisting solely of a fence (with optional language identifier) toggle fence state. Verified by injecting a deliberately broken link at the end of req/README.md and confirming the validator now flags it.
1 parent 99e3c9e commit 2bfaf1d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/check-requirements-catalog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ def collect_docs_anchor_index() -> dict[str, set[str]]:
342342

343343

344344
INLINE_CODE_RE = re.compile(r"``[^`]*``|`[^`]*`")
345+
# A real code fence is a line that begins with ``` followed only by an
346+
# optional info string (language identifier). Lines like
347+
# ```` ``` `code-span` ```` are inline-code escapes, not fences, and must
348+
# not be treated as opening/closing a fence.
349+
FENCE_LINE_RE = re.compile(r"^\s*```[A-Za-z0-9_-]*\s*$")
345350

346351

347352
def strip_fenced_code(text: str) -> str:
@@ -352,8 +357,7 @@ def strip_fenced_code(text: str) -> str:
352357
out: list[str] = []
353358
in_fence = False
354359
for line in text.splitlines():
355-
stripped = line.lstrip()
356-
if stripped.startswith("```"):
360+
if FENCE_LINE_RE.match(line):
357361
in_fence = not in_fence
358362
out.append("")
359363
continue

0 commit comments

Comments
 (0)