Skip to content

fix(comark): absorb markdown under incomplete HTML openers - #390

Open
farnabaz wants to merge 7 commits into
mainfrom
fix/html-block
Open

fix(comark): absorb markdown under incomplete HTML openers#390
farnabaz wants to merge 7 commits into
mainfrom
fix/html-block

Conversation

@farnabaz

Copy link
Copy Markdown
Collaborator

What

Incomplete block HTML open tags (e.g. streaming <ai-thinking>… with no closer) now wrap following markdown as children with $: { html: 1, block: 0 }, including the single-newline case where CommonMark would otherwise swallow the body into one raw html_block.

Why

During AI/streaming output, custom tags often arrive without a closing tag yet. The previous CommonMark-faithful path left the opener empty and the body as siblings, so renderers could not keep the unfinished element around its content. Blank-line-terminated incomplete openers were fixed first; the blank-line-less case still needed the block rule to stop at the opener line so the token processor can absorb the rest.

Leave single-line incomplete open tags (e.g. `<ai-thinking>\n**bold**`) as
opener-only html_block tokens so the following markdown can be absorbed as
children, matching the blank-line incomplete case.
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview Aug 28, 2026 3:42pm
comark-json-render Ready Ready Preview Aug 28, 2026 3:42pm
comark-nextjs Ready Ready Preview Aug 28, 2026 3:42pm
comark-nuxt Ready Ready Preview Aug 28, 2026 3:42pm
comark-svelte Ready Ready Preview Aug 28, 2026 3:42pm
comark-sveltekit Ready Ready Preview Aug 28, 2026 3:42pm
comark-twoslash Ready Ready Preview Aug 28, 2026 3:42pm
comark-vue Ready Ready Preview Aug 28, 2026 3:42pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@390

@comark/angular

npm i https://pkg.pr.new/@comark/angular@390

@comark/ansi

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

@comark/html

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

@comark/nuxt

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

@comark/react

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

@comark/svelte

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

@comark/vue

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

commit: a9d96b5

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle size snapshot is out of date

The published size of one or more packages changed, so the inline snapshot in
test/bundle.test.ts no longer matches.

Please review the diff below. If the change is expected, accept the new snapshot:

  • 🔄 Update the bundle snapshot — tick this box and CI will run vitest run bundle --update and commit the result to this branch.

Update bundle snapshot

Only maintainers with write access can trigger the update. You can also comment /update-bundle-snapshot, or run it locally with pnpm prepack && pnpm vitest run bundle -u.

Bundle size diff
 FAIL  test/bundle.test.ts > package bundle size > published size of each package
Error: Snapshot `package bundle size > published size of each package 1` mismatched

- Expected
+ Received

@@ -4,7 +4,7 @@
    "@comark/html": "18.9k (58 files)",
    "@comark/nuxt": "11.8k (58 files)",
    "@comark/react": "43.6k (74 files)",
    "@comark/svelte": "43.9k (82 files)",
    "@comark/vue": "60.5k (78 files)",
-   "comark": "424k (156 files)",
+   "comark": "433k (156 files)",
  }

 ❯ test/bundle.test.ts:61:20
     59|     }
     60|
     61|     expect(report).toMatchInlineSnapshot(`
       |                    ^
     62|       {
     63|         "@comark/angular": "60.6k (70 files)",

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Full CI log

A `$` at end of line (or with only trailing whitespace) is not an incomplete
inline-math opener, so auto-close leaves it alone instead of appending `$`.
Incomplete HTML openers with a later matching closer now absorb
intervening
tokens (including nested same-tag blocks) as children, so cases like
details-in-details build a proper tree instead of sibling empties.
Markdown stringify no longer glues `</summary>Nested content`. HTML wrappers
with a lone markdown paragraph among HTML siblings still auto-unwrap that
paragraph; multi-block bodies keep their `<p>` structure.
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