lepture / mistune

A fast yet powerful Python Markdown parser with renderers and plugins.
http://mistune.lepture.com/
BSD 3-Clause "New" or "Revised" License
2.59k stars 251 forks source link

parse -> render to markdown misses leading newlines, appends extra newline #366

Open nschloe opened 11 months ago

nschloe commented 11 months ago

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 = "\n\n\n\nabc"
tokens = markdown(md)

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

Output:

'abc\n'

Expected output:

"\n\n\n\nabc"