Repository navigation
Read validate.py's Markdown and the README Link Definitions Through markdown-it-py - #3635
Conversation
…arkdown-it-py spec/validate.py's link targets, section reader, and section-declaration headings now read through spec/fidelity_text.py, so a code span, a code block, and a fenced "## " line are content rather than links or headings. The import stays lazy, so spec/resolve_description.py still imports the module under a plain python3, and CI and OPERATIONS.md run the validator under uv. The README link-naming, shield, and 3rd Party Tools checks read reference definitions from the parser rather than the _LINK_DEF line scan. A line that would interrupt a paragraph is no longer a definition, and of two definitions whose labels fold together the first wins, as GitHub renders it, with every reference lookup folded the same way. Closes #3426 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and Drop the Validator's Import Cache The validator's import helper no longer uses functools.cache, which a Python 3.8 interpreter configure.sh accepts does not have. Link targets read each definition from the parser's table, decoded as a link is, so a link and its definition compare as one target. An empty destination reads as the empty string, and a label wrapped onto a second line is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Order link_definitions reads the label markdown-it-py's definition token keeps as written, so a label wrapped inside a blockquote folds to the key the parser resolves it by. Only the destination, which the parser stores normalized, is read from the source lines. link_targets' docstring now says links come first and definitions after them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
A recorded local strict-review pass covers head |
There was a problem hiding this comment.
🟡 Changes recommended
The change still has an active moderate documentation issue because the docstring incorrectly promises that duplicate reference definitions are returned.
1 open issue
What changed in this PR
This pull request replaces the remaining hand-written Markdown readers with markdown-it-py, preserving rendered Markdown behavior across validation and README auditing while updating validator execution to use uv.
Changes:
- Adds parser-backed handling for links, headings, sections, reference definitions, and folded reference keys.
- Updates validation, README auditing, CI, and operations documentation.
- Adds regression coverage for autolinks, fenced content, reference resolution, and lazy imports.
- Remaining findings include a moderate P2 docstring contract issue in
spec/fidelity_text.py(3 votes) and P2 nit findings for the fenced-definition regression fixture inspec/fidelity_text.pyandtests/test_audit_helpers.py(1 vote each).
This pull request requires changes.
| File | Description |
|---|---|
tests/test_spec_validate.py |
Tests autolinks, fenced headings, validation behavior, and lazy imports. |
tests/test_fidelity_text.py |
Tests parser-backed headings, links, definitions, folding, and code exclusion. |
tests/test_audit_helpers.py |
Updates fixtures and tests rendered reference resolution and audit behavior. |
spec/validate.py |
Uses lazy parser-backed Markdown validation and adds PEP 723 metadata. |
spec/fidelity_text.py |
Adds shared parser-backed link targets, reference definitions, and folded reference keys. |
spec/audit_markdown.py |
Replaces regex-based reference scanning with parser-backed definitions. |
OPERATIONS.md |
Documents running validation through uv. |
.github/actions/validate/action.yml |
Sets up uv and runs validation with the script metadata. |
Review effort: Lite
…First link_targets also reads the duplicate definitions the parser resolves nothing to, so a carried duplicate's destination is checked as it was before. The fenced-sample tool case now places its sample ahead of the real definition, since under first-wins a later one could not override it and the case would pass whether or not fences were read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3635 +/- ##
===========================================
+ Coverage 81.63% 81.69% +0.06%
===========================================
Files 26 26
Lines 9081 9111 +30
===========================================
+ Hits 7413 7443 +30
Misses 1668 1668
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
unfenced_text and readme_link_findings read fenced lines through one helper, and the link-targets test now holds a fenced block whose link and definition must not count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
… code_lines The block parser emits definition tokens, so link_definitions reads the same cached parse headings and code blocks do rather than a second one. code_lines takes fenced_only, which the README readers use in place of a local copy. The validator's docstring names the hook that runs it, and fidelity_text's names a document rather than a region as what a lazy importer reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…3637) ## Summary Fixes the finding Copilot raised on promotion #3636 against #3635's `spec/fidelity_text.py` `_DESTINATION`, and the second one its review body named. Both come from one root cause: the regex re-reading a definition's as-written destination did not honor backslash escapes. - An angle-bracket destination holding an escaped `>` was cut at it, so `[b]: <https://example.test/a\>b>` read as `https://example.test/a\`. - A label ending in an escaped backslash matched nothing, so `[a\\]: one.md` raised `AttributeError` in `link_definitions`. The regex now anchors on the label's opening `[` and honors escapes on both sides, including a label the parser lets wrap after a backslash. `test_an_escape_in_a_label_or_an_angle_destination_is_read_through` pins all three shapes. The first two fail on the old regex, and the third on this branch's first commit. ## Verification - The full unittest suite ran 3103 tests, OK (skipped=7). - `spec/validate.py` prints the same output as before #3635. - Two recorded `local-strict-review` passes ran. The first raised the wrapped-after-backslash label, fixed in 149f883. The second raised nothing. ## Dropped findings - `spec/fidelity_text.py` `_DESTINATION`, `pre-existing`: `[ \t>]*` swallows a leading `>` of a bare destination, an angle destination holding a backslash-newline falls back to `\S+`, and `\S+` stops at a non-breaking space the parser keeps. The old regex behaved the same on each, and none is a realistic README shape. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…nitions Through markdown-it-py (#3636) Promotes the #3426 markdown-it-py link reading from `develop` to `main`. - [#3635](#3635) Reads `spec/validate.py`'s link targets, sections, and headings, and the README audit's reference definitions, through `spec/fidelity_text.py` and markdown-it-py. A definition resolves first-wins with folded lookup, as GitHub renders it, and code is content rather than links. The validator now runs under `uv run --no-project --script`. - [#3637](#3637) Reads backslash escapes in a definition's label and angle destination, so an escaped `>` no longer cuts a destination short and a label ending in an escaped backslash no longer raises. It answers both findings Copilot raised on this promotion. Closes #3426 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Summary
Moves the last two hand-written Markdown readers onto markdown-it-py, per #3426.
spec/validate.pyreads link targets, the verbatim-section region, and the section-declaration headings throughspec/fidelity_text.py. So a code span, a code block, and a fenced##line are content rather than links or headings, and an autolink counts as a link. The import stays lazy, held by a new import-probe test, sospec/resolve_description.pystill imports the module under the plainpython3thatrepo-config/configure.shfinds. The validator gains a PEP 723 header, and CI andOPERATIONS.mdrun it underuv run --no-project --script.spec/audit_markdown.pyreads reference definitions from the parser for the link-naming, shield, and 3rd Party Tools checks, replacing the_LINK_DEFline scan. A definition-shaped line inside a paragraph is no longer a definition. Of two definitions whose labels fold together, the first wins, as GitHub renders it. Every reference lookup is folded the same way, so![x][Docs]resolves to[docs].spec/fidelity_text.py's cached block parse now emits definition tokens. It gainslink_definitions(the token's label as written, the destination re-read from the source lines),link_targets(links, images, definitions, and duplicates, all decoded),reference_key, and afenced_onlyswitch oncode_lines.The
commentslabel is for the PEP 723 header inspec/validate.py. #3634 tracks exempting such a block fromcomment-added.Before and After
spec/validate.pyprints the same output on the base and at every commit: 22 cataloged repos classify cleanly.uv run --no-project --script spec/audit.py, every cataloged repo) ran on the base, on the first commit, on 97e63e9, and on 7ed8ecf, the last commit touching code the audit reads. Every finding line matched, except where a live repository moved between runs. Twomainheads advanced. ESPHome-Config gained a branch-divergence DRIFT, which the base code also reports when run against that repository now.DOCKER_SHIELDintests/test_audit_helpers.pyplaced[e]: ...directly under a paragraph line, which GitHub renders as text. Its definition now sits with the others.## Rule.Local Review
Seven recorded
local-strict-reviewpasses ran, the last at ff63df6 with no findings. Everyintroducedfinding the earlier passes raised was fixed on this branch:functools.cachethat a Python 3.8configure.shhost lacks, and mixed decoded and raw link targets.<>destination read asNone, a wrapped label dropped, and a label re-parsed by regex rather than taken from the parser's definition token.link_targets, and a fenced-sample tool test that first-wins had made unable to fail.OPERATIONS.mdbullet that no longer matched the code.Declined with evidence:
audit_markdown.references()into the new definition readers.references()feedsstrip_md_links, which needs markdown-it's env shape with normalized hrefs. The naming checks need labels and destinations as written, and both read the same parser table.fidelity_text._LINKSandaudit_markdown._MD._MDdisablestext_joinbecausestrip_md_linksrebuilds a line from its source tokens, a requirement sharing would move intofidelity_text.validate.fidelity_text_moduleas a copy of thecarry.pyandbuild_dist.pyhelpers. Those also putspec/onsys.path. This one is a two-line wrapper.Closes #3426
🤖 Generated with Claude Code