Skip to content

Commit

Permalink
Presentation XML caption refactor: metanorma/isodoc#617
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Nov 21, 2024
1 parent 2d2b7da commit 8930d0b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presxml-autonum"
gem "isodoc-i18n", git: "https://github.com/metanorma/isodoc-i18n", branch: "fix/markup-connectives"
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "feature/presxml-autonum"

8 changes: 5 additions & 3 deletions lib/isodoc/ietf/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ def formula_where(dlist, out)
def formula_parse1(node, out)
out.t **attr_code(anchor: node["id"]) do |p|
parse(node.at(ns("./stem")), p)
lbl = @xrefs.anchor(node["id"], :label, false)
lbl.nil? or
p << " (#{lbl})"
if lbl = @xrefs.anchor(node["id"], :label, false)
lbl.gsub!(%r{</?span[^>]*>}, "")
/^\(.+?\)$/.match?(lbl) or lbl = "(#{lbl})"
p << " #{lbl}"
end
end
end

Expand Down
14 changes: 10 additions & 4 deletions lib/isodoc/ietf/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def eref_parse(node, out)
section: eref_section(node),
relative: eref_relative(node),
sectionFormat: node["displayFormat"]) do |l|
linkend.each { |n| parse(n, l) }
linkend.map(&:text).join.strip.empty? or
linkend.each { |n| parse(n, l) }
end
end

Expand All @@ -148,10 +149,11 @@ def eref_relative(node)
end

def eref_section(node)
@isodoc.eref_localities(
ret = @isodoc.eref_localities(
node.xpath(ns("./locality | ./localityStack")), nil, node
)&.sub(/^,/, "")&.sub(/^\s*(Sections?|Clauses?)/, "")&.strip
&.sub(/,$/, "") || ""
) or return ""
ret.gsub(%r{</?span[^>]*>}, "").sub(/^,/, "")
.sub(/^\s*(Sections?|Clauses?)/, "").strip.sub(/,$/, "")
end

def origin_parse(node, out)
Expand All @@ -171,6 +173,10 @@ def index_parse(node, out)
def bookmark_parse(node, out)
out.bookmark nil, **attr_code(anchor: node["id"])
end

def span_parse(node, out)
children_parse(node, out)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/isodoc/ietf/reqt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def recommendation_parse(node, out)
end

def recommendation_parse1(node, out)
recommendation_name(node.at(ns("./name")), out)
recommendation_name(node.at(ns("./fmt-name")), out)
node.children.each do |n|
parse(n, out) unless n.name == "name"
parse(n, out) unless n.name == "fmt-name"
end
end

Expand Down
7 changes: 3 additions & 4 deletions lib/isodoc/ietf/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ def termnote_anchor_names(docxml)
docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
c = IsoDoc::XrefGen::Counter.new
notes = t.xpath(ns("./termnote"))
notes.each do |n|
next if n["id"].nil? || n["id"].empty?

notes.noblank.each do |n|
idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
@anchors[n["id"]] =
anchor_struct(idx, n, @labels["note_xref"], "note", false)
anchor_struct(idx, n, @labels["note_xref"], "note",
{ container: true })
end
end
end
Expand Down
21 changes: 10 additions & 11 deletions spec/isodoc/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,9 @@
</dd>
</dl>
<aside anchor='_83083c7a-6c85-43db-a9fa-4d8edd0c9fc0'>
<t>
NOTE: [durationUnits] is essentially a duration statement without the
<t>NOTE: [durationUnits] is essentially a duration statement without the
"P" prefix. "P" is unnecessary because between "G" and "U" duration is
always expressed.
</t>
always expressed.</t>
</aside>
<t anchor='_be9158af-7e93-4ee2-90c5-26d31c181935'>$$ r = 1 % $$ (1)</t>
</abstract></front><middle/><back/></rfc>
Expand Down Expand Up @@ -797,18 +795,19 @@
<em>Inherits: /ss/584/2015/level/1</em>
</t>
<t anchor='_'>
I recommend#{' '}
I recommend
<em>this</em>
.
</t>
<t anchor='_'>As for the measurement targets,</t>
<t anchor='_'>The measurement target shall be measured as:</t>
<t anchor='B'>$$ r/1 = 0 $$ (1)</t>
<t anchor='_'>The following code will be run for verification:</t>
<sourcecode anchor='_'>
CoreRoot(success): HttpResponse if (success) recommendation(label:
success-response) end#{' '}
</sourcecode>
<t anchor="B">$$ r/1 = 0 $$ (1)</t>
<t anchor="_">The following code will be run for verification:</t>
<sourcecode anchor="_">CoreRoot(success): HttpResponse
if (success)
recommendation(label: success-response)
end
</sourcecode>
</abstract>
</front>
<middle/>
Expand Down
34 changes: 18 additions & 16 deletions spec/isodoc/lists_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,26 @@
INPUT
output = <<~OUTPUT
#{XML_HDR}
<ol anchor='_ae34a226-aab4-496d-987b-1aa7b6314026' spacing='compact' type='a' group='X' start='7' indent="5">
<li>
<t anchor='_0091a277-fb0e-424a-aea8-f0001303fe78'>all information necessary for the complete identification of the sample;</t>
<ol anchor='_' spacing='compact' type='a' group='X' start='7' indent="5">
<li id="_">
<t anchor='_'>all information necessary for the complete identification of the sample;</t>
</li>
<ol>
<li>
<t anchor='_8a7b6299-db05-4ff8-9de7-ff019b9017b2'>a reference to this document (i.e. ISO 17301-1);</t>
<t anchor='_'>a reference to this document (i.e. ISO 17301-1);</t>
</li>
<ol>
<li>
<t anchor='_ea248b7f-839f-460f-a173-a58a830b2abe'>the sampling method used;</t>
<t anchor='_'>the sampling method used;</t>
</li>
</ol>
</ol>
</ol>
</abstract></front><middle/><back/></rfc>
OUTPUT
expect(Xml::C14n.format(IsoDoc::Ietf::RfcConvert.new({})
.convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output)
expect(strip_guid(Xml::C14n.format(IsoDoc::Ietf::RfcConvert.new({})
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(output)
end

it "processes Roman Upper ordered lists" do
Expand All @@ -97,21 +98,22 @@
INPUT
output = <<~OUTPUT
#{XML_HDR}
<ol anchor='_ae34a226-aab4-496d-987b-1aa7b6314026' type='I'>
<li id='_ae34a226-aab4-496d-987b-1aa7b6314027'>
<t anchor='_0091a277-fb0e-424a-aea8-f0001303fe78'>all information necessary for the complete identification of the sample;</t>
<ol anchor='_' type='I'>
<li id='_'>
<t anchor='_'>all information necessary for the complete identification of the sample;</t>
</li>
<li>
<t anchor='_8a7b6299-db05-4ff8-9de7-ff019b9017b2'>a reference to this document (i.e. ISO 17301-1);</t>
<li id="_">
<t anchor='_'>a reference to this document (i.e. ISO 17301-1);</t>
</li>
<li>
<t anchor='_ea248b7f-839f-460f-a173-a58a830b2abe'>the sampling method used;</t>
<li id="_">
<t anchor='_'>the sampling method used;</t>
</li>
</ol>
</abstract></front><middle/><back/></rfc>
OUTPUT
expect(Xml::C14n.format(IsoDoc::Ietf::RfcConvert.new({})
.convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output)
expect(strip_guid(Xml::C14n.format(IsoDoc::Ietf::RfcConvert.new({})
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(output)
end

it "processes definition lists" do
Expand Down

0 comments on commit 8930d0b

Please sign in to comment.