Commit 2407e93
authored
fix(super-editor): stop default-rPr injection + normalize pgMar twips on round-trip (SD-2912) (#3237)
* fix(super-editor): stop injecting bCs/iCs/highlight defaults on round-trip (SD-2912)
The customer fixture round-tripped to a document.xml ~37KB larger than the
source, with 822 occurrences each of `<w:bCs/>`, `<w:iCs/>` and
`<w:highlight w:val="none"/>` injected into runs whose source rPr contained
none of them. Word treats explicit-off and absence as identical so the
rendering was unchanged, but every consumer reading the XML saw thousands
of "intentional" toggles that weren't real.
Two changes:
- `decodeRPrFromMarks` no longer auto-propagates `boldCs`/`italicCs` from
the latin bold/italic mark. In OOXML these are independent properties
(ECMA-376 §17.3.2). The propagation was emitting a complex-script
companion element on every run that touched a bold or italic mark, even
when the source rPr had no `<w:bCs/>` or `<w:iCs/>`.
- The highlight case in the same function no longer emits an explicit
`<w:highlight w:val="none"/>` for the transparent mark. That mark is
synthesized from `<w:shd val="clear" fill="auto"/>` shading on import
and the shading itself round-trips independently via its own element.
To keep round-trip lossless for documents that genuinely carry `<w:bCs/>`
or `<w:iCs/>` (which were previously preserved as a side effect of the
auto-propagation), `boldCs` and `italicCs` are removed from
`RUN_PROPERTIES_DERIVED_FROM_MARKS` in calculateInlineRunPropertiesPlugin.
That moves them to the "preserve from existing runProperties" branch in
`getInlineRunProperties`, so the values captured at import time survive
appendTransactions verbatim.
Verified on the SD-2912 fixture:
- bCs: input=0 → before=822 → after=0
- iCs: input=0 → before=822 → after=0
- highlight: input=0 → before=822 → after=0
- document.xml: 1.13 MB → 1.08 MB (smaller than the 1.09 MB input)
- All 12714 super-editor tests pass.
* fix(super-editor): normalize pgMar attrs to integer twips on export (SD-2912)
Customer ask: ECMA-376 §17.6.11 requires `ST_TwipsMeasure` values on
<w:pgMar> to be non-negative whole numbers when expressed as raw twips.
Athena Intelligence's source DOCX carries float-valued twips like
`w:top="168.160400390625"` from an upstream pipeline. SuperDoc was
preserving those floats verbatim on the paragraph-level sectPr passthrough
(56 of 57 pgMar elements on the customer fixture). Strict consumers reject
the result as schema-invalid.
The body sectPr already produced integer twips (via the
`pageMargins` → `inchesToTwips` write path); paragraph-level sectPrs went
through the `savedTagsToRestore` passthrough that preserved source attrs
verbatim, so floats survived.
Fix is a single export-time normalization pass: `normalizePgMarTwipsInTree`
walks the final XML JSON tree and rounds every numeric pgMar attribute to
an integer via `Math.round`. Applied once at the export entry point in
`translateDocumentNode`. Idempotent.
Why a single pass instead of fixing each import or write site:
- catches every path (current and future) that produces pgMar elements
- one helper, one call site, easy to revert
- doesn't touch import — `pageStyles.pageMargins` still in inches as before
Verified on customer fixture:
pgMar element count: 57 → 57 (preserved)
decimal-valued pgMar attrs: 2549 → 0
customer-cited example: `w:top="168.160400390625"` → `w:top="168"`
Tests:
- 9 helper unit tests covering AAA scenarios (undefined/null input,
no-pgMar tree, single pgMar, nested sectPrs, idempotency, integer-only
no-op, non-numeric ignored, no cross-element bleed)
- 3 extended integration tests: every exported pgMar attr is integer,
raw XML has zero decimal-valued pgMar attrs, source fixture confirmed
to carry decimals (otherwise the assertion would be vacuous)
Full super-editor suite: 12 726 passed (+12), 13 skipped, 0 failed.
* fix(super-editor): preserve highlight clears and cs formatting
* fix(super-editor): cover review export regressions1 parent ec5db77 commit 2407e93
17 files changed
Lines changed: 582 additions & 40 deletions
File tree
- packages/super-editor/src/editors/v1
- core
- helpers
- super-converter
- v3/handlers/w/r
- extensions
- highlight
- run
- track-changes/trackChangesHelpers
- types
- tests
- data
- import-export
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
| 454 | + | |
| 455 | + | |
455 | 456 | | |
456 | 457 | | |
457 | 458 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
109 | 147 | | |
110 | 148 | | |
111 | 149 | | |
| |||
402 | 440 | | |
403 | 441 | | |
404 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
405 | 449 | | |
406 | 450 | | |
407 | 451 | | |
| |||
568 | 612 | | |
569 | 613 | | |
570 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
571 | 618 | | |
572 | 619 | | |
573 | 620 | | |
| |||
Lines changed: 156 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
Lines changed: 23 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
147 | | - | |
| 151 | + | |
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
151 | | - | |
| 155 | + | |
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | | - | |
179 | | - | |
| 182 | + | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| |||
535 | 539 | | |
536 | 540 | | |
537 | 541 | | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
| |||
566 | 573 | | |
567 | 574 | | |
568 | 575 | | |
569 | | - | |
570 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
571 | 579 | | |
572 | | - | |
573 | | - | |
574 | 580 | | |
| 581 | + | |
| 582 | + | |
575 | 583 | | |
576 | 584 | | |
577 | 585 | | |
| |||
0 commit comments