Skip to content

fix(render): correct list indentation and block content in list items#120

Merged
farnabaz merged 4 commits into
comarkdown:mainfrom
ManUtopiK:fix/list-indentation-and-block-content
Apr 17, 2026
Merged

fix(render): correct list indentation and block content in list items#120
farnabaz merged 4 commits into
comarkdown:mainfrom
ManUtopiK:fix/list-indentation-and-block-content

Conversation

@ManUtopiK

Copy link
Copy Markdown
Contributor

Summary

Fix two markdown rendering bugs in renderMarkdown:

Changes

File Change
indent.ts Add width parameter for character-count indentation
ul.ts Set listIndent: 2 in context (matches - prefix)
ol.ts Set listIndent: 3 in context (matches 1. prefix)
li.ts Detect block-level children, render them on a new line with prefix-aligned indentation
3 SPEC files Update expected markdown output to match corrected behavior

Test plan

  • All existing tests pass (746 passed, 2 pre-existing shiki timeouts unrelated)
  • Roundtrip stable: parse → renderMarkdown → parse → renderMarkdown produces identical output
  • Verified against CommonMark spec §5.2: indentation matches the column of first content after list marker

Closes #114, closes #118

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)
@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown

@ManUtopiK is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Apr 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comarkdown/comark@120

@comark/ansi

npm i https://pkg.pr.new/comarkdown/comark/@comark/ansi@120

@comark/html

npm i https://pkg.pr.new/comarkdown/comark/@comark/html@120

@comark/nuxt

npm i https://pkg.pr.new/comarkdown/comark/@comark/nuxt@120

@comark/react

npm i https://pkg.pr.new/comarkdown/comark/@comark/react@120

@comark/svelte

npm i https://pkg.pr.new/comarkdown/comark/@comark/svelte@120

@comark/vue

npm i https://pkg.pr.new/comarkdown/comark/@comark/vue@120

commit: 4a1f5c6


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$/, '')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's never too much to have more tests 🙂
Feel free to push it in this PR 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est fait !

@farnabaz

Copy link
Copy Markdown
Collaborator

Thanks for the PR @ManUtopiK
I just add a comment on the li handler, other than that it looks great 🙂

ManUtopiK and others added 3 commits April 16, 2026 14:19
Cover blockquote, table, and code blocks inside list items with
various nesting patterns (ol/ul mixed, up to 3 levels deep).

@farnabaz farnabaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@farnabaz farnabaz merged commit aad5516 into comarkdown:main Apr 17, 2026
3 of 10 checks passed
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.

renderMarkdown merges code blocks into preceding text inside list items renderMarkdown nested lists indentation is off inside ordered lists

2 participants