Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkdownRenderer should emit extra newline after list #211

Closed
ahelwer opened this issue Jan 14, 2024 · 4 comments
Closed

MarkdownRenderer should emit extra newline after list #211

ahelwer opened this issue Jan 14, 2024 · 4 comments

Comments

@ahelwer
Copy link

ahelwer commented Jan 14, 2024

Using latest version 1.2.1. Here's a simple round-trip python script:

from mistletoe import Document
from mistletoe.markdown_renderer import MarkdownRenderer

d = None
with open('test.md', 'r') as f:
    d = Document(f)

with open('test.md', 'w') as f:
    with MarkdownRenderer() as r:
        f.write(r.render(d))

If I run this script on this markdown file:

- Item1
- Item2
- Item3

Some text

it will output:

- Item1
- Item2
- Item3
Some text

if I run it again on this output, it will produce:

- Item1
- Item2
- Item3
  Some text

So the text has become part of the final list item, changing the document layout. The same behavior is also exhibited with ordered lists.

@ahelwer
Copy link
Author

ahelwer commented Jan 15, 2024

There are actually quite a few places where newlines are deleted, changing the formatting (sticking paragraphs together and such).

@pbodnar
Copy link
Collaborator

pbodnar commented Jan 15, 2024

@ahelwer, works for me. I guess you are experiencing #64 rather than a problem with MarkdownRenderer. Can you please confirm?

@ahelwer
Copy link
Author

ahelwer commented Jan 15, 2024

I don't think so, I'm on Linux and running file -k test.md outputs test.md: ASCII text so the line endings are just \n.

@pbodnar
Copy link
Collaborator

pbodnar commented Jan 18, 2024

I'm sorry, looking at it again and I am actually able to reproduce. And it looks like you are experiencing #56 then. :)

I.e. change your code to the following and the MarkdownRenderer will work correctly (because the renderer will manage to add its BlankLine and other tokens to the parsing process):

from mistletoe import Document
from mistletoe.markdown_renderer import MarkdownRenderer

with MarkdownRenderer() as r:
    with open('test.md', 'r') as f:
        d = Document(f)
    with open('test.md', 'w') as f:
        f.write(r.render(d))

So I'm closing this as answered. Feel free to reopen by commenting on this issue.

@pbodnar pbodnar closed this as completed Jan 18, 2024
shtrom added a commit to shtrom/shtrom that referenced this issue Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants