gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.41k stars 173 forks source link

Fence code blocks rendering bug #204

Open prologic opened 3 years ago

prologic commented 3 years ago

The following piece of Markdown does not render correctly:

Hilariously it doesn't seem to render correctly with Github's own Markdown support in comments either πŸ˜‚ foo.md

prologic commented 3 years ago

Example:

would you know the regex to use within .muttrc to colorise a Markdown code block like the one below?

# This one works for `code`, but that's about it.
(^|[[:space:][:punct:]])\`[^\`]+\`([[:space:][:punct:]]|$)
prologic commented 3 years ago

Hilariously it doesn't seem to render correctly with Github's own Markdown support in comments either πŸ˜‚

Oh the above rendering worked just fine on Github, but falls over when you place the sample itself inside a code fence.

kjk commented 3 years ago

This is the html I get:

<p>would you know the regex to use within .muttrc to colorise a Markdown code block like the one below?</p>

<pre><code># This one works for `code`, but that's about it.
(^|[[:space:][:punct:]])\`[^\`]+\`([[:space:][:punct:]]|$)
</code></pre>

Which seems correct to me.

What do you get and what do you expect?

prologic commented 3 years ago

This is what I end up with:

DEBU[0051] md:
"would you know the regex to use within .muttrc to colorise a Markdown code block like the one below?\n\n```\n# This one works for ```code`, but that's about it.\n(^|[[:space:][:punct:]])\\`[^\\`]+\\`([[:space:][:punct:]]|$)\n``"
DEBU[0051] maybeUnsafeHTML:
"<p>would you know the regex to use within .muttrc to colorise a Markdown code block like the one below?</p>\n\n<p>&rdquo;`</p>\n\n<h1>This one works for &ldquo;<code>code</code>, but that&rsquo;s about it.</h1>\n\n<p>(^|[[:space:][:punct:]])`[^`]+`([[:space:][:punct:]]|$)<br>\n&rdquo;</p>\n"
DEBU[0051] html:
"<p>would you know the regex to use within .muttrc to colorise a Markdown code block like the one below?</p>\n\n<p>”`</p>\n\n<h1>This one works for β€œ<code>code</code>, but that’s about it.</h1>\n\n<p>(^|[[:space:][:punct:]])`[^`]+`([[:space:][:punct:]]|$)<br>\n”</p>\n"

I'm not actually sure what's going on here just yet... I need to analyze this a bit. Something is going wrong in this process and it may not be your library's fault πŸ˜‚

kjk commented 3 years ago

Here's the code to get the result I got: https://github.com/gomarkdown/markdown/blob/master/cmd/printast/main.go#L44

You might be pre-processing markdown before passing it to parser, postprocessing the html you get from the renderer or using different parser or renderer flags.

prologic commented 3 years ago

I'll dig a bit further and get back to you πŸ‘Œ