diff --git a/lib/sts/niso_sts/preformat.rb b/lib/sts/niso_sts/preformat.rb index 0762b9e..c44512d 100644 --- a/lib/sts/niso_sts/preformat.rb +++ b/lib/sts/niso_sts/preformat.rb @@ -16,6 +16,14 @@ class Preformat < Lutaml::Model::Serializable attribute :underline, ::Sts::NisoSts::Underline, collection: true attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true + attribute :xref, ::Sts::TbxIsoTml::Xref, collection: true + attribute :sub, ::Sts::NisoSts::Sub, collection: true + attribute :sup, ::Sts::NisoSts::Sup, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :monospace, ::Sts::NisoSts::Monospace, collection: true + attribute :ext_link, ::Sts::NisoSts::ExtLink, collection: true + attribute :inline_formula, ::Sts::NisoSts::InlineFormula, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "preformat" @@ -34,6 +42,14 @@ class Preformat < Lutaml::Model::Serializable map_element "underline", to: :underline map_element "styled-content", to: :styled_content map_element "std", to: :std + map_element "xref", to: :xref + map_element "sub", to: :sub + map_element "sup", to: :sup + map_element "sc", to: :sc + map_element "monospace", to: :monospace + map_element "ext-link", to: :ext_link + map_element "inline-formula", to: :inline_formula + map_element "break", to: :break end end end diff --git a/lib/sts/niso_sts/sup.rb b/lib/sts/niso_sts/sup.rb index a0e5a88..ca0d67c 100644 --- a/lib/sts/niso_sts/sup.rb +++ b/lib/sts/niso_sts/sup.rb @@ -12,6 +12,13 @@ class Sup < Lutaml::Model::Serializable attribute :monospace, ::Sts::NisoSts::Monospace, collection: true attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true attribute :xref, ::Sts::TbxIsoTml::Xref, collection: true + attribute :sub, ::Sts::NisoSts::Sub, collection: true + attribute :sup, ::Sts::NisoSts::Sup, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true + attribute :ext_link, ::Sts::NisoSts::ExtLink, collection: true + attribute :inline_formula, ::Sts::NisoSts::InlineFormula, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "sup" @@ -26,6 +33,13 @@ class Sup < Lutaml::Model::Serializable map_element "monospace", to: :monospace map_element "styled-content", to: :styled_content map_element "xref", to: :xref + map_element "sub", to: :sub + map_element "sup", to: :sup + map_element "sc", to: :sc + map_element "std", to: :std + map_element "ext-link", to: :ext_link + map_element "inline-formula", to: :inline_formula + map_element "break", to: :break end end end diff --git a/lib/sts/niso_sts/term.rb b/lib/sts/niso_sts/term.rb index f4c7a30..e43108d 100644 --- a/lib/sts/niso_sts/term.rb +++ b/lib/sts/niso_sts/term.rb @@ -20,6 +20,13 @@ class Term < Lutaml::Model::Serializable attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true attribute :ext_link, ::Sts::NisoSts::ExtLink attribute :entailed_term, ::Sts::TbxIsoTml::EntailedTerm + attribute :sub, ::Sts::NisoSts::Sub, collection: true + attribute :sup, ::Sts::NisoSts::Sup, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :monospace, ::Sts::NisoSts::Monospace, collection: true + attribute :underline, ::Sts::NisoSts::Underline, collection: true + attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true attribute :specific_use, :string, values: ["abbreviation", "acronym", "equation", "formula", "fullForm", "symbol", "variant"] attribute :term_status, :string, @@ -63,6 +70,13 @@ class Term < Lutaml::Model::Serializable map_element "uri", to: :uri map_element "std", to: :std map_element "xref", to: :xref + map_element "sub", to: :sub + map_element "sup", to: :sup + map_element "sc", to: :sc + map_element "monospace", to: :monospace + map_element "underline", to: :underline + map_element "styled-content", to: :styled_content + map_element "break", to: :break end end end diff --git a/lib/sts/niso_sts/title.rb b/lib/sts/niso_sts/title.rb index 382aa94..ed1c32a 100644 --- a/lib/sts/niso_sts/title.rb +++ b/lib/sts/niso_sts/title.rb @@ -18,6 +18,7 @@ class Title < Lutaml::Model::Serializable attribute :styled_content, Sts::NisoSts::StyledContent, collection: true attribute :monospace, Sts::NisoSts::Monospace, collection: true attribute :sc, Sts::NisoSts::Sc, collection: true + attribute :ext_link, Sts::NisoSts::ExtLink, collection: true xml do element "title" @@ -38,6 +39,7 @@ class Title < Lutaml::Model::Serializable map_element "styled-content", to: :styled_content map_element "monospace", to: :monospace map_element "sc", to: :sc + map_element "ext-link", to: :ext_link end end end diff --git a/lib/sts/tbx_iso_tml/bold.rb b/lib/sts/tbx_iso_tml/bold.rb index c54835d..06a90bf 100644 --- a/lib/sts/tbx_iso_tml/bold.rb +++ b/lib/sts/tbx_iso_tml/bold.rb @@ -18,6 +18,9 @@ class Bold < Lutaml::Model::Serializable attribute :fn, ::Sts::NisoSts::Fn, collection: true attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true attribute :bold, ::Sts::TbxIsoTml::Bold, collection: true + attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true + attribute :inline_formula, ::Sts::NisoSts::InlineFormula, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "bold" @@ -38,6 +41,9 @@ class Bold < Lutaml::Model::Serializable map_element "fn", to: :fn map_element "styled-content", to: :styled_content map_element "bold", to: :bold + map_element "std", to: :std + map_element "inline-formula", to: :inline_formula + map_element "break", to: :break end end end diff --git a/lib/sts/tbx_iso_tml/definition.rb b/lib/sts/tbx_iso_tml/definition.rb index 3e47108..92d214d 100644 --- a/lib/sts/tbx_iso_tml/definition.rb +++ b/lib/sts/tbx_iso_tml/definition.rb @@ -19,6 +19,8 @@ class Definition < Lutaml::Model::Serializable attribute :monospace, ::Sts::NisoSts::Monospace, collection: true attribute :ext_link, ::Sts::NisoSts::ExtLink, collection: true attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "definition" @@ -41,6 +43,8 @@ class Definition < Lutaml::Model::Serializable map_element "monospace", to: :monospace map_element "ext-link", to: :ext_link map_element "styled-content", to: :styled_content + map_element "sc", to: :sc + map_element "break", to: :break end end end diff --git a/lib/sts/tbx_iso_tml/example.rb b/lib/sts/tbx_iso_tml/example.rb index 224193a..cff4539 100644 --- a/lib/sts/tbx_iso_tml/example.rb +++ b/lib/sts/tbx_iso_tml/example.rb @@ -11,6 +11,13 @@ class Example < Lutaml::Model::Serializable attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true attribute :italic, ::Sts::TbxIsoTml::Italic, collection: true attribute :bold, ::Sts::TbxIsoTml::Bold, collection: true + attribute :sub, ::Sts::NisoSts::Sub, collection: true + attribute :sup, ::Sts::NisoSts::Sup, collection: true + attribute :monospace, ::Sts::NisoSts::Monospace, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :ext_link, ::Sts::NisoSts::ExtLink, collection: true + attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "example" @@ -27,6 +34,13 @@ class Example < Lutaml::Model::Serializable map_element "std", to: :std map_element "italic", to: :italic map_element "bold", to: :bold + map_element "sub", to: :sub + map_element "sup", to: :sup + map_element "monospace", to: :monospace + map_element "sc", to: :sc + map_element "ext-link", to: :ext_link + map_element "styled-content", to: :styled_content + map_element "break", to: :break end end end diff --git a/lib/sts/tbx_iso_tml/italic.rb b/lib/sts/tbx_iso_tml/italic.rb index 475d537..1827e3d 100644 --- a/lib/sts/tbx_iso_tml/italic.rb +++ b/lib/sts/tbx_iso_tml/italic.rb @@ -18,6 +18,9 @@ class Italic < Lutaml::Model::Serializable attribute :fn, ::Sts::NisoSts::Fn, collection: true attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true attribute :italic, ::Sts::TbxIsoTml::Italic, collection: true + attribute :std, ::Sts::NisoSts::ReferenceStandard, collection: true + attribute :inline_formula, ::Sts::NisoSts::InlineFormula, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "italic" @@ -38,6 +41,9 @@ class Italic < Lutaml::Model::Serializable map_element "fn", to: :fn map_element "styled-content", to: :styled_content map_element "italic", to: :italic + map_element "std", to: :std + map_element "inline-formula", to: :inline_formula + map_element "break", to: :break end end end diff --git a/lib/sts/tbx_iso_tml/note.rb b/lib/sts/tbx_iso_tml/note.rb index 1029b7a..e8630d9 100644 --- a/lib/sts/tbx_iso_tml/note.rb +++ b/lib/sts/tbx_iso_tml/note.rb @@ -16,6 +16,11 @@ class Note < Lutaml::Model::Serializable attribute :italic, ::Sts::TbxIsoTml::Italic, collection: true attribute :bold, ::Sts::TbxIsoTml::Bold, collection: true attribute :inline_formula, ::Sts::NisoSts::InlineFormula, collection: true + attribute :monospace, ::Sts::NisoSts::Monospace, collection: true + attribute :sc, ::Sts::NisoSts::Sc, collection: true + attribute :ext_link, ::Sts::NisoSts::ExtLink, collection: true + attribute :styled_content, ::Sts::NisoSts::StyledContent, collection: true + attribute :break, ::Sts::NisoSts::Break, collection: true xml do element "note" @@ -35,6 +40,11 @@ class Note < Lutaml::Model::Serializable map_element "xref", to: :xref map_element "math", to: :math map_element "inline-formula", to: :inline_formula + map_element "monospace", to: :monospace + map_element "sc", to: :sc + map_element "ext-link", to: :ext_link + map_element "styled-content", to: :styled_content + map_element "break", to: :break end end end diff --git a/spec/sts_missing_inline_elements_spec.rb b/spec/sts_missing_inline_elements_spec.rb new file mode 100644 index 0000000..ebda034 --- /dev/null +++ b/spec/sts_missing_inline_elements_spec.rb @@ -0,0 +1,189 @@ +# frozen_string_literal: true + +require "spec_helper" +require "canon/rspec_matchers" + +RSpec.describe Sts do + # metanorma-iso's STS InlineTransformer walks a source's mixed content and + # public_sends each inline element name onto the target model + # (metanorma/metanorma-pdfa#122: a inside a def-list
dispatched + # `monospace` onto Sts::NisoSts::Term, which did not declare it — + # NoMethodError, and the element was silently dropped on parse). + # + # These specs pin the dispatched inline set on every model the transformer + # targets, and round-trip the newly added elements. + describe Sts::NisoSts::Term do + it "round-trips a term containing monospace (metanorma-pdfa#122)" do + xml = "voltageV" + parsed = described_class.from_xml(xml) + + expect(parsed.monospace.map(&:content)).to eq([["V"]]) + expect(parsed.text).to eq(["voltage"]) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + + it "round-trips a term containing sub, sup, sc and break" do + xml = "103 Hz rangerfend" + parsed = described_class.from_xml(xml) + + expect(parsed.sup.map(&:content)).to eq([["3"]]) + expect(parsed.sc.map(&:content)).to eq([["rf"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + + it "round-trips nested inline content inside sup" do + xml = "106v" + parsed = described_class.from_xml(xml) + + expect(parsed.sup.first.sub.map(&:content)).to eq([["6"]]) + expect(parsed.sup.first.sc.map(&:content)).to eq([["v"]]) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + + it "round-trips underline and styled-content inside a term" do + xml = "u" \ + "s" + parsed = described_class.from_xml(xml) + + expect(parsed.underline.map(&:content)).to eq([["u"]]) + expect(parsed.styled_content.map(&:style_type)).to eq(["strong"]) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::NisoSts::Title do + it "round-trips a title containing ext-link" do + xml = "see <ext-link xlink:href=\"https://example.com\">" \ + "the reference</ext-link>" + parsed = described_class.from_xml(xml) + + expect(parsed.ext_link.map(&:href)).to eq(["https://example.com"]) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::NisoSts::Preformat do + it "round-trips a preformat containing inline elements" do + xml = "resistor table" \ + "inout" + parsed = described_class.from_xml(xml) + + expect(parsed.xref.map(&:rid)).to eq(["tab_1"]) + expect(parsed.sub.map(&:content)).to eq([["in"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::NisoSts::Sup do + it "round-trips nested inline content inside sup" do + xml = "106" \ + "l" + parsed = described_class.from_xml(xml) + + expect(parsed.sub.map(&:content)).to eq([["6"]]) + expect(parsed.ext_link.map(&:href)).to eq(["https://example.com"]) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::TbxIsoTml::Bold do + it "round-trips std and break inside bold" do + xml = "per ISO 1234" \ + "done" + parsed = described_class.from_xml(xml) + + expect(parsed.std.map do |std| + std.std_ref.map(&:value) + end).to eq([["ISO 1234"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::TbxIsoTml::Italic do + it "round-trips std and break inside italic" do + xml = "see IEV 113" \ + "below" + parsed = described_class.from_xml(xml) + + expect(parsed.std.map do |std| + std.std_ref.map(&:value) + end).to eq([["IEV 113"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::TbxIsoTml::Definition do + it "round-trips sc and break inside a definition" do + xml = "" \ + "ac currentnotes" + parsed = described_class.from_xml(xml) + + expect(parsed.sc.map(&:content)).to eq([["ac"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::TbxIsoTml::Note do + it "round-trips monospace and break inside a note" do + xml = "" \ + "use sethere" + parsed = described_class.from_xml(xml) + + expect(parsed.monospace.map(&:content)).to eq([["set"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe Sts::TbxIsoTml::Example do + it "round-trips sub, sup and break inside an example" do + xml = "" \ + "106 Hzrmsend" + parsed = described_class.from_xml(xml) + + expect(parsed.sup.map(&:content)).to eq([["6"]]) + expect(parsed.sub.map(&:content)).to eq([["rms"]]) + expect(parsed.break.first).to be_an(Sts::NisoSts::Break) + expect(parsed.to_xml).to be_xml_equivalent_to(xml) + end + end + + describe "dispatched inline accessor coverage" do + it "responds to every dispatched inline accessor on models receiving " \ + "inline content" do + dispatched = %i[ + bold italic sub sup monospace sc xref std ext_link break + inline_formula styled_content + ] + targets = { + Sts::NisoSts::Term => "def-list term", + Sts::NisoSts::Title => "section title", + Sts::NisoSts::Paragraph => "p", + Sts::NisoSts::Preformat => "preformat (sourcecode)", + Sts::NisoSts::Sup => "nested sup", + Sts::NisoSts::StyledContent => "styled-content", + Sts::TbxIsoTml::Bold => "bold", + Sts::TbxIsoTml::Italic => "italic", + Sts::TbxIsoTml::Definition => "tbx definition", + Sts::TbxIsoTml::Note => "tbx note", + Sts::TbxIsoTml::Example => "tbx example", + } + + aggregate_failures do + targets.each do |klass, context| + missing = dispatched.reject { |e| klass.new.respond_to?(e) } + next if missing.empty? + + message = "#{klass} missing #{missing.join(', ')} " \ + "(#{context} receives inline content)" + expect(missing).to(be_empty, message) + end + end + end + end +end