Skip to content

:name[…] content is terminated at the first ] — images and links inside components break #303

Description

@sandros94

Environment

  • Operating System: Linux (WSL2)
  • Node Version: v24.17.0
  • Package Manager: pnpm@11.11.0
  • Comark Version: 0.5.1 (reproduces on current main)
  • Framework: None

Comark Version

v0.5.1

Reproduction

import { parse } from 'comark'

console.log(JSON.stringify((await parse('See :badge[![icon](i.png)] here')).nodes))
// [["p",{},"See ",["badge",{},"!["],"(i.png)] here"]]   ← chopped at the `]` of `![`

console.log(JSON.stringify((await parse('See :badge[[docs](https://x.dev)] b')).nodes))
// same shape — the link half-parses outside the component

Description

parseBracketContent scans for the first unescaped ] with no depth tracking, so any bracket-bearing construct inside a component's content — images, links, nested [spans] — terminates it early and spills the remainder into the paragraph as corrupted text. This is plain hand-written markdown, no stringifier involved.

The inline span rule already does depth counting, which is why [![icon](i.png)]{.cls} parses fine while :badge[![icon](i.png)] doesn't. Sharing that scan fixes both call sites at once (inline component and block fence params, so ::card[![alt](i.png)] too).

Known residual once depth-counted: a code span containing ] inside the content (:badge[`a]b`]) still mis-parses, a bracket counter can't see backticks. Rare enough that I'd document it rather than special-case it, but personal preference

also for this one fix + tests ready locally, PR incoming

Additional context

Adjacent area to #287 / #288 (bracketed link labels), the fix keeps #288's behavior intact, its SPEC fixtures stay green. Distinct from #256 (consecutive inline components), which is about component start detection, not content termination.

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions