fix: resolve markdown roundtrip formatting issue in save functionality
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user