Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/presxml oct24 #1233

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/presxml-oct24"
1 change: 0 additions & 1 deletion lib/isodoc/iso/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def figure_parse1(node, out)
measurement_units(node, out)
out.div **figure_attrs(node) do |div|
node.children.each do |n|
figure_key(out) if n.name == "dl"
n.name == "note" && n["type"] == "units" and next
parse(n, div) unless n.name == "name"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/isodoc/iso/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def annex(isoxml)
end

def figure1(node)
figure_fn(node)
figure_key(node.at(ns("./dl")))
lbl = @xrefs.anchor(node["id"], :label, false) or return
figname = node.parent.name == "figure" ? "" : "#{@i18n.figure} "
conn = node.parent.name == "figure" ? "  " : " — "
Expand Down
159 changes: 159 additions & 0 deletions spec/isodoc/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,165 @@
expect(Xml::C14n.format(output)).to be_equivalent_to Xml::C14n.format(html)
end

it "processes figures" do
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<preface><foreword>
<figure id="figureA-1" keep-with-next="true" keep-lines-together="true">
<name>Split-it-right <em>sample</em> divider<fn reference="1"><p>X</p></fn></name>
<image src="rice_images/rice_image1.png" height="20" width="30" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" mimetype="image/png" alt="alttext" title="titletxt"/>
<image src="rice_images/rice_image1.png" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f1" mimetype="image/png"/>
<image src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f2" mimetype="image/png"/>
<image src="data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjw/eG1sLXN0eWxlc2hlZXQgdHlwZT0idGV4dC94c2wiIGhyZWY9Ii4uLy4uLy4uL3hzbC9yZXNfZG9jL2ltZ2ZpbGUueHNsIj8+CjwhRE9DVFlQRSBpbWdmaWxlLmNvbnRlbnQgU1lTVEVNICIuLi8uLi8uLi9kdGQvdGV4dC5lbnQiPgo8aW1nZmlsZS5jb250ZW50IG1vZHVsZT0iZnVuZGFtZW50YWxzX29mX3Byb2R1Y3RfZGVzY3JpcHRpb25fYW5kX3N1cHBvcnQiIGZpbGU9ImFjdGlvbl9zY2hlbWFleHBnMS54bWwiPgo8aW1nIHNyYz0iYWN0aW9uX3NjaGVtYWV4cGcxLmdpZiI+CjxpbWcuYXJlYSBzaGFwZT0icmVjdCIgY29vcmRzPSIyMTAsMTg2LDM0MywyMjciIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9iYXNpY19hdHRyaWJ1dGVfc2NoZW1hL2Jhc2ljX2F0dHJpYnV0ZV9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMTAsMTAsOTYsNTEiIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9hY3Rpb25fc2NoZW1hL2FjdGlvbl9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMjEwLDI2NCwzNTgsMzA1IiBocmVmPSIuLi8uLi9yZXNvdXJjZXMvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEueG1sIiAvPgo8L2ltZz4KPC9pbWdmaWxlLmNvbnRlbnQ+Cg==" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f2" mimetype="application/xml"/>
<fn reference="a">
<p id="_ef2c85b8-5a5a-4ecd-a1e6-92acefaaa852">The time <stem type="AsciiMath">t_90</stem> was estimated to be 18,2 min for this example.</p>
</fn>
<dl>
<dt>A</dt>
<dd><p>B</p></dd>
</dl>
<source status="generalisation">
<origin bibitemid="ISO712" type="inline" citeas="ISO 712">
<localityStack>
<locality type="section">
<referenceFrom>1</referenceFrom>
</locality>
</localityStack>
</origin>
<modification>
<p id="_">with adjustments</p>
</modification>
</source>
<source status="specialisation">
<origin bibitemid="ISO712" type="inline" citeas="ISO 712">
<localityStack>
<locality type="section">
<referenceFrom>2</referenceFrom>
</locality>
</localityStack>
</origin>
</source>
</figure>
<figure id="figure-B">
<pre alt="A B">A &#x3c;
B</pre>
</figure>
<figure id="figure-C" unnumbered="true">
<pre>A &#x3c;
B</pre>
</figure>
</foreword></preface>
<bibliography><references id="_normative_references" obligation="informative" normative="true"><title>Normative References</title>
<bibitem id="ISO712" type="standard">
<title format="text/plain">Cereals or cereal products</title>
<title type="main" format="text/plain">Cereals and cereal products</title>
<docidentifier type="ISO">ISO 712</docidentifier>
<contributor>
<role type="publisher"/>
<organization>
<name>International Organization for Standardization</name>
</organization>
</contributor>
</bibitem>
</bibliography>
</iso-standard>
INPUT
presxml = <<~OUTPUT
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface>
<clause type="toc" id="_" displayorder="1">
<title depth="1">Contents</title>
</clause>
<foreword displayorder="2">
<figure id="figureA-1" keep-with-next="true" keep-lines-together="true">
<name>
Figure 1 — Split-it-right
<em>sample</em>
divider
<fn reference="1">
<p>X</p>
</fn>
</name>
<image src="rice_images/rice_image1.png" height="20" width="30" id="_" mimetype="image/png" alt="alttext" title="titletxt"/>
<image src="rice_images/rice_image1.png" height="20" width="auto" id="_" mimetype="image/png"/>
<image src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto" id="_" mimetype="image/png"/>
<image src="data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjw/eG1sLXN0eWxlc2hlZXQgdHlwZT0idGV4dC94c2wiIGhyZWY9Ii4uLy4uLy4uL3hzbC9yZXNfZG9jL2ltZ2ZpbGUueHNsIj8+CjwhRE9DVFlQRSBpbWdmaWxlLmNvbnRlbnQgU1lTVEVNICIuLi8uLi8uLi9kdGQvdGV4dC5lbnQiPgo8aW1nZmlsZS5jb250ZW50IG1vZHVsZT0iZnVuZGFtZW50YWxzX29mX3Byb2R1Y3RfZGVzY3JpcHRpb25fYW5kX3N1cHBvcnQiIGZpbGU9ImFjdGlvbl9zY2hlbWFleHBnMS54bWwiPgo8aW1nIHNyYz0iYWN0aW9uX3NjaGVtYWV4cGcxLmdpZiI+CjxpbWcuYXJlYSBzaGFwZT0icmVjdCIgY29vcmRzPSIyMTAsMTg2LDM0MywyMjciIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9iYXNpY19hdHRyaWJ1dGVfc2NoZW1hL2Jhc2ljX2F0dHJpYnV0ZV9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMTAsMTAsOTYsNTEiIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9hY3Rpb25fc2NoZW1hL2FjdGlvbl9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMjEwLDI2NCwzNTgsMzA1IiBocmVmPSIuLi8uLi9yZXNvdXJjZXMvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEueG1sIiAvPgo8L2ltZz4KPC9pbWdmaWxlLmNvbnRlbnQ+Cg==" height="20" width="auto" id="_" mimetype="application/xml"/>
<p keep-with-next="true">
<strong>
Key
<strong/>
</strong>
</p>
<dl class="formula_dl">
<dt>a</dt>
<dd>
<p id="_">
The time
<stem type="AsciiMath">t_90</stem>
was estimated to be 18,2 min for this example.
</p>
</dd>
<dt>A</dt>
<dd>
<p>B</p>
</dd>
</dl>
<source status="generalisation">
[SOURCE:
<xref type="inline" target="ISO712">
<span class="stdpublisher">ISO </span>
<span class="stddocNumber">712</span>
, Section 1
</xref>
— with adjustments ;
<xref type="inline" target="ISO712">
<span class="stdpublisher">ISO </span>
<span class="stddocNumber">712</span>
, Section 2
</xref>
]
</source>
</figure>
<figure id="figure-B">
<name>Figure 2</name>
<pre alt="A B">A &lt;
B</pre>
</figure>
<figure id="figure-C" unnumbered="true">
<pre>A &lt;
B</pre>
</figure>
</foreword>
</preface>
<sections>
<references id="_" obligation="informative" normative="true" displayorder="3">
<title depth="1">
1
<tab/>
Normative References
</title>
<bibitem id="ISO712" type="standard">
<formattedref>
<em>
<span class="stddocTitle">Cereals and cereal products</span>
</em>
</formattedref>
<docidentifier type="ISO">ISO 712</docidentifier>
<docidentifier scope="biblio-tag">ISO 712</docidentifier>
<biblio-tag>ISO 712, </biblio-tag>
</bibitem>
</references>
</sections>
<bibliography>
</bibliography>
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::Iso::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true).gsub(/&lt;/, "&#x3c;"))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "adds ordered list classes for HTML" do
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
Expand Down
59 changes: 0 additions & 59 deletions spec/isodoc/postproc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,65 +710,6 @@
OUTPUT
end

