Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions spec/omml/wordprocessing_in_math_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run_of(xml)

it "round-trips through serialize and re-parse" do
parsed = Omml.parse(wrap('<w:br w:type="page"/>'))
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)
Expand Down Expand Up @@ -94,7 +94,7 @@ def run_of(xml)
it "round-trips a complex run with multiple wordprocessing children" do
xml = wrap("<w:cr/><w:t>x</w:t><w:tab/><m:t>y</m:t>")
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
Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/omml_fixture_round_trip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions spec/omml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<m:oMath")
expect(parsed.to_xml(prefix: "m")).to include("<m:t>x</m:t>")
expect(parsed.to_xml(use_prefix: true)).to include("<m:oMath")
expect(parsed.to_xml(use_prefix: true)).to include("<m:t>x</m:t>")
end

it "parses roots with leading declarations and comments" do
Expand All @@ -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)

Expand Down
Loading