Closed SamyPesse closed 3 years ago
This seems to be the same as some part of remarkjs/remark-gfm#16 (specifically last sentence in my comment here: https://github.com/remarkjs/remark-gfm/issues/16#issuecomment-843314610).
It’s annoying because GitHub is buggy. See here how they render different in readmes from comments/issues/prs: https://gist.github.com/wooorm/076fd173c31ba6837f17591d5932476e#file-autolink-algo-2-character-reference-md
The output of unified et al gives:
import {toHtml} from 'hast-util-to-html'
import {toHast} from 'mdast-util-to-hast'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {
gfmAutolinkLiteralFromMarkdown,
gfmAutolinkLiteralToMarkdown
} from './index.js'
const input = `
~~~markdown
[ https://example.com
[ https://example.com
https://example.com
https://example.com
~~~
[ https://example.com
[ https://example.com
https://example.com
https://example.com
`
const actual = toHtml(
toHast(
fromMarkdown(input, {
extensions: [gfmAutolinkLiteral],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
})
)
)
console.log(actual)
<pre><code class="language-markdown">[ https&#x3A;//example.com
[ https://example.com
https&#x3A;//example.com
https://example.com
</code></pre>
<p>[ <a href="https://example.com">https://example.com</a>
[ https://example.com
https://example.com
https://example.com</p>
This does not match either of the algorithms. However, I’d lean towards how GitHub renders readmes as “standard” whereas comments are buggy. So, I’d think unified et al should match readmes. This is different from your statement on proposed outcome though: “Instead it should be parsed the same way as GitHub does, as a pure text node.”
Hi! This was closed. Team: If this was fixed, please add phase/solved
. Otherwise, please add one of the no/*
labels.
I’ve applied a fix to better match how GitHub renders readmes.
Initial checklist
Affected packages and versions
mdast-util-gfm-autolink-literal@1.0.0
Link to runnable example
No response
Steps to reproduce
Considering this broken markdown string (extracted from one of our user content):
Using the following JS code:
it results in the following tree:
Expected behavior
Instead it should be parsed the same way as GitHub does, as a pure text node.
Actual behavior
Links are detected in the content. It results in a tree containing links. It also causes a bigger issue where the following is not true:
input > parsed > markdown > parsed2 > markdown2
andmarkdown !== markdown2
.Runtime
Node v14
Package manager
yarn v2
OS
macOS
Build and bundle tools
esbuild