fix: use use_prefix: true (not prefix: 'm') for Word-compatible serialization - #9
Merged
Conversation
The prefix: 'm' option forces a SINGLE prefix for every element in the output, which causes prefix rebinding when child elements belong to a different namespace (e.g. <m:br xmlns:m='...wordprocessing...'/> inside an m:CT_R). The rebinding is valid XML but unconventional, and the API itself is wrong: it tells the serializer to use 'm' for everything, contradicting the per-namespace prefix_default declarations. The correct API for 'use each namespace prefix_default' is use_prefix: true. With it, math elements get m: and wordprocessing elements get w: naturally — the form Word requires. Update all four call sites in the specs: - spec/omml_spec.rb:90-91, 104 (parse + serialize tests) - spec/omml_fixture_round_trip_spec.rb:169 (round-trip corpus) - spec/omml/wordprocessing_in_math_spec.rb (programmatic construction) The programmatic-construction spec now asserts: - br element has unprefixed_name 'br' - br namespace URI is wordprocessing - br namespace prefix is 'w' (not a rebound 'm') This is the form Word requires; default xmlns declarations are Word-incompatible for math content.
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
Follow-up to PR #8 to fix incorrect serialization API usage in the specs.
The previous PR documented a "known limitation" that
CTR.new(br: CTBr.new).to_xml(prefix: "m")produces prefix-rebinding (<m:br xmlns:m="...wordprocessing..."/>). That framing was wrong — the limitation only manifests with incorrect API usage.prefix: "m"forces a single prefix on every element, which contradicts the per-namespaceprefix_defaultdeclarations and causes the rebinding.The correct API is
use_prefix: true, which tells the serializer to honor each namespace'sprefix_default. This is the form Word requires — Word rejects math elements in default xmlns form.What changed
spec/omml_spec.rb(3 call sites):prefix: "m"→use_prefix: truespec/omml_fixture_round_trip_spec.rb(1 call site): same changespec/omml/wordprocessing_in_math_spec.rb: replaced the false "known limitation" framing with a proper assertion that programmaticCTR.new(br: CTBr.new).to_xml(use_prefix: true)produces:brelement withunprefixed_name == "br"w:prefix (not a reboundm:)Why this matters
Word requires every math element to carry the
m:prefix (per OOXML schema'selementFormDefault="qualified", which Word enforces strictly). Default xmlns declarations are rejected.use_prefix: trueis the API that produces Word-compatible output.prefix: "m"was always wrong; the "known limitation" was actually "wrong API usage".Test plan
bundle exec rspec— 333 examples, 0 failuresbundle exec rubocop— cleanCTR.new(br: CTBr.new(type: "page")).to_xml(use_prefix: true)produces<m:CT_R xmlns:m="...math"><w:br xmlns:w="...wordprocessing" w:type="page"/></m:CT_R>— correct prefix per element