fix(render): correct list indentation and block content in list items#120
Conversation
Fix two issues in the markdown renderer: - Nested lists now use correct indentation width matching the parent list marker (3 spaces for `1. `, 2 spaces for `- `), conforming to the CommonMark spec. (comarkdown#114) - Block-level elements (code blocks, blockquotes, tables) inside list items are now rendered on their own line with proper indentation instead of being concatenated to the preceding inline text. (comarkdown#118)
|
@ManUtopiK is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
comark
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
|
|
||
| if (Array.isArray(child) && blockElements.has(child[0] as string)) { | ||
| // Block-level child: put on its own line and indent to align with list prefix | ||
| const trimmed = rendered.replace(/\n\n$/, '\n').replace(/\n$/, '') |
There was a problem hiding this comment.
Are you sure that these replaces are needed?
I just checked and even with removing these replaces tests passed.
I didn't get the real reason behind these replaces, maybe these are useful when li have multiple chilred.
Could you add a test to check against these replaces? 🙏
There was a problem hiding this comment.
You're right!
I tested with and without the .replace() and the output is the same in all cases. I started this current fix for some experiments with markdownlint. I didn't remember why I added this lines... so I removed them.
To be sure, I also added 7 SPEC tests to cover all cases (blockquote, table, code blocks, nested ol/ul up to 3 levels) here : ManUtopiK@f4c2330
Should I merge these tests ? Is it too much ? Or in another PR ?
There was a problem hiding this comment.
It's never too much to have more tests 🙂
Feel free to push it in this PR 👍
|
Thanks for the PR @ManUtopiK |
Cover blockquote, table, and code blocks inside list items with various nesting patterns (ol/ul mixed, up to 3 levels deep).
Summary
Fix two markdown rendering bugs in
renderMarkdown:3spaces for1.,2spaces for-), conforming to CommonMark 0.31.2 §5.2 — continuation blocks must be indented to the column of the first non-blank character after the list marker (Examples 254, 109).pre,blockquote,table) inside list items are now rendered on their own line with proper indentation, instead of being concatenated to the preceding inline text. Per CommonMark 0.31.2 §5.2 Example 263, fenced code blocks in list items must be indented to align with list content.Changes
indent.tswidthparameter for character-count indentationul.tslistIndent: 2in context (matches-prefix)ol.tslistIndent: 3in context (matches1.prefix)li.tsTest plan
parse → renderMarkdown → parse → renderMarkdownproduces identical outputCloses #114, closes #118