Skip to content

Commit d771f91

Browse files
committed
update architecture docs
1 parent a927870 commit d771f91

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

ARCHITECTURE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ The system allows the AI to write in Markdown, which is then converted to Word-n
165165
1. **Input**: AI generates `newContent` with Markdown (e.g., `Hello **World**`).
166166
2. **Detection**: `agentic-tools` detects Markdown markers.
167167
3. **Path Selection**:
168-
* *Complex (Nested Lists/Direct Bold)?* -> **OOXML Pipeline** -> `markdown-processor` extracts hints -> **Reconstruction Mode** splits the text into pieces where format changes, applying explicit `w:val="1"` attributes.
169-
* *Simple?* -> **HTML Fallback** -> `markdown-utils` -> `Hello <strong>World</strong>` -> `paragraph.insertHtml()`.
170-
* **Migration Target**: Replace HTML fallback with pure OOXML generation
168+
* **Pure Formatting Mode (Surgical)**: For formatting-only changes (Bold, Italic, U, Strike), the engine modifies `w:rPr` in place and uses `w:rPrChange` for redlines. This is the **preferred high-fidelity path**.
169+
* **Reconstruction Mode**: For combined text and formatting edits, or complex list/table generation. It reconstructs paragraphs and applies explicit `w:val="1"` attributes.
170+
* **HTML Fallback (Deprecated)**: Used for simple text updates.
171+
* **Migration Target**: Fully eliminate HTML fallback and rely on Pure Formatting and Reconstruction modes for all edits.
171172

172173
## 6. Migration Plan to Pure OOXML
173174

OOXML_ARCHITECTURE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This document outlines the architecture of the **OOXML Reconciliation Engine**,
77
The system operates in two distinct modes depending on the complexity of the operation:
88

99
1. **Reconstruction Pipeline** (Standard): Parses original OOXML, diffs against new text, and rebuilds the paragraph from scratch. Used for standard text edits and list generation.
10-
2. **Surgical Hybrid Engine** (Complex): Direct DOM manipulation. Used for Tables (to preserve cell structure) and specific "Highlight" and "Format Removal" operations.
10+
2. **Surgical Hybrid Engine** (Complex): Direct DOM manipulation. Used for Tables (to preserve cell structure) and **Pure Formatting Changes** (Bold, Italic, etc.) to ensure clean redlines.
1111

1212
```mermaid
1313
graph TD
@@ -43,8 +43,9 @@ The OOXML engine currently handles the following operations without Word JS API
4343
3. **List Generation**: Complex nested lists with custom numbering styles
4444
4. **Table Generation**: Complete table creation and modification
4545
5. **Format Preservation**: Maintains existing document formatting during edits
46-
6. **Track Changes**: Generates proper `w:ins`/`w:del` elements for redlines
47-
7. **Comment Preservation**: Maintains comment positions during text edits
46+
6. **Pure Formatting Redlines**: Generates `w:rPrChange` elements for clean formatting-only changes (Bold, Italic, U, Strike)
47+
7. **Track Changes**: Generates proper `w:ins`/`w:del` elements for text edits
48+
8. **Comment Preservation**: Maintains comment positions during text edits
4849

4950
### 🚧 Hybrid Operations (Partial OOXML)
5051

@@ -160,12 +161,11 @@ To reconcile tables, the engine converts the hierarchical XML (`w:tr` -> `w:tc`)
160161
* The `applyHighlightToOoxml` function (in `ooxml-formatting-removal.js`) performs targeted XML modification to inject `w:highlight` tags into specific runs.
161162
* This bypasses the reconstruction pipeline for high-speed, structural-preserving formatting updates.
162163

163-
* **Format Removal Workaround**:
164-
* Word's `insertOoxml` ignores `<w:rPrChange>` (formatting track changes).
165-
* **Workaround**: To "Redline" a format removal (e.g., un-bolding), the engine treats it as a text replacement:
166-
* `<w:del><strong>Text</strong></w:del>`
167-
* `<w:ins>Text</w:ins>`
168-
* This forces Word to show the change visibly as a deletion of the bold text and insertion of plain text.
164+
* **Pure Formatting Changes**:
165+
* To ensure formatting changes (e.g., adding or removing Bold) appear as native "Formatting" edits in Word rather than "Delete + Insert" redlines, the engine uses **Surgical Property Modification**.
166+
* **Mechanism**: Directly modifies the `<w:rPr>` element and injects a `<w:rPrChange>` snapshot.
167+
* **High Fidelity**: This allows Word to display clean formatting signals in the Track Changes pane.
168+
* **Functions**: `applyFormatAdditionsAsSurgicalReplacement` and `applyFormatRemovalAsSurgicalReplacement`.
169169

170170
### Comment & Range Preservation
171171
* **Position Markers**: Elements like `w:commentRangeStart/End` are treated as zero-width position markers during ingestion.

0 commit comments

Comments
 (0)