it "processes figure keys (Word)" do
FileUtils.rm_rf "test.doc"
IsoDoc::Iso::WordConvert
.new(WORD_HTML_CSS.dup)
.convert("test", <<~INPUT, false)
<iso-standard xmlns="http://riboseinc.com/isoxml">
<annex id="P" inline-header="false" obligation="normative" displayorder="1">
<figure id="samplecode">
<p>Hello</p>
<p>Key</p>
<dl>
<dt>
<p>A</p>
</dt>
<dd>
<p>B</p>
</dd>
</dl>
</figure>
</annex>
</iso-standard>
INPUT
word = File.read("test.doc", encoding: "UTF-8")
.sub(/^.*<div class="WordSection3">/m, '<div class="WordSection3">')
.sub(%r{<br[^>]*>\s*<div class="colophon".*$}m, "")
expect(Xml::C14n.format(word)).to be_equivalent_to Xml::C14n.format(<<~OUTPUT)
<div class="WordSection3">
<p class="MsoNormal">
<br clear="all" style="mso-special-character:line-break;page-break-before:always"/>
</p>
<div class="Section3">
<a id="P" name="P"/>
<div class="MsoNormal" style='text-align:center;'>
<a id="samplecode" name="samplecode"/>
<p class="MsoNormal">Hello</p>
<p class="MsoNormal">Key</p>
<p class="MsoNormal" style="page-break-after:avoid;">
<b>Key</b>
</p>
<div class="figdl" style="page-break-after:avoid;">
<table class="figdl">
<tr>
<td align="left" valign="top">
<p align="left" class="MsoNormal" style="margin-left:0pt;text-align:left;">
<p class="MsoNormal">A</p>
</p>
</td>
<td valign="top">
<p class="MsoNormal">B</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
OUTPUT
end

it "processes editorial notes (Word)" do
FileUtils.rm_rf "test.doc"
IsoDoc::Iso::WordConvert
Expand Down
Loading