Python-Markdown/markdown

Fenced code blocks broken if containing empty lines

gynvael-hexarcana opened this issue · 2 comments

According to the documentation (and usual way markdown works) empty lines – including at the beginning and end – should work as expected. For example, the documentation shows this example:

Fenced code blocks can have a blank line as the first and/or last line of the code block and those lines will be preserved.


a three-line code block

However this doesn't seem to work in the current version of markdown library (tested on 3.6, though I think it's the same behavior on 3.5 and 3.4).

Example code:

import markdown

a = """
```

a three-line code block

```
"""

b = """
```
def func():

  return
```
"""

print(markdown.markdown(a))
print("-" * 70)
print(markdown.markdown(b))

Expected output: (give or take)

<p><code>
a three-line code block

</code></p>
----------------------------------------------------------------------
<p><code>def func():

  return</code></p>

Actual output:

<p>```</p>
<p>a three-line code block</p>
<p>```</p>
----------------------------------------------------------------------
<p>```
def func():</p>
<p>return
```</p>

Note: A workaround is to enable SuperFences extension.

Triple-backtick codeblocks are not part of standard Markdown syntax. You need to enable the Fenced Code extension in order to use them.

Note: it does not matter whether there are empty lines or not.

@mitya57 Thank you! I see I trolled myself testing this on lines like this:

```
One line
Two lines
```

...which now I see is just interpreted as "single backtick opening" "single backtick closing", "single backtick opening".

Whoops ;)
I'm closing the issue.