marktext / marktext

📝A simple and elegant markdown editor, available for Linux, macOS and Windows.
https://www.marktext.cc/
MIT License
46.68k stars 3.48k forks source link

Line breaks (not paragraph breaks) ignored when exporting to PDF / HTML #3676

Open SwissArmyWrench opened 1 year ago

SwissArmyWrench commented 1 year ago

Description

Line breaks that are not paragraph breaks are ignored when exporting as PDF/HTML.

Steps to reproduce

  1. Open MarkText to a new blank document.
  2. Type text of your choice, advancing to new lines via line break (Shift + Enter) rather than paragraph break (Enter)
  3. Export the file as either HTML or PDF (the behavior is the same for both)
  4. Open the exported file.

Expected behavior: One would expect the line breaks to be rendered in the PDF/HTML export the same was as they are shown in Marktext.

Actual behavior: The line breaks have been ignored and the text runs together as if it was only separated by spaces, breaking whatever formatting you had in your original Markdown file.

Versions

memen45 commented 6 months ago

Same issue here! While GitHub markdown does add the lines correctly. Quite an annoyance! Is it an issue within marktext or some external library that is used?

memen45 commented 6 months ago

https://github.com/marktext/marktext/blob/4fef4498b57a283aad6c6ced2cad3003a7d3bc49/src/muya/lib/parser/marked/parser.js#L70

It seems that

In the lexer a paragraph is seen here: https://github.com/marktext/marktext/blob/4fef4498b57a283aad6c6ced2cad3003a7d3bc49/src/muya/lib/parser/marked/lexer.js#L531-L534 And here is also the place where \n is replaced with an empty string. So this is probably where the cause is: the multiple lines are seen as a single paragraph, and thus the \n are removed.

There is an option right above the line, which is 'disableInline', however, as I see it, it is not and cannot be passed to the exportHtml function here https://github.com/marktext/marktext/blob/4fef4498b57a283aad6c6ced2cad3003a7d3bc49/src/muya/lib/utils/exportHtml.js#L133

So, in short, this would require an additional option setting to set disableInline option to the renderer?