You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Compatibility] Automatic Removal of Empty Lines #1354
MarkText automatically trims empty lines. That sounds like a good idea, but factually, it's not always the case. When you open a file which is not formatted for the strict standards required by MarkText, it will usually break the layout. (And if autosave is on, that can lead to disastrous results.)
So for the sake of compatibility, I'd like to request a feature: a way to control that behavior. Ideally, perhaps a to the number of trimmed lines? So anything beyond that amount is trimmed, but anything below isn't touched.
Likewise, it automatically replaces non-breaking spaces with regular ones. So if you are using those before punctuations, it will replace them… which again can lead to disastrous results.
Reacted by Zineddine Saibi, Mike, Kristen McWilliam, Alexandry Augustin, Alexey Goussev, Martin Prinzler, Nesaijn, liquidblasted, azou, joe-123 and 10 more
Thanks @Fuzen777 for opening the issue. Mark Text follows the CommonMark and GitHub Flavored Markdown specification that requires to trim empty lines and only allow one new line between paragraphs. @Jocs What do you think about this? It would require "just" a parser (markedjs) change because muya has a loose behavior on this and accept multiple new lines.
Likewise, it automatically replaces non-breaking spaces with regular ones.
Could you please open another issue for this? In the meantime you may use   instead.
Ah indeed. CommonMark doesn't provide a hard line-break method at the end of a paragraph, except by using <br/>. It's usually better since it leaves no ambiguity but remains the problem of compatibility with files that were using GFM's version.
I don't know if it's possible to implement, but what about this? When opening a document where MarkDown detects two or more consecutive white lines, ask the user if it should either trim them or replace them with <br/>? That would both solve the compatibility issue and update the files to be CommonMark-compliant.
Could you please open another issue for this? In the meantime you may use   instead.
I have literally hundreds of files using so that's really not an option.
When I tried to reproduce that behavior to identify the cause, I found myself unable to do so. I'll open a new issue as soon as I pinpoint the problematic behavior.
@Fuzen777 Non-breaking spaces were removed from our markdown parser marked.js. The issue was solved upstream and v0.16.0 will not remove non-breaking spaces any more. I'll summit a patch for this later.
@fxha Continuing the discussion around supporting consecutive empty lines, would you be open to a PR with the suggested parser change and some associated functionality and configuration?
Expanding on @Fuzen777's suggestion, if Marktext opens a file with consecutive empty lines and does not yet have any stored configuration around this it could present 3 options to the affect of
Always trim consecutive empty lines
Always preserve consecutive empty lines
Ask me each time I open a file with consecutive empty lines
With an associated config menu option that could be updated at any point.
Reacted by Losiki, Kristen McWilliam, Alexey Goussev, Martin Prinzler, timatpam and Daniel Andrade
Thanks @kureus, contributions are always welcome 👍 I think the easiest solution is to add a settings option and change Muya's and our marked.js implementation accordingly but we should prefer to always trim empty lines due to markdown specification. I would also like to see the user selection/dialog per tab/file but I don't really know whether is possible to add it to Mark Text's editor structure without changing to much.
To break down our current data flow:
render process -> main process: load file by given path
main: load the given file (decoding etc)
main -> renderer: initialize tab (Muya/editor)
here we parse the markdown string and tokenize
If you want, you could start with the first part without user interaction, only settings option, and summit another PR to finish the user dialog.
Edit: I guess you need to edit our markdown parser (marked.js), importer and exporter (Muya - import/exportMarkdown.js) to be able to keep whitespaces.
Could there be an option to turn off trim empty lines or format file on open? Sometimes I like to Mark Text as markdown viewer only and never make any change on the file.
Reacted by NoOne, Alexey Goussev, Martin Prinzler, qouteall and Sergio Vazquez II
@zpdcodes At present, it is more difficult, because we first parse markdown into a format that Mark Text can recognize, such as a large json, but we don't remember how many blank lines between two blocks. When outputting, we assemble the json into text. A standard markdown file. we will only insert one blank line between blocks.
Reading this discussion, I find that two issues are conflated:
Whether saved file content must conform to syntax specification.
How to handle opened file content that does not conform to specification.
To me, the answers seem obvious. It is preferred to write file content following specification, but it is inevitable that opened files may not follow specification. Therefore, Mark Text should ensure that new content follows the specification, but should leave existing content unchanged even if it does not follow specification. When no changes are made to the text, none should be made to the file contents. When some changes are made to the text, minimal changes should be made to the file contents, even if the effect that some file content does not follow specification.
@zpdcodes At present, it is more difficult, because we first parse markdown into a format that Mark Text can recognize, such as a large json, but we don't remember how many blank lines between two blocks. When outputting, we assemble the json into text. A standard markdown file. we will only insert one blank line between blocks.
@Jocs, obviously, the implementation you describe makes it impossible to achieve the behavior suggested above. Rather, it would be required that the JSON tree preserve the original raw text from each syntax element in additional data fields. When new tree elements are added during the editing session, the raw text may be generated following the specification. However, unmodified elements could still be written to the file following the form of the original raw text.
It may seem helpful if the application always writes content that follows specification, but actually MarkDown content must never be owned by any single application or editor. MarkDown users expect that the editor does not always enforce its own rules, even good rules. If the application rewrites an entire file even if much of the text has not changed, then users will experience problems. It may be worthwhile to alter the approach for managing raw text even if extra implementation is required.
Even so, a feature that provides an action for cleaning the raw text of an open file, or for saving a cleaned version, may improve usability for cases when such behavior is desired.
Please see #2189 for details about the issue. I keep this issue open for discussion about the spacing issue. You may want to subscribe there for further updates.
changed the title [-][Compatibility] Automatic Removal of Empty Lines & Non-Breaking Spaces[/-][+][Compatibility] Automatic Removal of Empty Lines[/+]on Jun 6, 2020
As far as I can tell, there is still no easy way of keeping the blank lines, rigth?
For me, MarkText always removes all empty lines. Which regularely destroys the formating of my files.
Is there an easy way of changing this behaviour? Entering something like " " is not exactely intuitive xD
Reacted by yixuan, しんりんごろり, Esther, David Křístek, Rc, Maxwell, Robin Hermann, noktochielo, Calos, 白一梓 and 6 more
I am commenting here to share my frustrations as well. I have gone through basically all the markdown editor alternatives like Obisidan and Logseq, and just when I think I came across the perfect app, I realize it doesn't so something as simple as line breaks. Such a dealbreaker and a bummer.
Reacted by Kerim Mutlu, elzik, Hojjat, Izaque_Nogueira and Jonathan-Payne
Just commenting here to say that, although there is an option in the menu to disable the trimming, it still isn't working. It's so frustrating because this app is almost perfect, almost
I am commenting here as I believe this is relevant to the discussion.
I created a Markdown file containing empty lines like this:
When opened in MarkText, it is displayed with the empty lines completely ignored:
In this state, I added a line break between the two lines of "texttexttext" and saved the file:
When I open the saved file in another plain text editor, the empty lines increase to three:
Next, I opened this file again along with another file in a separate tab:
After adding a line break, switching to the other tab, and then switching back, the newly added line break disappears:
Please make it so that empty lines are preserved.
Ideally, the empty lines should be displayed properly from the moment the file is first opened, like this:
Activity
fxha commentedon Sep 23, 2019
Thanks @Fuzen777 for opening the issue. Mark Text follows the CommonMark and GitHub Flavored Markdown specification that requires to trim empty lines and only allow one new line between paragraphs. @Jocs What do you think about this? It would require "just" a parser (markedjs) change because muya has a loose behavior on this and accept multiple new lines.
Could you please open another issue for this? In the meantime you may use
 instead.Jocs commentedon Sep 24, 2019
