Skip to content

Add markdown healing via remend at segment boundaries - #2

Merged
taras merged 1 commit into
mainfrom
feat/markdown-healing
Mar 8, 2026
Merged

taras merged 1 commit into
mainfrom
feat/markdown-healing

Conversation

@taras

@taras taras commented Mar 8, 2026 •

Copy link
Copy Markdown
Owner

Why

When the boundary scanner splits a document at component or exec block boundaries, it can produce text segments with unclosed markdown constructs. For example:

Hello **world
<Component />
more text

The scanner produces two text segments: Hello **world\n (unclosed bold) and \nmore text. Without healing, the unclosed ** bleeds into the component expansion output, corrupting the rendered markdown. Components and exec blocks are semantic boundaries — markdown constructs (emphasis, links, code spans, math) cannot span them. Each text segment must be valid markdown independently.

Summary

  • Implements spec §2.3 — self-healing markdown using the remend package to close unclosed markdown constructs (bold, italic, strikethrough, code spans, links, images, math) at segment boundaries
  • Adds healSegment wrapper that runs after the boundary scanner and before interpolation, preserving trailing whitespace that remend would otherwise strip
  • Adds 28 Tier F tests (F1–F28) covering all spec scenarios: boundary healing, htmlTags: false behavior, orphaned closers, nested constructs, no-op cases, interpolation interaction, Content slot interaction, and math blocks

Changes

File Description
src/heal.ts healSegment wrapper — remend(text, { htmlTags: false }) with trailing-space preservation
src/expand.ts Integrates healing into expandSegments text branch: heal → interpolate
src/heal.test.ts 28 Tier F tests (F1–F28)
mod.ts Exports healSegment
specs/executable-mdx-spec.md Updated with §2.3 (remend), Tier F test table, decisions 22–24
package.json Added remend dependency

Test Results

All 115 tests pass (87 pre-existing + 28 new Tier F).

Implements spec §2.3 — text segments are healed with remend before
interpolation, closing unclosed bold, italic, strikethrough, code spans,
links, images, and math at component and exec block boundaries.

- src/heal.ts: healSegment wrapper (htmlTags: false, trailing-space restore)
- src/expand.ts: healing integrated into expandSegments text branch
- src/heal.test.ts: 28 Tier F tests (F1–F28) covering all spec scenarios
- specs/executable-mdx-spec.md: updated with §2.3, Tier F, decisions 22–24
@taras
taras merged commit f406d18 into main Mar 8, 2026
1 check passed
@taras
taras deleted the feat/markdown-healing branch March 8, 2026 22:36
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