Skip to content

Commit

Permalink
ensure that anchors are preemptively inserted in ol/li in xrefs proce…
Browse files Browse the repository at this point in the history
…ssing, to guarantee labels are assigned: #617
  • Loading branch information
opoudjis committed Nov 15, 2024
1 parent 85add8a commit 4656410
Show file tree
Hide file tree
Showing 5 changed files with 1,149 additions and 790 deletions.
3 changes: 0 additions & 3 deletions lib/isodoc/presentation_function/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ def ol_depth(node)

def ol1(elem)
elem["type"] ||= ol_depth(elem).to_s
elem.xpath(ns("./li")).each do |li|
li["id"] ||= "_#{UUIDTools::UUID.random_create}"
end
elem.at(ns("./name")) and
prefix_name(elem, {}, "", "name") # copy name to fmt-name
end
Expand Down
10 changes: 5 additions & 5 deletions lib/isodoc/xref/xref_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def list_item_anchor_names(list, list_anchor, depth, prev_label,
list_item_value(li, c, depth,
{ list_anchor:, prev_label:,
refer_list: depth == 1 ? refer_list : nil })
li["id"] and @anchors[li["id"]] =
{ label: bare_label, bare_xref: "#{label})",
xref: %[#{label}#{list_item_delim}],
type: "listitem", refer_list:,
container: list_anchor[:container] }
li["id"] ||= "_#{UUIDTools::UUID.random_create}"
@anchors[li["id"]] =
{ label: bare_label, bare_xref: "#{label})", type: "listitem",
xref: %[#{label}#{list_item_delim}], refer_list:,
container: list_anchor[:container] }
(li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
list_item_anchor_names(ol, list_anchor, depth + 1, label,
refer_list)
Expand Down
120 changes: 68 additions & 52 deletions spec/isodoc/presentation_xml_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,46 @@
</source>
</metanorma>
</metanorma-extension>
<preface>
<clause type="toc" id="_" displayorder="1"> <title depth="1">Table of contents</title> </clause>
<foreword id="fwd" displayorder="2"><title>Foreword</title>
<p>
<math xmlns:sodipodi="ABC" id="b">
<sodipodi:b> xmlns:sodipodi</sodipodi:b>
</math>
<xref target="N1">Figure 1</xref>
</p>
</foreword>
<introduction id="intro" displayorder="3">
<figure id="N1">
<name>Figure 1 — Split-it-right sample divider</name>
<image src="rice_images/rice_image1.png" id="_" mimetype="image/png"/>
</figure>
</introduction>
</preface>
<preface>
<clause type="toc" id="_" displayorder="1">
<fmt-title depth="1">Table of contents</fmt-title>
</clause>
<foreword id="fwd" displayorder="2">
<title id="_">Foreword</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">Foreword</semx>
</span>
</fmt-title>
<p>
<math xmlns:sodipodi="ABC" id="b">
<sodipodi:b> xmlns:sodipodi</sodipodi:b>
</math>
<xref target="N1">
<span class="fmt-element-name">Figure</span>
<semx element="autonum" source="N1">1</semx>
</xref>
</p>
</foreword>
<introduction id="intro" displayorder="3">
<figure id="N1" autonum="1">
<name id="_">Split-it-right sample divider</name>
<fmt-name>
<span class="fmt-caption-label">
<span class="fmt-element-name">Figure</span>
<semx element="autonum" source="N1">1</semx>
<span class="fmt-caption-delim"> — </span>
<semx element="name" source="_">Split-it-right sample divider</semx>
</span>
</fmt-name>
<fmt-xref-label>
<span class="fmt-element-name">Figure</span>
<semx element="autonum" source="N1">1</semx>
</fmt-xref-label>
<image src="rice_images/rice_image1.png" id="_" mimetype="image/png"/>
</figure>
</introduction>
</preface>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert
Expand All @@ -81,22 +104,26 @@
</iso-standard>
INPUT
output = <<~OUTPUT
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<bibdata type="standard"/>
<metanorma-extension>
<clause id="_user_css" inline-header="false" obligation="normative">
<title depth="1">user-css</title>
<sourcecode id="_2d494494-0538-c337-37ca-6d083d748646">.green { background-color: green }</sourcecode>
</clause>
<source-highlighter-css>
.green { background-color: green }</source-highlighter-css>
</metanorma-extension>
</iso-standard>
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<bibdata type="standard"/>
<metanorma-extension>
<clause id="_" inline-header="false" obligation="normative">
<title id="_">user-css</title>
<fmt-title depth="1">
<span class="fmt-caption-label">
<semx element="title" source="_">user-css</semx>
</span>
</fmt-title>
<sourcecode id="_">.green { background-color: green }</sourcecode>
</clause>
<source-highlighter-css>
.green { background-color: green }</source-highlighter-css>
</metanorma-extension>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(IsoDoc::PresentationXMLConvert.new(presxml_options)
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options)
.convert("test", input, true))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.sub(%r{<localized-strings>.*</localized-strings>}m, "")))
.to be_equivalent_to Xml::C14n.format(output)
end

Expand All @@ -122,17 +149,17 @@
<title>List of recommendations</title>
</toc>
</metanorma-extension>
<preface> <clause type="toc" id="_" displayorder="1"> <title depth="1">Table of contents</title> </clause> </preface>
<sections> </sections>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert
xml = Nokogiri::XML(IsoDoc::PresentationXMLConvert
.new({ tocfigures: true,
toctables: true,
tocrecommendations: true }
.merge(presxml_options))
.convert("test", input, true)))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.convert("test", input, true))
xml.xpath("//xmlns:preface | //xmlns:localized-strings | //xmlns:sections")
.each(&:remove)
expect(Xml::C14n.format(strip_guid(xml.to_xml)))
.to be_equivalent_to Xml::C14n.format(presxml)
end

Expand Down Expand Up @@ -167,26 +194,15 @@
<value>font1</value>
</presentation-metadata>
</metanorma-extension>
<preface> <clause type="toc" id="_" displayorder="1"> <title depth="1">Table of contents</title> </clause> </preface>
<sections>
<clause id='A' inline-header='false' obligation='normative' displayorder='2'>
<title depth='1'>
1.
<tab/>
Section
</title>
<figure id='B1'>
<name>Figure 1&#xA0;&#x2014; First</name>
</figure>
</clause>
</sections>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert
xml = Nokogiri::XML(IsoDoc::PresentationXMLConvert
.new({ fonts: "font1; font2", fontlicenseagreement: "no-install-fonts" }
.merge(presxml_options))
.convert("test", input, true)))
.sub(%r{<localized-strings>.*</localized-strings>}m, ""))
.convert("test", input, true))
xml.xpath("//xmlns:preface | //xmlns:localized-strings | //xmlns:sections")
.each(&:remove)
expect(Xml::C14n.format(strip_guid(xml.to_xml)))
.to be_equivalent_to Xml::C14n.format(presxml)
end

Expand Down
Loading

0 comments on commit 4656410

Please sign in to comment.