fix(parser): preserve content around opener/closer with trailing whitespace#83
Merged
fix(parser): preserve content around opener/closer with trailing whitespace#83
Conversation
…espace
Two related bugs in remark-containers, plus four bugs fixed in cascade.
Targets:
- `::: card ` (trailing spaces on opener) → remark emits a hard `break`
node, splitting the opener paragraph into [text, break, text, …].
`collectContainer` only handled `children.length === 1`, so post-opener
content was silently dropped, producing an empty container.
- `::: ` (trailing space on closer) → CASE 1 recognized the closer line
via `.trim()` but discarded any text after the closer, instead of
emitting it as a sibling node.
Fixes:
1. CASE 1 now returns trailing siblings via a new `trailing` field on
`collectContainer`'s return shape; `processNodes` and the recursive
callsites push them after the container.
2. CASE 3 has a new branch for multi-child openers (children.length > 1
with a leading text node) that extracts the post-opener children
into a synthetic paragraph, mirroring the existing single-text-child
branch.
Cascade — incidentally fixed:
- `docs/page-layouts/sidebar-layout` and `sidebar-with-sections` had
`.expected-fail.invariants.ts` files for the same root cause: the
`::: sidebar` opener with no blank line broke parsing because remark
inlined content into the multi-child opener paragraph.
- `docs/tabs/basic-tabs` and `docs/navigation/sidebar-nav` snapshots
recover previously-dropped `**Free**`/`**App**` brand and pricing
content. The HTML output is now correct; their React/Tailwind
snapshots show the pre-existing latent bug where `transformParagraph`
emits inline `<strong>` as an HTML *string literal*, which renders
fine in HTML but escapes in React/JSX. That escape pattern already
exists in 10+ other fixture snapshots — separate PR will land a
proper inline-children fix.
Tests:
- 1,184 baseline → 1,187 with new isolated parse tests for remark-
containers' opener/closer whitespace contract.
- All 4 affected fixtures' invariants flipped from `.expected-fail` to
live, KNOWN_FAILURES list trimmed accordingly.
- REVIEW_LOG.md ⏳→✅ for the 6 affected fixtures (visually verified
via diff inspection of HTML output).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 4 bugs in
remark-containers.ts(2 targeted + 2 incidental) and recovers content in 2 docs fixtures that was previously silently dropped.Targeted bugs:
::: card(trailing spaces on opener) — remark emits a hard `break` node, splitting the opener paragraph into multi-child. `collectContainer` only handled `children.length === 1`, so post-opener content was silently dropped → empty container.:::(trailing space on closer) — CASE 1 recognized the closer line via `.trim()` but silently discarded any text after the closer.Cascade — incidentally fixed:
Content recovery (no prior expected-fail invariants):
What changed
packages/core/src/parser/remark-containers.tsTests
Known caveat
The React/Tailwind snapshots for `basic-tabs` and `sidebar-nav` reveal a pre-existing latent bug: `transformParagraph` builds inline `strong`/`em` as HTML string literals (lines 776-786 of transformer.ts), which render correctly in HTML but escape to `<strong>` in React/JSX. This pattern already exists in 10+ other fixture snapshots — not introduced here. Separate PR will land a proper inline-children fix.
Test plan
🤖 Generated with Claude Code