Skip to content

fix: parse indented raw html children in html blocks#208

Merged
farnabaz merged 6 commits into
mainfrom
fix/html-block-indented-children
May 22, 2026
Merged

fix: parse indented raw html children in html blocks#208
farnabaz merged 6 commits into
mainfrom
fix/html-block-indented-children

Conversation

@atinux
Copy link
Copy Markdown
Contributor

@atinux atinux commented May 21, 2026

Why

Indented raw HTML children inside an open HTML block could be tokenized as markdown code blocks.

<p align="center">
  <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
    <img src="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg" alt="Sponsors"/>
  </a>
</p>

was creating:

[
  [
    "p",
    { "$": { "html": 1, "block": 1 }, "align": "center" },
    [
      "a",
      {
        "$": { "html": 1, "block": 1 },
        "href": "https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg"
      }
    ],
    [
      "pre",
      {},
      [
        "code",
        {},
        "<img src=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\" alt=\"Sponsors\"/>"
      ]
    ]
  ],
  ["component", {}]
]

What

  • Process multiline html_block tokens through one HTML-aware path.
  • Reinterpret HTML-looking code_block tokens as raw HTML only while inside an HTML block.
  • Keep normal markdown parsing inside HTML blocks, including emphasis, inline code, components, and real indented code blocks.
  • Add regression coverage for nested indented raw HTML, markdown inside HTML, comments, stray close tokens, and code-block boundaries.

Tests

  • pnpm --dir packages/comark exec vitest run test/html-block.test.ts
  • pnpm --dir packages/comark test
  • pnpm exec oxfmt --check packages/comark/test/html-block.test.ts

Not run in this final pass: pnpm run typecheck due existing unrelated errors in packages/comark-vue/test/vite.test.ts.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

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

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview May 22, 2026 2:18pm
comark-json-render Ready Ready Preview May 22, 2026 2:18pm
comark-nextjs Ready Ready Preview May 22, 2026 2:18pm
comark-nuxt Ready Ready Preview May 22, 2026 2:18pm
comark-svelte Ready Ready Preview May 22, 2026 2:18pm
comark-sveltekit Ready Ready Preview May 22, 2026 2:18pm
comark-twoslash Ready Ready Preview May 22, 2026 2:18pm
comark-vue Ready Ready Preview May 22, 2026 2:18pm

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

comark

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

@comark/ansi

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

@comark/html

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

@comark/nuxt

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

@comark/react

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

@comark/svelte

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

@comark/vue

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

commit: 003d556

@atinux
Copy link
Copy Markdown
Contributor Author

atinux commented May 21, 2026

The more I think, the less I believe we should be able to mix markdown within html @farnabaz, this would probably simplify a lot the logic & performance

@farnabaz farnabaz merged commit 6f8f4b3 into main May 22, 2026
10 of 11 checks passed
@farnabaz farnabaz deleted the fix/html-block-indented-children branch May 22, 2026 14:18
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.

2 participants