feat: honor PAGE/NUMPAGES field format switches (SD-2990)#3262
Conversation
Parse `\*` general-format and `\#` numeric-picture switches when importing PAGE/NUMPAGES fields and thread the requested format (roman/alphabetic/zero-padded decimal/etc.) plus the section-aware numeric page value through the converter, pm-adapter, layout engine, and DOM painter so page-number fields render in the format Word stored rather than always decimal. The original instruction is preserved on the node so export round-trips back to the same field code.
|
The output structure (begin/instrText/separate/result/end runs with Status: PASS The two translators (
No non-existent attributes, no missing required attributes, no incorrect defaults observed in the four changed files. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6157e5d222
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Parses
\*general-format and\#numeric-picture switches when importingPAGE/NUMPAGES fields and threads the requested format (Roman, alphabetic,
zero-padded decimal, dashed) plus the section-aware numeric page value
through the converter → pm-adapter → layout engine → DOM painter so page
number fields render in the format Word stored — not always decimal.
The original instruction text is preserved on the node so export round-trips
back to the same field code Word wrote.
Changes
Converter (super-editor)
field-references/shared/page-number-field-switches.jsparses\* Arabic|roman|ROMAN|alphabetic|ALPHABETIC|ArabicDashand\# 0000-stylepicture switches into
{ pageNumberFormat, pageNumberZeroPadding, instruction }.page-preprocessor.jsandnum-pages-preprocessor.jsnow accept an optionsobject (
{ docx, instructionTokens, fieldRunRPr }) and emit those attrs onsd:autoPageNumber/sd:totalPageNumber. All sibling preprocessors updatedto the new options-object signature for consistency.
autoPageNumber-translator/totalPageNumber-translatorround-trip theattrs back to the original
PAGE/NUMPAGESinstruction on export and applythe format to the cached
NUMPAGESexport value.PageNumber/TotalPageCountextensions gaininstruction,pageNumberFormat,pageNumberZeroPaddingattributes (allrendered: false).HeaderFooterPerRidLayoutresolver now also returnsdisplayNumber(thesection-aware numeric value) so non-decimal formats can be applied per page.
Contracts
page-number-formatting.tscentralizesformatPageNumber/formatPageNumberFieldValueand thePageNumberFieldFormat/PageNumberFormattypes.pageNumbering.tsin layout-engine now re-exportsfrom contracts to keep the public surface stable.
TextRungainspageNumberFieldFormat?: PageNumberFieldFormat.pm-adapter
getPageNumberFieldFormat()helper reads the node attrs and attachespageNumberFieldFormatto token runs in bothgeneric-token.tsandtext-run.ts.Layout bridge / engine
resolveHeaderFooterTokensandresolvePageNumberTokensapply the fieldformat when present, falling back to the previous display text.
layoutHeaderFooteropts out of digit-bucketing for variants whose PAGEtokens use formats that don't share a digit-width budget (Roman, letters,
zero-padded decimal).
decimalandnumberInDashstill bucket.displayNumberis plumbed throughHeaderFooterLayout→FragmentRenderContext→ DOM painter so the painter formats per-page.DOM painter
resolveRunTextusespageNumberFieldFormat+displayPageNumbertoformat PAGE / NUMPAGES tokens at render time when a format is set.