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 20241106 #1239

Merged
merged 2 commits into from
Nov 10, 2024
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
6 changes: 4 additions & 2 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/presxml-20241106"



33 changes: 4 additions & 29 deletions lib/isodoc/iso/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,18 @@ def table_th_center(docxml)
end
end

def admonition_parse(node, out)
type = node["type"]
name = admonition_name(node, type)
out.div id: node["id"], class: admonition_class(node) do |div|
if node.first_element_child.name == "p"
admonition_p_parse(node, div, name)
else
admonition_parse1(node, div, name)
end
end
end

def admonition_class(node)
if node["type"] == "editorial" then "zzHelp"
else super
end
end

def admonition_parse1(node, div, name)
div.p do |p|
admonition_name_parse(node, p, name) if name
end
node.children.each { |n| parse(n, div) unless n.name == "name" }
end

def admonition_p_parse(node, div, name)
div.p do |p|
admonition_name_parse(node, p, name) if name
node.first_element_child.children.each { |n| parse(n, p) }
end
node.element_children[1..].each { |n| parse(n, div) }
def admonition_p_parse(node, div)
admonition_name_in_first_para(node, div)
end

# TODO to presentation XML
def admonition_name_parse(_node, div, name)
name.children.each { |n| parse(n, div) }
div << " &#x2014; "
def admonition_name_para_delim(para)
para << " "
end

def figure_name_parse(_node, div, name)
Expand Down
21 changes: 8 additions & 13 deletions lib/isodoc/iso/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def clause(docxml)

def admonition1(elem)
super
admonition_inline_name(elem)
admonition_outside_clauses(elem)
end

Expand All @@ -118,18 +117,6 @@ def wrap_in_bold(cell)
cell.children.each { |p| wrap_in_bold(p) }
end

# TODO keep name, and append em-dash within it
def admonition_inline_name(elem)
n = elem.at(ns("./name")) or return
if (p = n.next_element) && p&.name == "p"
p.add_first_child admonition_name(to_xml(n.remove.children))
end
end

def admonition_name(xml)
"#{xml} &#x2014; "
end

def bibrender_formattedref(formattedref, xml)
%w(techreport standard).include? xml["type"] and return
super
Expand Down Expand Up @@ -238,6 +225,14 @@ def render_identifier(ident)
ret
end

def admonition_delim(elem)
if elem.at("./*[not(self::xmlns:name)]")&.name == "p"
" &#x2014; "
else
""
end
end

include Init
end
end
Expand Down
23 changes: 12 additions & 11 deletions spec/isodoc/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::Iso::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
expect(Xml::C14n.format(IsoDoc::Iso::HtmlConvert.new({})
.convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html)
.convert("test", presxml, true)))
.to be_equivalent_to Xml::C14n.format(html)
output = IsoDoc::Iso::WordConvert.new({}).convert("test", presxml, true)
expect(Xml::C14n.format(output
.sub(/^.*<body/m, "<body").sub(%r{</body>.*$}m, "</body>")))
Expand All @@ -214,8 +216,8 @@
</clause>
<foreword displayorder="2"><title>Foreword</title>
<admonition id="_" type="caution">
<p id='_'>
CAUTION — Only use paddy or parboiled rice for the
<name>CAUTION — </name>
<p id='_'>Only use paddy or parboiled rice for the
determination of husked rice yield.
</p>
<p id="_">Para 2.</p>
Expand Down Expand Up @@ -264,7 +266,7 @@
</clause>
<foreword displayorder="2"><title>Foreword</title>
<admonition id="_" type="caution">
<name>CAUTION</name>
<name>CAUTION<</name>
</admonition>
</foreword>
</preface>
Expand Down Expand Up @@ -311,7 +313,7 @@
<div>
<h1 class='ForewordTitle'>Foreword</h1>
<div id='_' class='Admonition'>
<p>Title — </p>
<p class="AdmonitionTitle" style="text-align:center;">Title</p>
<div class="ul_wrap">
<ul>
<li>List</li>
Expand Down Expand Up @@ -352,8 +354,8 @@
<sections>
<title>A</title>
<admonition id="_" type="important" displayorder="2">
<name><strong>IMPORTANT —</strong></name>
<p id="_">
<strong>IMPORTANT — </strong>
<strong>The electronic file of this document contains colours which are considered to be useful for the correct understanding of the &lt;document&gt;.</strong>
</p>
</admonition>
Expand Down Expand Up @@ -388,8 +390,8 @@
</clause>
<foreword displayorder="2"><title>Foreword</title>
<admonition id="_" type="editorial">
<p id='_'>EDITORIAL NOTE —
Only use paddy or parboiled rice for the
<name>EDITORIAL NOTE —</name>
<p id="_">Only use paddy or parboiled rice for the
determination of husked rice yield.
</p>
<p id="_">Para 2.</p>
Expand All @@ -403,8 +405,7 @@
<div>
<h1 class='ForewordTitle'>Foreword</h1>
<div id='_' class='zzHelp'>
<p>EDITORIAL NOTE —
Only use paddy or parboiled rice for the
<p>EDITORIAL NOTE — Only use paddy or parboiled rice for the
determination of husked rice yield.
</p>
<p id='_'>Para 2.</p>
Expand Down
Loading