Repository navigation
Description
Description
Description
MarkText automatically normalizes Markdown structure on file open or view toggle (e.g., injecting mandatory blank lines after headers, lists, and code blocks).
The first-hand effect is that an opened document is silently reformatted and modified in memory without the user's knowledge, consent, or ability to opt out. This forceful AST transformation alters the user's source text immediately upon load, creating severe downstream friction for collaboration and document stability. The secondary effects cascade across a range of reported Issues and Pull Requests that don't get accepted because they unknowningly band-aid symptoms rather than address the root problem.
Downstream Symptoms & Linked Reports
- False Unsaved State: Files display as modified immediately on open without any intentional user edits.
- Viewport / Cursor Shifting: AST recalculation during initial render shifts line offsets, forcing cursor jumps (especially on large files or during LLM text pastes).
- Git Diff Pollution: Minor edits cause repository-wide newline diffs across headers, code blocks, and lists.
Key Related Issues
| Issue | Status | Title / Area | Direct Impact & Connection |
|---|---|---|---|
| #3772 | Open | Blank lines auto inserted no matter what | Core issue detailing mandatory blank line insertion after headers/lists/code blocks causing Git diff pollution and external rendering breaks (e.g., Discord). |
| #2189 | Open | Document is modified when opened / Markdown formatting | Maintainer-authored root-cause tracking issue: MarkText stores documents as an internal block structure (not raw text), so the file is rebuilt/reformatted on every save — directly explains the false-unsaved-state and silent-reformatting behavior your tracking issue describes. |
| #2286 | Closed | Do not insert blank lines between list items | Auto-expanding compact/tight lists into loose lists with blank lines inserted between items when a code block or paragraph is added, regardless of the "Preferred loose list item" setting. |
| #2148 | Closed | Don't modify file when I don't modify it | Reports the editor silently re-inserting/duplicating code fence markers and marking files as edited without user input — a partial match; no dedicated open issue for code-block blank-line padding specifically was found. |
| #2304 | Closed | Reload jumps to the end of the document | Editor jumps/scrolls to the bottom of the document after reload/re-render — matches the cursor-jump-on-render symptom. Note: this was closed just recently (June 23, 2026) — worth checking the resolution/PR before citing it as still-open evidence. |
Related Pull Requests
| PR | Title / Focus | Direct Impact & Connection |
|---|---|---|
| #4146 | Fix newline and blank line auto-insertion in AST editor pipeline | Addresses the underlying AST serialization logic that automatically injects blank lines into list blocks, headers, and code snippets. |
| #4075 | Resolve false unsaved prompt when closing unmodified files | Fixes background re-parsing and line-insertion side effects that incorrectly set the document state to dirty upon opening. |
Proposed Solutions
Immediate / Short-Term
Add explicit configuration toggles under Preferences -> Markdown to disable mandatory line insertions after headings (#), code blocks, and block elements (extending the existing "Prefer loose list items" setting).
Architectural / Long-Term
Transition to non-destructive AST parsing that preserves original source text formatting and whitespace until an explicit "Format Document" action is manually requested by the user.
Appendix A: What PR #4146 Actually Does
Like PR #4075, PR #4146 is a downstream band-aid that treats a symptom rather than fixing the root cause.
The PR's author explicitly notes the root cause in their description:
"The tab was incorrectly marked as unsaved because Muya's
setMarkdown()triggers a change event with re-serialized content that can differ from the on-disk content..."
To work around this, the PR implements two client-side hacks:
- Ignores the First Change Event: It sets a temporary flag (
ignoreNextContentChangeForSaveStatus) when opening a file so the editor ignores the initial mutation event sent by Muya's re-serializer. - Normalizes Trailing Newlines on Comparison: It trims trailing newlines before checking
isSavedstatus.
Downstream Impact
Because the in-memory document remains silently altered by Muya upon opening:
- The moment the user makes a single legitimate keystroke, the dirty state will trigger, and saving the file will still overwrite the disk document with MarkText's forced line insertions.
- It does not fix viewport/cursor jumping caused during the initial render phase.
Analysis and writeup assisted by Gemini
Steps to Reproduce
- Using a simple text-editor, create a long non-trivial (multiple pages) Markdown document by hand or ask a cross section of AI tools to provide you such. Not all will put "mandatory" newlines after all elements. Save their docs or paste them into a simple text-editor and close.
- open the document in MarkText, observe modified status
- use save-as to save a copy without overwriting the original
- compare before/after in a text-diff tool
Expected Behavior
MarkText opens the existing text-document with a "read-only" mind-set and does not make any changes to the document not explicitly triggered by user edits to the relevant sections.
Actual Behavior
- After opening the doc, the screen or cursor may make repeated jumps through the document interrupting the user who is trying to read or edit.
- The file will be marked as "modified / unsaved" even if the user has not made any changes
- If autosave is enabled, the silent modifications will be saved and if the files were tracked by version control, it should show them as modified, despite the user only opening the docs to READ them.
Screenshots / Logs
No response
Operating System
macOS
MarkText Version
0.17.1, 0.19.1
OS Version
Windows (probably all systems)
Reproducibility
- I can reliably reproduce this issue
Activity
[-][Bug][/-][+] [Tracking Issue] Silent AST auto-formatting on open causes false unsaved state, cursor jumping, and Git diff pollution[/+]SPetersonNICE commentedon Jul 30, 2026
grr, I ran 'check for update' this morning then revalidated the issue, but did not notice the application remained on the
0.17.1...After updating to
0.19.1I see some of the secondary effects have been mitigated, but running 'save as' on a file opened in MarkText and comparing it to the original, I see the underlying issues have not been fully resolved.Jocs commentedon Sep 22, 2026
Closing as a duplicate of #2189.
#2189 is the maintainer-authored tracking issue for exactly this — MarkText storing documents as a block structure, so opening a file re-serialises it, which is what produces the false unsaved state, the silent reformatting and the Git diff noise. It holds the root-cause explanation, the current design decision, the live TODO checklist (list style, ordered-list numbering, SetExt heading count, footnote positioning, table cell styling) and the explicit charter that any development is tracked there. This thread names #2189 as that tracking issue itself.
Keeping one tracker rather than two. Both PRs referenced here (#4146, #4075) are closed. Please add anything from the appendix here to #2189 — in particular the confirmation that the diffs still occur on 0.19.1.