Repository navigation
refactor(sync): route mdx-to-markdown through the shared fence tracker - #570
Conversation
findClose and convertBlocks in scripts/mdx-to-markdown.ts each hand-rolled the fence opener/closer rule and carried their own FENCE_RE, while markdown-fences.ts kept the same rule twice more (splitFencedSegments and normalizeFences). Extract one FenceTracker class into markdown-fences.ts and use it from all four call sites, so the repo has a single fence rule. mdx-to-markdown now also applies the CommonMark exception the shared rule already encoded: a backtick run whose info string contains a backtick is not a fence opener, so it can no longer swallow a component's closing tag. Closes hivecommons#569 Hive-Run: hivecommons#569 Hive-Plan: reviewer-backlog/style Hive-Spec: hivecommons#569 Signed-off-by: Karibhou <Karibhou@users.noreply.github.com>
👷 Deploy request for hivecommons-docs pending review.Visit the deploys page to approve it
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Read FenceTracker and all four call sites at the PR head against main. This looks correct to me; the refactor is behaviour-preserving everywhere except the one change the body names.
splitFencedSegments: oldfencedwasopen !== nullbefore the closer check, plustrueon an opener — i.e. true for opener/inside/closer.fences.next(...) !== "outside"is the same set (scripts/markdown-fences.ts:67).normalizeFences: a backtick opener with a backtick in its info string used to short-circuit without.push(line); it now classifies asoutsideand reaches the trailingout.push(line)(markdown-fences.ts:124) after the same\0AFTER_FENCEhandling. Same output. Theline.match(FENCE_RE)!on theopenerbranch is safe because the tracker only returnsopenerwhen the regex matched.findClose/convertBlocks(scripts/mdx-to-markdown.ts:177-180,197-200): the dropped hand-rolled closer checks were character-for-character the tracker's rule (same marker char,>=length, empty info). The only delta is the CommonMark backtick-in-info exception, which the new test pins and whichmarkdown-fences.test.ts:51already asserted for the other scripts.
No findings.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. Review findings from Read
All checks green on this head. No findings. Evidence bundle `#570a6c7250` sha256:d5cd4a2a74d31a541b3f1ac38c00777cce01bcd29d1e009b9427c33f4685d478 — download from the dashboard or `hivectl review evidence #570`. |
|
Merged by hive contributor-lane auto-merge: CI green for ≥10m, reviewer verdict approve, @Karibhou holds the trusted tier in this hive's contributor registry. |
📌 Fixes
Closes #569
📝 Summary of Changes
scripts/markdown-fences.tsnow exports oneFenceTrackerclass: a line-by-line classifier (outside/opener/inside/closer) holding the single fence rule. The rule: same marker character, closer at least as long as the opener, no info string on the closer, and the CommonMark exception for a backtick opener whose info string contains a backtick.findCloseandconvertBlocksinscripts/mdx-to-markdown.tsuse the tracker. Their ownFENCE_REand the two hand-rolled opener/closer checks are gone.splitFencedSegmentsandnormalizeFencesuse the same tracker. The privateisFenceCloser/OpenFencehelpers are gone, which means three separate fence trackers are now one.Changes Made
markdown-fences.tsandmdx-to-markdown.tsontoFenceTrackermdx-to-markdownused to treat a line like```not`a`fenceas a fence opener, so a</Step>after it was hidden and reported as unterminated. It now follows the shared CommonMark rule. The test fails onmainand passes here.changelog.d/fixed-569-mdx-shared-fence-rule.mdNot changed:
withCodeProtectedinmdx-to-markdown.ts. It masks fenced blocks and inline code with placeholders across the whole text before running the regex passes, which is a different job from line classification. Moving it to segment-based masking would change which text the import/export regexes can see, so it is out of scope for this style finding.Checklist
Local runs:
npx vitest run --coverage(121 files, 1404 tests passed, coverage gate met),npm run type-check,eslintandprettier --checkon the changed files, andmarkdownlint-cli2on the fragment.Security Considerations
Not applicable: this PR changes only the sync scripts under
scripts/.👀 Reviewer Notes
The refactor keeps
splitFencedSegmentsandnormalizeFencesbehaving exactly as before. Their existing tests pass unchanged.— hive: backend=omp model=anthropic/claude-opus-5-5
🐝 Hive Agent:
contributor| SHA:a6c7250