Skip to content

fix: stop content loss and code-sample damage in cleaning and partials - #85

Merged
rachfop merged 2 commits into
mainfrom
fix/content-loss
Oct 2, 2026
Merged

rachfop merged 2 commits into
mainfrom
fix/content-loss

Conversation

@rachfop

@rachfop rachfop commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Content cleaning and partial inlining deleted prose, damaged code samples, and could hang the build:

  • Any line starting with "import " was deleted from inlined partials (and from every page with excludeImports), including wrapped prose. Only ES import statements are removed now, multi-line ones whole.
  • Code samples inside nested partials were emptied, and one partial's body could be spliced into another partial's code sample. Code is masked at every resolution level, and inlined bodies are protected from later splices.
  • A JSX tag with many brace-valued attributes backtracked exponentially (about 4 s at 24 attributes). Matching is now linear.
  • HTML tags were removed with no separator (a<br/>b became ab, table cells ran together, <img> vanished). Block tags leave a line break, cells get |, and <img> becomes a Markdown image.
  • Nested fences closed at the inner fence, and fences inside blockquotes weren't masked.
  • Descriptions could come from a shell comment in a code block or an MDX comment; {/* */} and <!-- --> comments are now stripped outside code.
  • Aliased and combined partial imports, and partials used with children, weren't inlined. Children render where the partial uses {props.children}.
  • Blank lines inside code samples were collapsed; collapsing now happens only outside code.

tests/test-content-loss.js covers each case. The docs site build output is unchanged. On a 3,461-page MDX docs site, no prose is lost: the only removed words are comments and a half-removed multi-line import.

- Import removal (partial inlining and excludeImports) matched any line
  starting with "import ", deleting wrapped prose, and left multi-line
  imports half-removed. A shared IMPORT_STATEMENT regex removes only ES
  import statements with a quoted specifier, multi-line braces included.
- resolvePartialImports masks code at every recursion level, so imports
  and partial usage inside a nested partial's code fence stay as written
  (also on the missing-partial path). Inlined bodies are parked behind
  tokens until the end, so a later splice cannot reach into an earlier
  partial's code sample.
- maskCodeSegments tokens are namespaced per call, so masking already
  masked content restores correctly.
- TAG_ATTRS: a bare attribute value cannot start with a quote or brace,
  removing the exponential backtracking on long tags that fail to match.
- HTML stripping keeps boundaries: block tags become a newline (a space in
  a markdown table row), adjacent td/th cells get " | ", and <img src alt>
  becomes ![alt](src) so image-URL rewriting applies.
- Fence masking follows CommonMark closing rules (same char, at least as
  long as the opener) and masks fences inside blockquotes.
- Description extraction: the H1 fallback reads the masked body, and MDX
  {/* */} paragraphs are skipped. MDX and HTML comments outside code are
  stripped from cleaned content.
- Partial imports accept `{ default as X }` and `X, { y }`, and a partial
  used with element children is inlined.

Adds tests/test-content-loss.js (32 cases; 25 failed before the fix).
- A partial used with children (`<Wrap>…</Wrap>`) now renders them where
  its body has `{props.children}`, matching MDX; otherwise they're dropped
  as before.
- Blank-line collapsing ran after code was restored, so a code sample's
  runs of blank lines were squeezed to one. Collapse before restoring, and
  also clear the whitespace-only lines that indented HTML leaves behind.
@rachfop
rachfop merged commit c1645fd into main Oct 2, 2026
5 checks passed
@rachfop
rachfop deleted the fix/content-loss branch October 2, 2026 22:48
rachfop added a commit that referenced this pull request Oct 2, 2026
#85)

* fix: stop content loss and code-sample damage in cleaning and partials

- Import removal (partial inlining and excludeImports) matched any line
  starting with "import ", deleting wrapped prose, and left multi-line
  imports half-removed. A shared IMPORT_STATEMENT regex removes only ES
  import statements with a quoted specifier, multi-line braces included.
- resolvePartialImports masks code at every recursion level, so imports
  and partial usage inside a nested partial's code fence stay as written
  (also on the missing-partial path). Inlined bodies are parked behind
  tokens until the end, so a later splice cannot reach into an earlier
  partial's code sample.
- maskCodeSegments tokens are namespaced per call, so masking already
  masked content restores correctly.
- TAG_ATTRS: a bare attribute value cannot start with a quote or brace,
  removing the exponential backtracking on long tags that fail to match.
- HTML stripping keeps boundaries: block tags become a newline (a space in
  a markdown table row), adjacent td/th cells get " | ", and <img src alt>
  becomes ![alt](src) so image-URL rewriting applies.
- Fence masking follows CommonMark closing rules (same char, at least as
  long as the opener) and masks fences inside blockquotes.
- Description extraction: the H1 fallback reads the masked body, and MDX
  {/* */} paragraphs are skipped. MDX and HTML comments outside code are
  stripped from cleaned content.
- Partial imports accept `{ default as X }` and `X, { y }`, and a partial
  used with element children is inlined.

Adds tests/test-content-loss.js (32 cases; 25 failed before the fix).

* fix: keep partial children and code-sample blank lines

- A partial used with children (`<Wrap>…</Wrap>`) now renders them where
  its body has `{props.children}`, matching MDX; otherwise they're dropped
  as before.
- Blank-line collapsing ran after code was restored, so a code sample's
  runs of blank lines were squeezed to one. Collapse before restoring, and
  also clear the whitespace-only lines that indented HTML leaves behind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant