lepture/mistune

parse -> render loop causes newlines within quote blocks

nschloe opened this issue · 1 comments

Another parse->render loop newline issue. This one actually changes the output.

MWE:

import mistune
from mistune.core import BlockState
from mistune.renderers.markdown import MarkdownRenderer

# format_markdown = mistune.create_markdown(renderer=MarkdownRenderer())
markdown = mistune.create_markdown(renderer="ast")


md = "> #### Lorem\n> Ipsum"
tokens = markdown(md)

# from rich import print
# print(tokens)

renderer = MarkdownRenderer()
print()
print(renderer(tokens, state=BlockState()))

Output:

> #### Lorem

> Ipsum

The cause is an incorrect application of textwrap.indent. Behold

indent("a\n\nb", '> ')
'> a\n\n> b'