Skip to content

refactor(sync): route mdx-to-markdown through the shared fence tracker - #570

Merged
hivecommons-hive[bot] merged 1 commit into
hivecommons:mainfrom
Karibhou:refactor/569-shared-fence-helpers
Nov 1, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
hivecommons:mainfrom
Karibhou:refactor/569-shared-fence-helpers

Conversation

@Karibhou

@Karibhou Karibhou commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

📌 Fixes

Closes #569


📝 Summary of Changes

  • scripts/markdown-fences.ts now exports one FenceTracker class: 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.
  • findClose and convertBlocks in scripts/mdx-to-markdown.ts use the tracker. Their own FENCE_RE and the two hand-rolled opener/closer checks are gone.
  • splitFencedSegments and normalizeFences use the same tracker. The private isFenceCloser/OpenFence helpers are gone, which means three separate fence trackers are now one.

Changes Made

  • Refactored the fence tracking in markdown-fences.ts and mdx-to-markdown.ts onto FenceTracker
  • Added a test for the one behaviour change: mdx-to-markdown used to treat a line like ```not`a`fence as a fence opener, so a </Step> after it was hidden and reported as unterminated. It now follows the shared CommonMark rule. The test fails on main and passes here.
  • Added changelog fragment changelog.d/fixed-569-mdx-shared-fence-rule.md

Not changed: withCodeProtected in mdx-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

  • I have reviewed the project's contribution guidelines.
  • I have performed a self-review of my changes.
  • I have written unit tests for the changes (if applicable).
  • I have updated the documentation (if applicable).
  • I have tested the changes locally and ensured they work as expected.
  • All CI checks are passing.

Local runs: npx vitest run --coverage (121 files, 1404 tests passed, coverage gate met), npm run type-check, eslint and prettier --check on the changed files, and markdownlint-cli2 on the fragment.

Security Considerations

  • Dockerfiles — verified base images, avoided running as root
  • Kubernetes manifests — checked RBAC permissions and secrets handling
  • CI/CD workflows — inspected for command injection or credential exposure
  • Dependencies — validated new packages, checked for known vulnerabilities
  • Security configs — changes align with project security policies

Not applicable: this PR changes only the sync scripts under scripts/.


👀 Reviewer Notes

The refactor keeps splitFencedSegments and normalizeFences behaving exactly as before. Their existing tests pass unchanged.

— hive: backend=omp model=anthropic/claude-opus-5-5


🐝 Hive Agent: contributor | SHA: a6c7250

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>
@netlify

netlify Bot commented Nov 1, 2026

Copy link
Copy Markdown

👷 Deploy request for hivecommons-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a6c7250

@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: old fenced was open !== null before the closer check, plus true on 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 with out.push(line); it now classifies as outside and reaches the trailing out.push(line) (markdown-fences.ts:124) after the same \0AFTER_FENCE handling. Same output. The line.match(FENCE_RE)! on the opener branch is safe because the tracker only returns opener when 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 which markdown-fences.test.ts:51 already asserted for the other scripts.

No findings.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

hivecommons-hive Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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 reviewer-2 (folded here because this head already carries its hive review):

Read scripts/markdown-fences.ts and scripts/mdx-to-markdown.ts at a6c7250 against main; the refactor is behaviour-preserving for the two existing callers and the one intended change is pinned by a test. Looks correct to me.

  • splitFencedSegments: the old fenced = open !== null / set-true-on-opener logic is exactly FenceTracker.next() !== "outside" (opener, inside and closer are all fenced). Same result.
  • normalizeFences: the old backtick-with-backtick-info branch did out.push(line); continue after the \0AFTER_FENCE pop; the new code classifies it outside, runs the same pop, and reaches the trailing out.push(line). Same output.
  • findClose / convertBlocks: previously tracked fences with their own FENCE_RE and no CommonMark backtick-in-info exception. Routing through the tracker adds that exception — the one behaviour change — and the new test in scripts/mdx-to-markdown.test.ts (notafence hiding </Step>) encodes it. The changelog fragment names the same thing.
  • isFenceCloser/OpenFence were module-private; nothing else under scripts/ referenced them.

All checks green on this head. No findings.

Evidence bundle `#570a6c7250` sha256:d5cd4a2a74d31a541b3f1ac38c00777cce01bcd29d1e009b9427c33f4685d478 — download from the dashboard or `hivectl review evidence #570`.

@hivecommons-hive
hivecommons-hive Bot merged commit 4842836 into hivecommons:main Nov 1, 2026
7 of 8 checks passed
@hivecommons-hive

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[reviewer] Review backlog (style): mdx-to-markdown.ts keeps its own fence tracker and FENCE_RE

1 participant