OLD-7872: test_docs_links strips code fences line by line, as CommonMark does #29

Merged
leonida/mandy
ItsMrDubey merged 1 commit from docs-links-fences into main 2026-11-24 02:26:53 +00:00

Pull request successfully merged and closed

ItsMrDubey commented 2026-11-24 02:02:26 +00:00

Claimed in the coordination issue as: OLD-7872 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964)

What and why

Old #7872 (ray3242): strip_fences() in tests/test_docs_links.py used re.compile(r"```.*?```", re.S), which pairs any two triple-backtick runs. An inline ``` in prose, a 4-backtick fence holding a 3-backtick one, a ~~~ fence, or a closing line with an info string all mis-pair it: text between unrelated fences was dropped, so real headings vanished from the anchor set and links in that text went unchecked.

strip_fences() is now a line-based scanner following CommonMark: a fence opens on a line indented at most 3 spaces past its list item's content column (so the 4-space fences nested in list items in the i18n quickstarts still count), with >=3 backticks (no backtick in the info string) or tildes; it closes on a line of the same character, at least as long, with nothing after it; an unclosed fence runs to the end of the page. CRLF input is handled.

No other test or tool carries the regex. The other tests/test_docs_*.py checkers use a separate line.lstrip().startswith("```") toggle; I left those alone because they do a different job and this issue does not cover them.

New StripFencesTest cases cover inline backticks, a longer fence holding a shorter one, tilde fences, closing lines with an info string, fences nested in list items, 4-space indent outside a list, an unclosed fence, CRLF, and a heading after inline backticks showing up as an anchor.

On the real docs, the old and new scanners give identical link and anchor sets for every tracked .md file, so no doc links needed fixing.

Tested

Windows 11, Python 3.11.9, no GPU needed.

  • python -I tests/test_docs_links.py: before 7 tests OK; after 16 tests OK.
  • The new StripFencesTest run against the old strip_fences: 7 of 9 fail (the bug reproduces); all pass with the new one.
  • Comparing old and new links()/anchors() over all tracked Markdown: no differences.
  • python -I tests/test_ci_registration.py, tests/test_docs_repo_paths.py, tests/test_runtime_paths.py: OK.
  • python -I scripts/check_no_game_data.py tests/test_docs_links.py: clean.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. n/a: no translator rule
Claimed in the coordination issue as: OLD-7872 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964) ### What and why Old #7872 (ray3242): `strip_fences()` in `tests/test_docs_links.py` used `re.compile(r"```.*?```", re.S)`, which pairs any two triple-backtick runs. An inline ```` ``` ```` in prose, a 4-backtick fence holding a 3-backtick one, a `~~~` fence, or a closing line with an info string all mis-pair it: text between unrelated fences was dropped, so real headings vanished from the anchor set and links in that text went unchecked. `strip_fences()` is now a line-based scanner following CommonMark: a fence opens on a line indented at most 3 spaces past its list item's content column (so the 4-space fences nested in list items in the i18n quickstarts still count), with >=3 backticks (no backtick in the info string) or tildes; it closes on a line of the same character, at least as long, with nothing after it; an unclosed fence runs to the end of the page. CRLF input is handled. No other test or tool carries the regex. The other `tests/test_docs_*.py` checkers use a separate `line.lstrip().startswith("```")` toggle; I left those alone because they do a different job and this issue does not cover them. New `StripFencesTest` cases cover inline backticks, a longer fence holding a shorter one, tilde fences, closing lines with an info string, fences nested in list items, 4-space indent outside a list, an unclosed fence, CRLF, and a heading after inline backticks showing up as an anchor. On the real docs, the old and new scanners give identical link and anchor sets for every tracked `.md` file, so no doc links needed fixing. ### Tested Windows 11, Python 3.11.9, no GPU needed. - `python -I tests/test_docs_links.py`: before 7 tests OK; after 16 tests OK. - The new `StripFencesTest` run against the old `strip_fences`: 7 of 9 fail (the bug reproduces); all pass with the new one. - Comparing old and new `links()`/`anchors()` over all tracked Markdown: no differences. - `python -I tests/test_ci_registration.py`, `tests/test_docs_repo_paths.py`, `tests/test_runtime_paths.py`: OK. - `python -I scripts/check_no_game_data.py tests/test_docs_links.py`: clean. AI-assisted: yes ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. n/a: no translator rule
Sign in to join this conversation.
No description provided.