Closed tripodsan closed 3 years ago
btw, the serialization doesn't escape the hostname
const mdast = root([
paragraph([
link('https://richardianson.com/', undefined, [
strong([
text('www.richardianson.com'),
])
]),
]),
]);
const doc = unified()
.use(stringify)
.use(gfm)
.stringify(mdast);
console.log(doc);
gives:
[**www.richardianson.com**](https://richardianson.com/)
so, it's rather hard to handle this properly in the client. the only workaround is to move all formattings out of the link children.
What GFM (well, github.com, because it’s not documented in GFM and doesn’t work like CM) seems to be doing here is rather complex... Take this markdown:
**www.a.com**](b)
Yields:
www.a.com](b)
^ So, all the characters are valid in a URL. And the attention (strong) does not “break out” of the URL. Nor does the label end (](b)
).
Whereas:
[**www.a.com**](b)
Yields:
^ So, apparently, the URLs are parsed after the label end matches a label start. But before attention (**
) is parsed? 🤔
For serialization, link
and image
might have to be removed, if I can’t think of anything else
this should all be fixed with https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/commit/a2fac797b315885cf6e279eb7577f1db3a8562e4 btw!
Subject of the issue
Consider the following markdown:
which renders correctly on github: www.richardianson.com
but with
mdast-util-gfm-autolink-literal
, it parses to:instead of:
workaround
escape the hostname: