open-agreements
Version:
Open-source legal template filling CLI and library
38 lines • 2.1 kB
TypeScript
/**
* minimal_save — restore untouched top-level body blocks from the original
* document.xml at save time.
*
* The in-memory session DOM is normalized at open (`mergeRuns` +
* `simplifyRedlines`) because text addressing, bookmarks, and comparison
* baselines all assume the normalized shape. Serializing that DOM wholesale
* persists the normalization for every paragraph, so a one-paragraph edit
* rewrites the whole document on disk (proofErr stripped, runs merged) and
* downstream diffs lie about the edit's blast radius.
*
* This module reconciles at save time instead: any body block (w:p, w:tbl,
* w:sectPr, ...) whose serialization equals the corresponding block of a
* freshly-normalized re-parse of the original XML was, by construction,
* untouched by edits — so it is replaced with the pristine original block.
* Edited blocks that are tables are descended into (rows → cells →
* paragraphs) so a one-cell edit doesn't churn the rest of the table.
* Edited or inserted leaves have no equal counterpart and are kept as-is.
* The output contract is element-for-element preservation of untouched
* blocks (the XML still passes through the serializer, so byte-identity
* with the original file is not guaranteed).
*
* @see https://github.com/UseJunior/safe-docx/issues/408
*/
/**
* Replace every block of `currentDoc` that is untouched — i.e.
* serialization-equal to the same block of the original document.xml after
* open-time normalization — with the pristine original block, descending
* into edited tables so their untouched rows/cells/paragraphs restore too.
*
* `currentDoc` must already have internal bookmarks removed (untouched
* blocks otherwise never match the bookmark-free reference). Returns the
* number of elements restored; 0 means the document is fully edited or the
* reference could not be aligned (output then matches today's full
* re-serialization, never anything worse).
*/
export declare function restoreUntouchedBlocks(currentDoc: Document, originalXmlText: string): number;
//# sourceMappingURL=minimal_save.d.ts.map