feat(docx-core): emit rPrChange for formatted paragraph replacements#215
Open
stevenobiajulu wants to merge 2 commits into
Open
feat(docx-core): emit rPrChange for formatted paragraph replacements#215stevenobiajulu wants to merge 2 commits into
stevenobiajulu wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ange Peer review of #215 surfaced two reproducible false positives in `rPrComparableSignature` that caused `replaceParagraphTextRange` to emit `w:rPrChange` for no-op formatting requests: 1. **Whitespace-sensitive comparison.** The signature concatenated text node `textContent`, so a pretty-printed source `<w:rPr>` with inter-element whitespace did not match the whitespace-free `<w:rPr>` produced by `cloneRPrWithoutChangeRecords` (which drops non-element children). Re-asserting an existing toggle therefore emitted a bogus `w:rPrChange`. The OOXML schema only permits element children inside `w:rPr`, so any text node there is insignificant pretty-printing — the signature now skips text nodes entirely. 2. **ST_OnOff variants compared as strings.** OOXML treats the absence of `w:val` on a toggle property as equivalent to `w:val="1"`, and the values `1`/`true`/`on` (and their falsy triple) are interchangeable. But `ensureBoolProp` always writes the explicit `w:val="1"` form, so re-asserting bold against a `<w:b/>` source produced a signature mismatch and a bogus `w:rPrChange`. The signature now canonicalizes toggle elements: it synthesizes a `w:val="1"` for absent attributes and normalizes `1|true|on`/`0|false|off` for the toggle set defined by ECMA-376 (`b`, `bCs`, `i`, `iCs`, `caps`, `smallCaps`, `strike`, `dstrike`, `outline`, `shadow`, `emboss`, `imprint`, `vanish`, `specVanish`, `webHidden`, `noProof`, `snapToGrid`, `rtl`, `cs`). New regression tests in `text.test.ts` lock both fixes plus two previously-uncovered shapes: `clearHighlight: true` must trigger `w:rPrChange` when the source carried a highlight, and a heterogeneous multi-run deletion pins the documented snapshot contract (the chosen template run's `rPr` becomes the prior state; per-run formatting of the removed span is preserved inside `<w:del>`). Ref: #173 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #173.
replaceParagraphTextRangenow emitsw:rPrChangewhen an explicit replacement formatting request changes the replacement run's effectivew:rPrrelative to the source/template run. Pure text replacements and explicit formatting requests that leave run properties unchanged preserve the existing insertion/deletion behavior without adding a property-change record.Implementation
buildRPrChangeElementfor the OOXML property-change wrapper.w:rPrChange.w:rPrChangerecords when cloning/snapshotting run properties.w:rPrChangeemission gated on explicitaddRunProps/clearHighlightdeltas.w:rPrChange.SUPPORT.mdso the text primitive no longer listsw:rPrChangeas pending.Verification
npm -w @usejunior/docx-core run test:run -- src/primitives/text.test.ts src/integration/canonical-emission-regression.test.ts— 60 passednpm -w @usejunior/docx-core run buildnpm -w @usejunior/docx-core run lintnpm run lint:allure-imports— passed with one pre-existing warning inpackages/docx-mcp/src/cli/commands/edit.test.ts:133npm run lint:workspaces— fails in unrelated@usejunior/safedocx-mcpb:src/index.tsimports missingrunServerfrom@usejunior/safe-docxand has an implicitanyparameter