markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Fence code blocks rendering bug

Open prologic opened this issue 4 years ago β€’ 6 comments

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 avatar Oct 16 '21 21:10 prologic

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 avatar Oct 16 '21 21:10 prologic

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.

prologic avatar Oct 16 '21 21:10 prologic

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?

kjk avatar Oct 16 '21 23:10 kjk

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 πŸ˜‚

prologic avatar Oct 17 '21 00:10 prologic

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.

kjk avatar Oct 17 '21 01:10 kjk

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

prologic avatar Oct 17 '21 08:10 prologic