Skip to content

Document is modified when opened/Markdown formatting #2189

Open

Description

@fxha

Overview

The goal of this issue is to clarify automatic markdown formatting, the modification notification without any document interaction and further steps to improve the situation.

The document is always formatted

Some would say this is a great feature and others don't. Mark Text formats all content according CommonMark and GFM (+other extensions if enabled). The reason for this is that we don't store the document as string with spaces etc but as block structure with minimal information. As a side effect, we need to build the text file when saving the document. In some situations, we don't know the formatting of the original document and apply the default style according markdown specification.

Why is my document modified after opened?

That's an issue with our data structure/flow and cursor positioning but will hopefully fix soon as we (@Jocs) refactor the data structure and get rid of the old data flow. This should also bring better performance and extension support the core of the editor.

Next steps

It's currently not planned to change the markdown formatting as it's built-in into the editor but as we continuously improve our engine, we'll keep this issue in mind and try our best to overwrite as little as possible. The removal of empty lines is currently not addressed as it would require a significant work to our markdown parser and data structure (#1354).

TODO's:

This is a non-exclusive list for improvements that require changes to the markdown parser, data structure and other parts of the core engine:

Please feel free to contribute on these issues. Any development will be tracked here.

Activity

  1. added
    🐳 help wanted
    🦋 optimization
    🐸 markdown/spec
    on Jun 6, 2020
  2. brainchild0 commented on Jun 7, 2020

    @brainchild0
    Contributor

    Thanks for opening this topic. Since the discussion on this question so far has been, I think, fragmented, taking it into a central issue topic is extremely helpful.

    I think the core of the discussion is exactly the following:

    Some would say this is a great feature and others don't.

    It is useful to note that the the application might include support for rewriting the formatting elements (i.e. markup) of the document without doing so as a side effect of document editing. For example, in principle, a menu command might produce this effect, but only when manually invoked by the user (e.g. "Clean document formatting").

    I am glad that it is considered a bug that unmodified document buffers are marked as modified. However, the unmodified document being marked as modified is simply a special case of unmodified parts of an edited document being modified in the raw file.

    A very common case for editing Markdown documents is changing part of a document, but desiring a resulting file as close as possible to the original, in terms of lines, words, and characters. For example, in this use, inserting a single word, through the editing buffer, in some existing paragraph, would have the sole effect of adding that word to the raw document. Reasons for needing this behavior include integration with revision tracking systems and inclusion of non-standard markup. I believe that this use, for whatever reasons in each case, is common enough that support for it is necessary for an editor to become a popular and reliable application within the Markdown community.

    Clearly, as observed, this functionality depends on a more sophisticated internal representation of the document. I am wondering though whether the functionality is possible through very minimal enhancements to the document tree. It would seem necessary only to include with each node the original string representation (or offset bounds of some static buffer). Following a change to some part of a document in the editing buffer, the node might be marked dirty, or the string cleared, for a new value to be generated when the document is saved.

  3. aisbergde commented on Jun 7, 2020

    @aisbergde

    Mark Text formats all content according CommonMark and GFM (+other extensions if enabled). The reason for this is that we don't store the document as string with spaces etc but as block structure with minimal information.

    Thank you very much for the explanation. Now I understand some behaviors much better get a better idea how it works and why. I think this information is very important and should be available on a prominent place in the documentation, may even on the readme file.

    Knowing that you can understand marktext as an translator in well formatted markdown and use it this way. Don't knowing this you could be disappointed about marktext destroying content.

  4. aisbergde commented on Jun 7, 2020

    @aisbergde

    It would seem necessary only to include with each node the original string representation (or offset bounds of some static buffer).

    this would also allow to make changes to the raw text visible, which is normally not possible in "normal" editors, but can be done in Word. For example when I get the message that the file has changed it would be possible to compare changes.

  5. axelsimon commented on Jul 15, 2020

    @axelsimon

    Not sure if this is where to add this, but rather than open a new issue i'll comment here first:
    MarkText adds a lot of extraneous line breaks when formatting in Markdown. For instance, a bullet list i'd expect to be structured like this:

    this is a list:
    - item 1
    - item 2
    - item 3

    but the actual text file looks more like this:

    this is a list:
    
    - item 1
    
    - item 2
    
    - item 3
  6. brainchild0 commented on Aug 23, 2020

    @brainchild0
  7. pinned this issue on Aug 28, 2020
  8. brainchild0 commented on Aug 28, 2020

    @brainchild0
    Contributor

    (@axelsimon: Please see #2310.)

  9. laurent-simon commented on Oct 30, 2020

    @laurent-simon

    Automatic formatting can be a great feature, but only if it is done on demand. Currently, has it is, it is more a problem than a feature for my use cases.

    For example, Mark Text is problematic with existing files that are managed under Git. You can't edit only the parts that need to be be edited. Mark Text Introduces extra unexpected, and unwanted changes.

  10. aukeroorda commented on Nov 14, 2020

    @aukeroorda

    Also modified when toggling source code mode. Exported PDF is also modified, but doesn't change text buffer. Makes it unusable, as it partially removes footnotes (Pandoc-style enabled), and moves the remaining half to a different location, in between list items... Would be nice if we could just disable this completely in the options untill there is a better interface for it.

  11. 27 remaining items

  12. gatspy commented on Jun 19, 2024

    @gatspy

    every time open a file, it prompts me to save it when I close it, which is very annoying.

  13. elzik commented on Jan 13, 2025

    @elzik

    I use Markdown files created by Azure Devops, GitHub, Obsidian and others.

    This automated formatting makes MarkText overly opinionated and means I cannot use it. It's a shame because otherwise, it seems like a great tool.

  14. awxiaoxian2020 commented on Feb 23, 2025

    @awxiaoxian2020

    Do we have some workaround for this? Maybe we can get help from LLM?

  15. N0rbert commented on Feb 23, 2025

    @N0rbert

    I'm editing this comment again to say that mdSilo from https://github.com/mdSilo/mdSilo-app is not an option.
    It has WYSIWYG table editing, but also it made my 45 Kb real world document bad formatted and both remark and mdl linters are not happy with it. Reported an issue to their github.

    I'll continue to use ReText and Kate.

  16. stulluk commented on Feb 16, 2026

    @stulluk
  17. BlohoJo commented on Mar 7, 2026

    @BlohoJo

    I work with a lot of markdown files. This is a great viewer. But, I can't have it prompt me to save changes on every single file when I only view it and don't touch it. That's a deal breaker. I'll have to look for another viewer that doesn't do this.

    I switched to Markpad. 😕

  18. zac15987 commented on Mar 10, 2026

    @zac15987

    every time open a file, it prompts me to save it when I close it, which is very annoying.

    I work with a lot of markdown files. This is a great viewer. But, I can't have it prompt me to save changes on every single file when I only view it and don't touch it. That's a deal breaker. I'll have to look for another viewer that doesn't do this.

    I've fixed the "Save?" dialog issue in my fork. Files opened for viewing will no longer be falsely marked as modified, so you won't see the prompt when closing without making any edits.

    The root cause was that Muya's markdown round-trip (parse → export) produced output differing from the original file, triggering a false "modified" state. The fix adds an isJustLoaded flag that suppresses this first false-positive detection after loading a file from disk.

    Release: v0.17.2

  19. unpinned this issue on May 11, 2026
  20. chaosink commented on May 30, 2026

    @chaosink

    every time open a file, it prompts me to save it when I close it, which is very annoying.

    I work with a lot of markdown files. This is a great viewer. But, I can't have it prompt me to save changes on every single file when I only view it and don't touch it. That's a deal breaker. I'll have to look for another viewer that doesn't do this.

    I've fixed the "Save?" dialog issue in my fork. Files opened for viewing will no longer be falsely marked as modified, so you won't see the prompt when closing without making any edits.

    The root cause was that Muya's markdown round-trip (parse → export) produced output differing from the original file, triggering a false "modified" state. The fix adds an isJustLoaded flag that suppresses this first false-positive detection after loading a file from disk.

    Release: v0.17.2

    @zac15987 Thanks for the fix! Why not submit a pull request?

  21. zac15987 commented on Jun 1, 2026

    @zac15987

    @zac15987 Thanks for the fix! Why not submit a pull request?

    Thanks. I'll submit a PR soon!

  22. N0rbert commented on Jun 27, 2026

    @N0rbert

    With the 0.20.0~beta.4 the saved real-world document gets many warnings from the linters:

    Also code listing loses attributes - see #4770 .

  23. awebeer256 commented on Jun 28, 2026

    @awebeer256

    I've got two specific pet peeves that fall under this discussion.

    1. MarkText inserts blank lines between HTML-style comments on consecutive lines. In other words, if I want the raw text to look like this:
    <!-- foo -->
    <!-- bar -->
    

    Then MarkText changes it to this:

    <!-- foo -->
    
    <!-- bar -->
    
    1. MarkText adds four leading spaces for each level of nested list, when I would prefer two. If I want this:
    - foo
      - bar
    - baz
    

    Then MarkText changes it to this:

    - foo
        - bar
    - baz
    

    Ninja edit: this is not with the new beta.

  24. Beluk commented on Sep 25, 2026

    @Beluk

    I really love MarkText. It has a great design and is small and quick, but the silent reformatting on open/save is a real blocker for me when working with Git. Just opening a file and making a one-line change produces diffs across the whole document (blank lines after headings, lists, code blocks, etc.). That makes reviews noisy and causes unnecessary conflicts with collaborators who use other editors.
    I'm really looking forward to an option that keeps the original formatting. Thanks for all the work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐸 markdown/spec🐳 help wantedtodo 🗒️🔭 area/muya🦋 optimization

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions