Skip to content

GitHub-style <details> block content is parsed outside the details element #235

Description

@pynickle

Environment

  • Operating System: Windows 11
  • Node Version: v24.16.0
  • Package Manager: bun@1.3.14
  • Comark Version: 0.4.0
  • Framework: Vue / Nuxt

Comark Version

v0.4.0

Reproduction

import { parse } from 'comark'

const markdown = `<details>
<summary>Original summary in English</summary>

xxx
</details>`

console.log(JSON.stringify((await parse(markdown)).nodes, null, 2))

Actual output:

[
  [
    "details",
    {
      "$": {
        "html": 1,
        "block": 1
      }
    },
    [
      "summary",
      {
        "$": {
          "html": 1,
          "block": 1
        }
      },
      "Original summary in English"
    ]
  ],
  [
    "p",
    {},
    "xxx"
  ]
]

Expected output should keep xxx inside the details node, for example:

[
  [
    "details",
    {
      "$": {
        "html": 1,
        "block": 1
      }
    },
    [
      "summary",
      {
        "$": {
          "html": 1,
          "block": 1
        }
      },
      "Original summary in English"
    ],
    [
      "p",
      {},
      "xxx"
    ]
  ]
]

Description

GitHub-style collapsed sections using <details> / <summary> are not parsed correctly when the <summary> line is followed by a blank line.

Input:

<details>
<summary>Original summary in English</summary>

xxx
</details>

In GitHub Markdown, the body content remains inside the <details> block and is hidden until expanded. GitHub's Markdown API renders this as:

Original summary in English

xxx

Comark currently parses xxx as a sibling after the details node. Framework renderers then faithfully render the AST as:

Original summary in English

xxx

This breaks GitHub-compatible rendering for collapsed sections.

The issue appears related to raw HTML block handling. <details> / <summary> are treated as block HTML, and the blank line after <summary> appears to terminate the HTML block before is reached.

Additional context

No response

Logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions