Skip to content

fix(styles): resolve localized default styles instead of minting a second Normal - #62

Open
kklimuk wants to merge 1 commit into
mainfrom
claude/triage-issue-59-localized-default-styles
Open

kklimuk wants to merge 1 commit into
mainfrom
claude/triage-issue-59-localized-default-styles

Conversation

@kklimuk

@kklimuk kklimuk commented Nov 12, 2026

Copy link
Copy Markdown
Owner

🤖 docx-cli triage

What was wrong

In a localized Word doc, the built-in defaults use translated ids (German: Standard / Absatz-Standardschriftart). When docx-cli provisioned a baseline style, it looked them up by their English ids. So docx edit de.docx --at p0 "See https://example.com" added a second w:default="1" paragraph style called Normal, plus a Hyperlink style with <w:basedOn w:val="DefaultParagraphFont"/>, which doesn't exist. validate still said valid.

What changed

  • StylesView.localStyleId maps Normal / DefaultParagraphFont to the doc's w:default="1" style of that type. Ids that already exist as-is are left alone.
  • Every provisioning path goes through #ensureStyleNode / ensureCustomStyle: Hyperlink, headings, Quote, list, note, caption and code-block styles, and styles create. These paths now:
    • never add Normal when a default paragraph style already exists
    • point basedOn/next at the local ids
    • drop a basedOn that names a default the doc doesn't define at all (before this, our own create docs also had a dangling DefaultParagraphFont)
  • styles set --at Normal (and --based-on/--next Normal) now resolve to the localized default. The self-reference check runs after that resolution.
  • defaultSizeHalfPoints/defaultFont fall back through the localized default as well.
  • style-defs fixture: the template's defaults are re-id'd to the German ones, and the fixture now inserts an autolink too, so Heading1/Hyperlink/Callout all exercise this path in the LibreOffice round-trip. src/core/CLAUDE.md notes the rule.

Verification

  • Before: the repro's styles are Standard(default), Absatz-Standardschriftart(default), Normal(default=1), Hyperlink ← DefaultParagraphFont
  • After: the styles are Standard(default), Absatz-Standardschriftart(default), Hyperlink ← Absatz-Standardschriftart. docx validate reports valid and read shows the link.
  • 4 new CLI tests in tests/cli/styles.test.ts, covering hyperlink, heading basedOn/next, styles set --at Normal, and the self-reference via the local id. The first three failed before the fix.
  • bun run check ✅ bun run test:unit ✅ (2103 tests)
  • /simplify: I did a single pass inline because the Agent tool wasn't available. No changes. /code-review xhigh: the forked skill reviewed the wrong range (HEAD~1 in another checkout), so I reviewed this diff by hand. That found the --at Normal --based-on Standard self-cycle, which is now fixed and tested.

Decisions for you

  • For a style the doc lacks, Hyperlink used to keep basedOn DefaultParagraphFont; it now drops that line. This also changes the output for docs made by our own create, whose template has no DefaultParagraphFont. OK, or would you rather we provision a DefaultParagraphFont default?
  • Follow-ups not done here:
    • Other baselines are still matched by English id, so a German doc's Überschrift1 (name heading 1) gets a parallel Heading1. Matching by w:name would mean every caller using the resolved id in pStyle.
    • read's CONSTRUCT_STYLES still lists only Normal, so a German paragraph that explicitly sets pStyle="Standard" may get a style= hint.
    • Optional validate warnings for more than one default per type, or a basedOn that points at a missing style.

Fixes #59

Action needed: approve/merge — review the Hyperlink basedOn decision above, then merge.


Generated by Claude Code

…cond Normal

A localized Word names its built-in defaults in its own language (German
`Standard` / `Absatz-Standardschriftart`). Provisioning a baseline style
(Hyperlink via an autolink, headings, notes, code blocks, `styles create`)
looked for the English ids, so it added a second `w:default="1"` paragraph
style `Normal` and based Hyperlink on a nonexistent `DefaultParagraphFont`.

`StylesView.localStyleId` now maps `Normal`/`DefaultParagraphFont` to the
document's `w:default="1"` style of that type; provisioning rewrites
basedOn/next to the local ids (dropping a basedOn on a default the doc lacks
entirely), and `styles set --at Normal` targets the localized default.

Fixes #59

Triage-Routine: true
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LkctEPkr8mq92sCK3ERfG3

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a hyperlink to a localized document adds a second default paragraph style

2 participants