I don't fully understand this question. Do you want Mark Text to keep all the blank(empty) lines?
before:
expect after save:
Mark Text format the content:
Fuzen777 commentedon Sep 24, 2019
Ah indeed. CommonMark doesn't provide a hard line-break method at the end of a paragraph, except by using
<br/>. It's usually better since it leaves no ambiguity but remains the problem of compatibility with files that were using GFM's version.I don't know if it's possible to implement, but what about this? When opening a document where MarkDown detects two or more consecutive white lines, ask the user if it should either trim them or replace them with
<br/>? That would both solve the compatibility issue and update the files to be CommonMark-compliant.I have literally hundreds of files using
so that's really not an option.When I tried to reproduce that behavior to identify the cause, I found myself unable to do so. I'll open a new issue as soon as I pinpoint the problematic behavior.
fxha commentedon Sep 25, 2019
@Fuzen777 Non-breaking spaces were removed from our markdown parser marked.js. The issue was solved upstream and v0.16.0 will not remove non-breaking spaces any more. I'll summit a patch for this later.
kureus commentedon Dec 6, 2019
@fxha Continuing the discussion around supporting consecutive empty lines, would you be open to a PR with the suggested parser change and some associated functionality and configuration?
Expanding on @Fuzen777's suggestion, if Marktext opens a file with consecutive empty lines and does not yet have any stored configuration around this it could present 3 options to the affect of
With an associated config menu option that could be updated at any point.
fxha commentedon Dec 7, 2019
Thanks @kureus, contributions are always welcome 👍 I think the easiest solution is to add a settings option and change Muya's and our marked.js implementation accordingly but we should prefer to always trim empty lines due to markdown specification. I would also like to see the user selection/dialog per tab/file but I don't really know whether is possible to add it to Mark Text's editor structure without changing to much.
To break down our current data flow:
If you want, you could start with the first part without user interaction, only settings option, and summit another PR to finish the user dialog.
Edit: I guess you need to edit our markdown parser (marked.js), importer and exporter (Muya -
import/exportMarkdown.js) to be able to keep whitespaces.kureus commentedon Dec 10, 2019
@fxha Thanks for the guidance, I'll take a look.
zhengpd commentedon Feb 23, 2020
Could there be an option to turn off
trim empty linesorformat file on open? Sometimes I like to Mark Text as markdown viewer only and never make any change on the file.Jocs commentedon Feb 23, 2020
@zpdcodes At present, it is more difficult, because we first parse markdown into a format that Mark Text can recognize, such as a large
json, but we don't remember how many blank lines between two blocks. When outputting, we assemble the json into text. A standard markdown file. we will only insert one blank line between blocks.ejabu commentedon Apr 19, 2020
how is it going ?
brainchild0 commentedon Apr 29, 2020
Reading this discussion, I find that two issues are conflated:
To me, the answers seem obvious. It is preferred to write file content following specification, but it is inevitable that opened files may not follow specification. Therefore, Mark Text should ensure that new content follows the specification, but should leave existing content unchanged even if it does not follow specification. When no changes are made to the text, none should be made to the file contents. When some changes are made to the text, minimal changes should be made to the file contents, even if the effect that some file content does not follow specification.
@Jocs, obviously, the implementation you describe makes it impossible to achieve the behavior suggested above. Rather, it would be required that the JSON tree preserve the original raw text from each syntax element in additional data fields. When new tree elements are added during the editing session, the raw text may be generated following the specification. However, unmodified elements could still be written to the file following the form of the original raw text.
It may seem helpful if the application always writes content that follows specification, but actually MarkDown content must never be owned by any single application or editor. MarkDown users expect that the editor does not always enforce its own rules, even good rules. If the application rewrites an entire file even if much of the text has not changed, then users will experience problems. It may be worthwhile to alter the approach for managing raw text even if extra implementation is required.
Even so, a feature that provides an action for cleaning the raw text of an open file, or for saving a cleaned version, may improve usability for cases when such behavior is desired.
fxha commentedon Jun 6, 2020
Please see #2189 for details about the issue. I keep this issue open for discussion about the spacing issue. You may want to subscribe there for further updates.
[-][Compatibility] Automatic Removal of Empty Lines & Non-Breaking Spaces[/-][+][Compatibility] Automatic Removal of Empty Lines[/+]joe-123 commentedon Sep 17, 2022
As far as I can tell, there is still no easy way of keeping the blank lines, rigth?
For me, MarkText always removes all empty lines. Which regularely destroys the formating of my files.
Is there an easy way of changing this behaviour? Entering something like " " is not exactely intuitive xD
R-Studio commentedon Feb 13, 2023
Any news?
PwrSrg commentedon Apr 12, 2024
This is the #1 reason I had to stop using MarkText. The other reason was the "Document is modified when opened" nightmare.
If it weren't for these two simple issues, the application would be nearly PERFECT.
joaokalva commentedon Jun 28, 2024
I am commenting here to share my frustrations as well. I have gone through basically all the markdown editor alternatives like Obisidan and Logseq, and just when I think I came across the perfect app, I realize it doesn't so something as simple as line breaks. Such a dealbreaker and a bummer.
izqBR00 commentedon Jul 10, 2025
Just commenting here to say that, although there is an option in the menu to disable the trimming, it still isn't working. It's so frustrating because this app is almost perfect, almost
Add Light Touch mode to preserve original whitespace on save
Curosiz commentedon Sep 23, 2026
I am commenting here as I believe this is relevant to the discussion.
I created a Markdown file containing empty lines like this:
When opened in MarkText, it is displayed with the empty lines completely ignored:
In this state, I added a line break between the two lines of "texttexttext" and saved the file:
When I open the saved file in another plain text editor, the empty lines increase to three:
Next, I opened this file again along with another file in a separate tab:
After adding a line break, switching to the other tab, and then switching back, the newly added line break disappears:
Please make it so that empty lines are preserved.
Ideally, the empty lines should be displayed properly from the moment the file is first opened, like this:
Thank you for your consideration.