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

Normalising Line-Endings #64

Open
href opened this issue Sep 20, 2018 · 1 comment
Open

Normalising Line-Endings #64

href opened this issue Sep 20, 2018 · 1 comment
Labels

Comments

@href
Copy link

href commented Sep 20, 2018

When \r\n is used for line endings, the behaviour can be a bit surprising:

>>> from mistletoe import Document, HTMLRenderer

>>> HTMLRenderer().render(Document("foo  \r\nbar"))
'<p>foo  \r\nbar</p>\n'

>>> HTMLRenderer().render(Document("foo  \nbar"))
'<p>foo<br />\nbar</p>\n'

I stumbled on this today and I thought I'd report it. Not sure what the correct behaviour should be though. I only found it mentioned here: https://talk.commonmark.org/t/carriage-returns-and-code-blocks/2519

@miyuchina
Copy link
Owner

I can't find any authoritative answers from CommonMark either. I used to replace \r\n line endings with \n in Document.__init__, but stopped doing so after I discovered that Python's open function automatically normalizes line endings. See the documentation on open's newline parameter.

Is there a reason you would want to pass in raw strings with CRLF line-endings to mistletoe? It is an easy fix--I just need to add one line in Document.__init__, but it will incur some performance cost where the normalization is otherwise not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants