markdown-mode
markdown-mode copied to clipboard
Code blocks don't parse properly when in lists
When the beginning backticks of a codeblock are on the first line of a new list element (numbered, ordered, whatever), markdown-mode fails to parse the codeblock properly, and interprets the ending backticks as starting backticks.
As a result, whenever the user starts a list with a codeblock, then tries to edit it with C-', they'll get an error Not inside a GFM or tilde fenced code block. Also, if the codeblock happens to be a language that has a mode for it in emacs, the fontification fails - the contents of the codeblock are highlighted the default color.
This error is likely due to the parsing rule that requires the starting backticks of a codeblock to have whitespace before it. A correct rule would be whitespace preceding the backticks, or "list bullets" of any type preceding the backticks.
Steps to Reproduce
- Fill a markdown buffer with the following content:
1. ``` this is a codeblock ``` 2. This is normal text - Press C-' in the codeblock to edit it
- See Bug
- Replace the buffer contents with the following:
1. ``` this is a codeblock ``` 2. This is normal text 3. ``` the user thinks this is a new codeblock I think differently c; ``` - Press C-' in the second codeblock
- See Bug
I found this bug quite annoying when viewing/editing @logseq's Markdown notes in Emacs. Because all note entries are basically bullets and code fences will break syntax highlighting.
BTW Is this valid markdown syntax ? I couldn't find such examples in commonmark spec. Code block can be indented by spaces but other characters other than spaces can not be put before triple quotes.
As shown in the issue post, GitHub can render those code fences without a problem. So at least it is supported by GFM (I believe VS Code also supports this).
-
this is a codeblock - This is normal text
-
the user thinks this is a new codeblock I think differently c;
But in the Emacs Markdown mode, they will look like this screenshot:
