micromark / micromark

small, safe, and great commonmark (optionally gfm) compliant markdown parser

Home Page:https://unifiedjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

regression: link references w/o definition are ignored

tripodsan opened this issue · comments

Subject of the issue

With the old remark parser, link references that didn't have a corresponding definition were nonetheless detected and converted to mdast.

for example, the following:

> [!NOTE]
> This is a note. Who'd have noted?

used to generate:

{
  "type": "root",
  "children": [
    {
      "type": "blockquote",
      "children": [
        {
          "type": "paragraph",
          "children": [
            {
              "type": "linkReference",
              "identifier": "!note",
              "label": "!NOTE",
              "referenceType": "shortcut",
              "children": [
                {
                  "type": "text",
                  "value": "!NOTE"
                }
              ]
            },
            {
              "type": "text",
              "value": "\nThis is a note. Who'd have noted?"
            }
          ]
        }
      ]
    }
  ]
}

With micromark, the linkReference is not inserted, if there is no corresponding definition and a plain paragraph is genererated:

{
  "type": "root",
  "children": [
    {
      "type": "blockquote",
      "children": [
        {
          "type": "paragraph",
          "children": [
            {
              "type": "text",
              "value": "[!NOTE]\nThis is a note. Who’d have noted?"
            }
          ]
        }
      ],
    }
  ],
}

Expected behavior

It should still generate a linkReference node in the mdast, so that the client of the mdast can decide how to handle a missing definition.

Actual behavior

the parser ignores the link reference if no definition is defined.

This isn't a regression this is to spec

well, depends how you look at it :-)

of course, the transformation of that markdown to HTML (or whatever) can still be according to spec (i.e. just rendering the [!Note] if the definition is not set).

IMO the parser should not throw away the semantic information of the potential link reference.

this was the behaviour in the previous remark parser: mdast contains the link reference, but remark-stringify renders the plain link text if the definition is not present.

commented

well, depends how you look at it :-)

Every change can be seen as a “regression” if you look at it negatively, but if you look at it positively, it’s a fix. This is documented in the remark changelog: https://github.com/remarkjs/remark/releases. It is the biggest change, and I’ve discussed in with many different folks. I’ve also raised several issues with CommonMark. As this is emphasis: [text *emphasis start][undefined] emphasis end*, we can’t do what we did before / you want, while supporting CommonMark.

we can’t do what we did before / you want, while supporting CommonMark.

I understand. but the emphasis example is probably an edge case :-), where having a link reference with a non definition not so much.

would it be possible to make it configurable?

commented

It’s the same, because you want it to be a link reference without a definition, and I want it emphasis.
Anyway, it gets way more confusing, see the tests:

.

Would it be possible to make it configurable?

What’s the benefit of non-standard markdown? Why do you want that? Or this particularly? How would it work in the example I posted before, or with the other cases in the tests?

See also: micromark/common-markup-state-machine#14

What’s the benefit of non-standard markdown?

where in the standard is it defined that link references must have a valid definition?

Why do you want that? Or this particularly?

to ease the transition to the new version :-) i guess the best is to write an extension that detects the [!abc] links (similar to footnotes)

How would it work in the example I posted before, or with the other cases in the tests?

it wouldn't :-)

commented

where in the standard is it defined that link references must have a valid definition?

The required matching is described here: https://spec.commonmark.org/0.29/#reference-link

to ease the transition to the new version :-)

What is the benefit of a slow tradition instead of ripping the bandaid off and conforming to other markdown parsers?

i guess the best is to write an extension that detects the [!abc] links (similar to footnotes)

Yes, that might work!

While extensions are possible my personal opinion is that extensions are bad for the language. It won’t render here on GitHub. It creates lock-in: folks can’t export their “markdown” because it doesn’t render anywhere else. If you really really need to do it, maybe directives are an option. Several projects are going in that direction.

thanks for your answer and patience.