Skip to content

[Compatibility] Automatic Removal of Empty Lines #1354

Open

Description

@Fuzen777

MarkText 0.15.0 | Windows 10

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.

Activity

  1. fxha commented on Sep 23, 2019

    @fxha
    Contributor

    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 &nbsp instead.

  2. added
    🦁 need discuss
    on Sep 23, 2019
  3. Jocs commented on Sep 24, 2019

    @Jocs
    Member

    I don't fully understand this question. Do you want Mark Text to keep all the blank(empty) lines?

    before:

    abc
    <empty line>
    <empty line>
    def

    expect after save:

    abc
    <empty line>
    <empty line>
    def

    Mark Text format the content:

    abc
    <only one empty line>
    def
  4. Fuzen777 commented on Sep 24, 2019

    @Fuzen777
    Author

    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 &nbsp 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.

  5. fxha commented on Sep 25, 2019

    @fxha
    Contributor

    @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.

  6. kureus commented on Dec 6, 2019

    @kureus

    @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.

  7. fxha commented on Dec 7, 2019

    @fxha
    Contributor

    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:

    1. render process -> main process: load file by given path
    2. main: load the given file (decoding etc)
    3. 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.

  8. kureus commented on Dec 10, 2019

    @kureus

    @fxha Thanks for the guidance, I'll take a look.

  9. zhengpd commented on Feb 23, 2020

    @zhengpd
    Contributor

    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.

  10. Jocs commented on Feb 23, 2020

    @Jocs
    Member

    @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.

  11. ejabu commented on Apr 19, 2020

    @ejabu

    @fxha Thanks for the guidance, I'll take a look.

    how is it going ?

  12. brainchild0 commented on Apr 29, 2020

    @brainchild0
    Contributor

    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.

  13. fxha commented on Jun 6, 2020

    @fxha
    Contributor

    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.

  14. changed the title [-][Compatibility] Automatic Removal of Empty Lines & Non-Breaking Spaces[/-] [+][Compatibility] Automatic Removal of Empty Lines[/+] on Jun 6, 2020
  15. added
    🐸 markdown/spec
    on Jun 6, 2020
  16. joe-123 commented on Sep 17, 2022

    @joe-123

    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 "&nbsp" is not exactely intuitive xD

  17. R-Studio commented on Feb 13, 2023

    @R-Studio

    Any news?

  18. PwrSrg commented on Apr 12, 2024

    @PwrSrg

    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.

  19. joaokalva commented on Jun 28, 2024

    @joaokalva

    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.

  20. izqBR00 commented on Jul 10, 2025

    @izqBR00

    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

  21. Curosiz commented on Sep 23, 2026

    @Curosiz

    I am commenting here as I believe this is relevant to the discussion.

    I created a Markdown file containing empty lines like this:

    Image

    When opened in MarkText, it is displayed with the empty lines completely ignored:

    Image

    In this state, I added a line break between the two lines of "texttexttext" and saved the file:

    Image

    When I open the saved file in another plain text editor, the empty lines increase to three:

    Image

    Next, I opened this file again along with another file in a separate tab:

    Image

    After adding a line break, switching to the other tab, and then switching back, the newly added line break disappears:

    Image Image

    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:

    Image

    Thank you for your consideration.

  22. self-assigned this
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🐸 markdown/spec🦁 need discuss

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions