Skip to content

Inline HTML inside a block component loses its content (0.8) #505

Description

@onmax

Environment

  • Operating System: Linux
  • Node Version: v24.21.0
  • Package Manager: pnpm@11.18.0
  • Comark Version: 0.8.1
  • Framework: None

Comark Version

v0.8.1

Reproduction

import { parseMarkdown } from "comark";

const { nodes } = await parseMarkdown("::foo\nNote <b>x</b> end\n::");
console.log(JSON.stringify(nodes));

The text inside <b> moves out of it. 0.7.0 (-) against 0.8.1 (+):

-[["foo",{},"Note ",["b",{"$":{"html":1,"block":0}},"x"]," end"]]
+[["foo",{},"Note x",["b",{"$":{"html":1,"block":0}}]," end"]]

Rendered with @comark/html:

-<div class="foo">Note <b>x</b> end</div>
+<div class="foo">Note x<b></b> end</div>

The same line outside a block is fine on both versions:

await parseMarkdown("Note <b>x</b> end");
// [["p",{},"Note ",["b",{"$":{"html":1,"block":0}},"x"]," end"]]

Description

Inside a :: block component, inline HTML loses its content. The text between the tags joins the text before it, and the element is left empty. The same line in a paragraph or a blockquote parses correctly. It happens with every inline tag I tried (b, kbd, sub, script).

It started in 0.8.0 with the token processor refactor (#401). In packages/comark/src/internal/parse/tree.ts, paragraph_open passes nestHtml = state.insideMarkdownContainer === 0 to processChildren. Inside a block component that's false, so the inline text isn't delivered into the open HTML element, while the element itself is still created.

Additional context

Found while moving comark-plugins to 0.8.1: inline HTML inside annotate's notes and inside tabs renders wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions