From 74ee2760e2819d093755aab88569815367171794 Mon Sep 17 00:00:00 2001 From: tegwick Date: Sat, 25 Oct 2025 21:15:48 +0200 Subject: [PATCH] fix: resolve markdown roundtrip formatting issue in save functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed critical bug where saving unedited content would introduce unwanted indentation and formatting changes due to unnecessary DOM reconstruction. Problem: - getMarkdownContent() always reconstructed from DOM elements - textContent doesn't preserve original markdown formatting - HTML rendering adds/removes whitespace causing formatting drift - Lines after first would get extra indentation on roundtrip Solution: - Added hasEdits tracking to MarkitectEditor class - Return original markdown content when no edits have been made - Only reconstruct from DOM when actual edits occurred - Mark hasEdits=true when textarea blur event fires This ensures perfect fidelity when saving unedited documents while maintaining the reconstruction capability for edited content. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- markitect/document_manager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/markitect/document_manager.py b/markitect/document_manager.py index 34e52504..a7055964 100644 --- a/markitect/document_manager.py +++ b/markitect/document_manager.py @@ -657,6 +657,7 @@ class DocumentManager: editor_scripts = """ class MarkitectEditor { constructor() { + this.hasEdits = false; // Track if any edits have been made this.initializeEditor(); this.setupKeyboardShortcuts(); } @@ -707,6 +708,7 @@ class DocumentManager: textarea.className = 'edit-mode'; textarea.addEventListener('blur', () => { + this.hasEdits = true; // Mark that edits have been made section.innerHTML = marked.parse(textarea.value); this.markSections(section.parentElement); }); @@ -781,6 +783,11 @@ class DocumentManager: } getMarkdownContent() { + // If no edits have been made, return the original markdown content + if (!this.hasEdits) { + return markdownContent; + } + // Reconstruct markdown content from the current state of sections const content = document.getElementById('markdown-content'); if (!content) {