#6321·astryx

[Bug] Markdown: escaped closing brackets in inline link text prevent link parsing

Author: sunrioaCreated Sep 14, 2026Updated Sep 14, 2026
Labelsbug

Description

An escaped closing bracket (\]) inside inline link text is treated as the end of the label. Valid Markdown is consequently emitted as text instead of a link.

markdown
[\[DISCUSS\] Clarify](https://example.com)

Expected: one link to https://example.com, with the visible label [DISCUSS] Clarify.

Actual: only text nodes are returned; no link node is produced.

CommonMark 0.31.2 §6.3 allows escaped brackets in link text. §2.4 specifies that escaped punctuation loses its Markdown meaning.

Reproduction

Execute parseInline() from packages/core/src/Markdown/parser.ts at commit f138ed997b88e4dc4361e73b388bd4b1d8a47bf4:

typescript
parseInline('[\\[DISCUSS\\] Clarify](https://example.com)');

Expected:

json
[
  {
    "type": "link",
    "href": "https://example.com",
    "children": [
      {
        "type": "text",
        "content": "[DISCUSS] Clarify"
      }
    ]
  }
]

Multiple adjacent text children would also be acceptable; the important result is one link containing the complete label.

Actual:

json
[
  {
    "type": "text",
    "content": "["
  },
  {
    "type": "text",
    "content": "[DISCUSS"
  },
  {
    "type": "text",
    "content": "] Clarify](https://example.com)"
  }
]

A smaller failing case:

typescript
parseInline('[a\\]b](https://example.com)');

Controls that parse successfully:

typescript
parseInline('[Clarify](https://example.com)');
parseInline('[a\\[b](https://example.com)');

The failing inputs also produce no link with {autolink: 'gfm'}.

Source observation

The inline-link branch selects the first closing bracket without checking whether it is escaped:

typescript
const textClose = text.indexOf(']', i + 1);

For the first reproduction, it selects the escaped bracket after DISCUSS. The following character is a space rather than (, so the inline-link match fails.

Source at the tested commit.

Related work

#3621 added reference-style link support. This report concerns escaped closing brackets in inline-link text.

Astryx Version

Source at commit f138ed997b88e4dc4361e73b388bd4b1d8a47bf4

Environment

  • macOS
  • Node.js v22.23.1
  • Executed the unmodified upstream parser after stripping TypeScript types with Node.js.
  • No browser required.

AI assistance: OpenAI Codex assisted with source inspection, standalone reproduction, duplicate searches, and drafting this issue. I reviewed and approved the final report before submission.