Respect localized built-in DOCX styles#3807
Conversation
2354940 to
38a2027
Compare
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38a2027144
βΉοΈ About Codex in GitHub
Your team has set up Codex to 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 π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function isEquivalentBuiltInStyle(styleElement, canonicalStyleId) { | ||
| if (styleElement.attributes?.['w:styleId'] === canonicalStyleId) return true; | ||
| if (styleElement.attributes?.['w:type'] !== 'paragraph') return false; |
There was a problem hiding this comment.
Exclude custom styles from built-in alias matches
With this guard, any paragraph style can suppress a default built-in as soon as its normalized id or name matches an alias. In a DOCX that has a custom style marked w:customStyle="1" with an alias-like id/name such as Title or Kop1, but no canonical built-in Title/Heading1 definition, addDefaultStylesIfMissing now skips adding the fallback that previous imports provided; canonical w:pStyle references remain keyed by those canonical IDs and will not resolve to the custom style. Please exclude w:customStyle styles from alias matching, or otherwise require evidence that the style is actually a built-in localized equivalent.
Useful? React with πΒ / π.
Summary
Updates DOCX default-style injection so SuperDoc recognizes localized built-in style equivalents before adding the built-in defaults.
Why
addDefaultStylesIfMissingpreviously checked only for exact canonical style IDs such asTitleandHeading1. Some Word-authored DOCX files, especially localized documents, can contain built-in title/heading styles with localized or sanitized IDs/names, for example:Ttulo/TΓtuloTtulo1/TΓtulo 1Kop1Those styles should count as existing built-in title/heading styles. Without that recognition, SuperDoc appends its default
Title/Heading1definitions and consumers can see the default styling take precedence over the imported template's own heading/title styling.What changed
w:namevalues by stripping diacritics, spacing, and punctuation before matching.TΓtulo,TΓtulo 1) and existing localized heading examples such asKop1.Validation
Passed:
Result:
1 passed,41 tests passed.Note: running through
pnpm --filter @superdoc/super-editor test -- ...on Windows triggered the monorepopreparelifecycle with Unix shell syntax (if [ -z "$CI" ]), so the targeted test was run directly with the local Vitest binary after dependencies were installed.