Skip to content

fix(parser): reset indentation in common-containers to prevent code block parsing#75

Merged
mgks merged 1 commit intodocmd-io:mainfrom
svallory:fix/nesting
Mar 9, 2026
Merged

fix(parser): reset indentation in common-containers to prevent code block parsing#75
mgks merged 1 commit intodocmd-io:mainfrom
svallory:fix/nesting

Conversation

@svallory
Copy link
Contributor

@svallory svallory commented Mar 9, 2026

Summary

  • Nested containers (card, callout, collapsible) were rendering their inner content as code blocks when indented for readability
  • Root cause: createDepthTrackingContainer called state.md.block.tokenize() directly, which preserved accumulated indentation from the outer state — pushing content past markdown-it's 4-space code block threshold
  • Fix mirrors the approach already used in tabs.js: extract raw lines, apply smartDedent to strip minimum indentation, then use state.md.render() for isolated recursive parsing

Closes #74

Test plan

  • card > callout nesting renders as containers, not code blocks
  • card > collapsible nesting renders as containers, not code blocks
  • card > callout > collapsible (3-level) renders correctly — exact scenario from the issue
  • card > card > callout > collapsible (4-level) renders correctly
  • tabs > card > callout > collapsible still works (tabs path unchanged)
  • Inner content paragraphs render as <p>, not raw text
  • Run bun test packages/parser/src/features/common-containers.test.js — all 7 tests pass

…lock parsing

Nested containers (card, callout, collapsible) were incorrectly rendering
their inner content as code blocks when indented. This happened because
`createDepthTrackingContainer` used `state.md.block.tokenize()` directly,
which preserved the accumulated indentation from the outer state — causing
markdown-it to treat 4+ spaces of indented content as a code block.

The fix mirrors the approach already used in tabs.js:
- Extract raw content lines via `state.bMarks`
- Apply `smartDedent` to strip minimum indentation
- Use `state.md.render()` for isolated recursive parsing

Closes docmd-io#74
@mgks mgks merged commit abd1338 into docmd-io:main Mar 9, 2026
@mgks
Copy link
Member

mgks commented Mar 9, 2026

Funny thing, even I just found this bug yesterday trying to fix another dev server issue. Thanks for fixing this!

@mgks mgks mentioned this pull request Mar 9, 2026
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.

[Bug]: not all containers reset indentation

2 participants