21

Why does the following Markdown:

> ```
# test

render as it does?

<h1>test</h1>

Yes, you see that right: the # is converted even though it's inside a code block. Furthermore, it's converted into other source code, not HTML. Properly terminating the code block with another ``` doesn't help. This behaviour only happens inside a blockquote;

```
# test

produces (as you would expect):

# test

Using another > as suggested by @JeffZeitlin also renders correctly;

> ```
> # test

becomes

# test
  • 1
    Ew. That looks like a bug. What happens if you blockquote each line of the code block?, e.g. line 1 >```, line 2 ># test ? – Jeff Zeitlin Oct 17 '19 at 14:44
  • This is freaky! How did you discover it? :O – Jeff Darwood Oct 17 '19 at 14:58
15

Because what you've done is confused the processor as to whether you opened a code block inside a blockquote or just a hard-wrapped paragraph, which allows for the > to be excluded while continuing the blockquote. If you're planning to use block-level elements inside a blockquote, you should be explicit about what you are trying to do. You can do that either by adding the > to explicitly mark it as part of the blockquote, or indenting it to bypass the blockquote and make it part of the code manually (a single space seems to work for "identation" here).

For what it's worth, that specific block wouldn't work in CommonMark either, which just completely breaks it because you are explicitly not allowed to use lazy line breaks to continue block elements inside of blockquotes.

So in Markdown, this is simply undefined behavior. In CommonMark, it is disallowed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .