mistune icon indicating copy to clipboard operation
mistune copied to clipboard

Tab indented block after heading is rendered as code

Open guerda opened this issue 1 year ago • 1 comments

Here's an odd behavior of mistune version 3.0.2. If you indent a line with text with a tab after a heading (level does not matter), mistune automatically renders the following block as code.

If you indent with spaces, it renders correctly. If you add a different line before, it renders correctly.

>>> mistune.__version__
'3.0.2'
>>> mistune.markdown("""# Test
...   test with spaces""")
'<h1>Test</h1>\n<p>test</p>\n'
>>> mistune.markdown("""# Test
...     test with tab""")
'<h1>Test</h1>\n<pre><code>test</code></pre>\n'
>>> mistune.markdown("""# Test
...   first a line with spaces
...     test with tabs""")
'<h1>Test</h1>\n<p>first a line with spaces\ntest with tabs</p>\n'
>>> mistune.markdown("""# Test
...     test with tabs
...     and many more
...     lines""")
'<h1>Test</h1>\n<pre><code>test with tabs\nand many more\nlines</code></pre>\n'

guerda avatar Mar 06 '24 15:03 guerda

It seems that commonmark is doing the same:

https://spec.commonmark.org/dingus/?text=%3Csome-tag%3E%0A%0A%23%20a%20comment%0Asomething%20with%20%23%20a%20trailing%20comment%0A%3C%2Fsome-tag%3E

guerda avatar Mar 06 '24 15:03 guerda

It is correct behavior.

lepture avatar Apr 08 '24 13:04 lepture