Skip to content

Parser incorrectly splits nested emphasis in *(*foo*)* #1484

@tidefield

Description

@tidefield

Description

*(*foo*)* is parsed incorrectly, producing a different AST than expected per the CommonMark spec.

Input

*(*foo*)*

Expected behavior

Per CommonMark spec example 343, this should parse as nested emphasis:

<p><em>(<em>foo</em>)</em></p>

The CommonMark dingus confirms this interpretation.

Actual behavior

remark parses this as two separate emphasis nodes with plain text in between:

paragraph
  emphasis [0..3]    -> wraps "("
    text "("
  text "foo"
  emphasis [6..9]    -> wraps ")"
    text ")"

Instead of:

paragraph
  emphasis [0..9]    -> wraps everything
    text "("
    emphasis [2..7]  -> wraps "foo"
      text "foo"
    text ")"

Reproducible example

import remarkParse from "remark-parse";
import { unified } from "unified";

const tree = unified().use(remarkParse).parse("*(*foo*)*");
console.log(JSON.stringify(tree.children[0], null, 2));

Or via Prettier 3.8.1 (which uses remark):

const prettier = require("prettier");
const { ast } = await prettier.__debug.parse("*(*foo*)*", { filepath: "test.md" });
console.log(JSON.stringify(ast.children[0], null, 2));

Metadata

Metadata

Assignees

No one assigned

    Labels

    🤞 phase/openPost is being triaged manually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions