diff --git a/spec/omml/wordprocessing_in_math_spec.rb b/spec/omml/wordprocessing_in_math_spec.rb index e3918bf..34a3916 100644 --- a/spec/omml/wordprocessing_in_math_spec.rb +++ b/spec/omml/wordprocessing_in_math_spec.rb @@ -36,7 +36,7 @@ def run_of(xml) it "round-trips through serialize and re-parse" do parsed = Omml.parse(wrap('')) - serialized = parsed.to_xml(prefix: "m") + serialized = parsed.to_xml(use_prefix: true) reparsed = Omml.parse(serialized) expect(reparsed.r.first.br).to be_a(Omml::Models::CTBr) @@ -94,7 +94,7 @@ def run_of(xml) it "round-trips a complex run with multiple wordprocessing children" do xml = wrap("xy") parsed = Omml.parse(xml) - serialized = parsed.to_xml(prefix: "m") + serialized = parsed.to_xml(use_prefix: true) reparsed = Omml.parse(serialized) r = reparsed.r.first @@ -105,16 +105,24 @@ def run_of(xml) end describe "programmatic construction" do - it "builds a CTR with CTBr and serializes to wordprocessing namespace" do + it "builds a CTR with CTBr and serializes br with w: prefix" do br = Omml::Models::CTBr.new(type: "page") r = Omml::Models::CTR.new(br: br) - # The TYPE namespace determines the element's namespace URI. - # CTBr is in wordprocessing, so the element URI must be wordprocessing - # regardless of the prefix the serializer chooses to emit. - xml = r.to_xml(prefix: "m") - expect(xml).to include("http://schemas.openxmlformats.org/wordprocessingml/2006/main") - expect(xml).to include("br") + # `use_prefix: true` makes the serializer honor each namespace's + # `prefix_default` (m for math, w for wordprocessing). Required for + # Word compatibility — Word rejects math elements in default xmlns + # form; it requires the `m:` prefix on every element. + xml = r.to_xml(use_prefix: true) + doc = Omml::Configuration.xml_adapter.parse(xml).root + + expect(doc.namespace.uri) + .to eq("http://schemas.openxmlformats.org/officeDocument/2006/math") + br_element = doc.children.find(&:element?) + expect(br_element.unprefixed_name).to eq("br") + expect(br_element.namespace.uri) + .to eq("http://schemas.openxmlformats.org/wordprocessingml/2006/main") + expect(br_element.namespace.prefix).to eq("w") end end end diff --git a/spec/omml_fixture_round_trip_spec.rb b/spec/omml_fixture_round_trip_spec.rb index a01b115..f174971 100644 --- a/spec/omml_fixture_round_trip_spec.rb +++ b/spec/omml_fixture_round_trip_spec.rb @@ -166,7 +166,7 @@ def expected_root_class(xml) def expect_fixture_to_round_trip(fixture_path) xml = File.read(fixture_path) parsed = Omml.parse(xml) - serialized = parsed.to_xml(prefix: "m") + serialized = parsed.to_xml(use_prefix: true) diff = xml_difference(xml, serialized) expect(parsed).to be_a(expected_root_class(xml)) diff --git a/spec/omml_spec.rb b/spec/omml_spec.rb index 01fd510..aebd441 100644 --- a/spec/omml_spec.rb +++ b/spec/omml_spec.rb @@ -87,8 +87,8 @@ def wordprocessing_run_properties(parsed) expect(parsed).to be_a(Omml::Models::OMath) expect(parsed.r.first.t.content).to eq("x") - expect(parsed.to_xml(prefix: "m")).to include("x") + expect(parsed.to_xml(use_prefix: true)).to include("x") end it "parses roots with leading declarations and comments" do @@ -101,7 +101,7 @@ def wordprocessing_run_properties(parsed) it "preserves wordprocessing on-off run properties under ctrlPr" do parsed = described_class.parse(o_math_para_with_wordprocessing_flags_xml) r_pr = wordprocessing_run_properties(parsed) - serialized = parsed.to_xml(prefix: "m") + serialized = parsed.to_xml(use_prefix: true) reparsed = described_class.parse(serialized) reparsed_r_pr = wordprocessing_run_properties(reparsed)