syntax-tree / mdast-util-from-markdown

mdast utility to parse markdown
MIT License
196 stars 19 forks source link

Parser confusion with nested emphasis suffixed with star #15

Open ChristianMurphy opened 3 years ago

ChristianMurphy commented 3 years ago

Subject of the issue

***a*a*a* a*

is parsed as

{
    "type": "root",
    "children": [
        {
            "type": "paragraph",
            "children": [
                {
                    "type": "text"
                },
                {
                    "type": "emphasis",
                    "children": [
                        {
                            "type": "emphasis",
                            "children": [
                                {
                                    "type": "text"
                                }
                            ]
                        },
                        {
                            "type": "text"
                        },
                        {
                            "type": "emphasis",
                            "children": [
                                {
                                    "type": "text"
                                }
                            ]
                        },
                        {
                            "type": "text"
                        }
                    ]
                }
            ]
        }
    ]
}

while in CommonMark it parses as

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
  <paragraph>
    <emph>
      <emph>
        <emph>
          <text>a</text>
        </emph>
        <text>a</text>
      </emph>
      <text>a</text>
    </emph>
    <text> a</text>
    <text>*</text>
  </paragraph>
</document>

Not the difference in the depth of emphasis two vs three.

Your environment

Steps to reproduce

const parse = require("mdast-util-from-markdown");

parse("***a*a*a* a*")

Expected behavior

Three levels of emphasis

Actual behavior

Two levels of emphasis

github-actions[bot] commented 2 years ago

Hi! This was marked as ready to be worked on! Note that while this is ready to be worked on, nothing is said about priority: it may take a while for this to be solved.

Is this something you can and want to work on?

Team: please use the area/* (to describe the scope of the change), platform/* (if this is related to a specific one), and semver/* and type/* labels to annotate this. If this is first-timers friendly, add good first issue and if this could use help, add help wanted.

wooorm commented 2 years ago

Another same/similar example: https://github.com/unifiedjs/unified/discussions/160#discussioncomment-1379260