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 rendering of concepts with missing term reference: https://github… #176

Merged
merged 1 commit into from
Nov 14, 2022
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
2 changes: 2 additions & 0 deletions lib/isodoc/ieee/presentation_ref.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "../../relaton/render/general"

module IsoDoc
module IEEE
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
Expand Down
16 changes: 5 additions & 11 deletions lib/isodoc/ieee/presentation_terms.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_relative "../../relaton/render/general"

module IsoDoc
module IEEE
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
Expand Down Expand Up @@ -28,9 +26,7 @@ def unwrap_multidef(coll)
if coll.all? do |c|
c.elements.size == 1 && c.elements.first.name == "p"
end
ret = coll.map do |c|
c.elements.first.children.to_xml
end
ret = coll.map { |c| c.elements.first.children.to_xml }
return "<p>#{ret.join}</p>"
end
coll.map { |c| c.children.to_xml }.join
Expand Down Expand Up @@ -61,9 +57,9 @@ def term_related_collapse(coll)
prev = 0
coll[1..-1].each_with_index do |r, i|
if coll[prev]["type"] != r["type"]
prev = i
next
prev = i and next
end

coll[prev].at(ns("./preferred")) << "; #{r.at(ns('./preferred'))
.children.to_xml}"
r.remove
Expand All @@ -81,8 +77,7 @@ def sort_terms_key(term)
end

def sort_terms_key1(elem)
return "zzzz" if elem.nil?

elem.nil? and return "zzzz"
dup = elem.dup
dup.xpath(ns(".//asciimath | .//latexmath")).each(&:remove)
dup.text&.strip&.downcase || "zzzz"
Expand Down Expand Up @@ -190,8 +185,7 @@ def collapse_term_template(opt)
opt[:source] and src = "(#{opt[:source].remove.children.to_xml.strip})"
<<~TERM
<p>#{opt[:pref]&.children&.to_xml || '**TERM NOT FOUND**'}: #{defn}
#{collapse_term_related(opt[:rels])}
#{src}</p>
#{collapse_term_related(opt[:rels])} #{src}</p>
TERM
end

Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/ieee/isodoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@
<data type="boolean"/>
</attribute>
</optional>
<ref name="BibliographicItem"/>
<ref name="ReducedBibliographicItem"/>
</element>
</define>
<define name="image" combine="choice">
Expand Down
5 changes: 3 additions & 2 deletions lib/metanorma/ieee/term_lookup_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module IEEE
class TermLookupCleanup < Metanorma::Standoc::TermLookupCleanup
def remove_missing_ref_term(node, _target)
node.at("../xrefrender")&.remove
node.replace("<preferred><expression><name>#{node.children.to_xml}"\
"</name></expression></preferred>")
#node.replace("<preferred><expression><name>#{node.children.to_xml}"\
# "</name></expression></preferred>")
node.replace("<refterm>#{node.children.to_xml}</refterm>")
end
end
end
Expand Down
20 changes: 9 additions & 11 deletions lib/metanorma/ieee/validate_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Metanorma
module IEEE
class Converter < Standoc::Converter
ASSETS_TO_STYLE =
"//termsource | //formula | //termnote | "\
"//p[not(ancestor::boilerplate)] | //li[not(p)] | //dt | "\
"//dd[not(p)] | //td[not(p)][not(ancestor::boilerplate)] | "\
"//termsource | //formula | //termnote | " \
"//p[not(ancestor::boilerplate)] | //li[not(p)] | //dt | " \
"//dd[not(p)] | //td[not(p)][not(ancestor::boilerplate)] | " \
"//th[not(p)][not(ancestor::boilerplate)] | //example".freeze

def extract_text(node)
Expand Down Expand Up @@ -56,8 +56,8 @@ def style_percent(node, text)
end

# leaving out as problematic: N J K C S T H h d B o E
SI_UNIT = "(m|cm|mm|km|μm|nm|g|kg|mgmol|cd|rad|sr|Hz|Hz|MHz|Pa|hPa|kJ|"\
"V|kV|W|MW|kW|F|μF|Ω|Wb|°C|lm|lx|Bq|Gy|Sv|kat|l|t|eV|u|Np|Bd|"\
SI_UNIT = "(m|cm|mm|km|μm|nm|g|kg|mgmol|cd|rad|sr|Hz|Hz|MHz|Pa|hPa|kJ|" \
"V|kV|W|MW|kW|F|μF|Ω|Wb|°C|lm|lx|Bq|Gy|Sv|kat|l|t|eV|u|Np|Bd|" \
"bit|kB|MB|Hart|nat|Sh|var)".freeze

# Style manual 14.2
Expand All @@ -84,15 +84,15 @@ def table_style(docxml)
# deliberately doing naive, ignoring rowspan
def table_style_columns(table)
table_extract_columns(table).each do |col|
next unless col.any? do |x|
col.any? do |x|
/^[0-9. ]+$/.match?(x) &&
(/\d{3} \d/.match?(x) || /\d \d{3}/.match?(x))
end
end or next

col.each do |x|
/^[0-9. ]+$/.match?(x) && /\d{4}/.match?(x) and
@log.add("Style", table,
"#{x} is a 4-digit number in a table column with "\
"#{x} is a 4-digit number in a table column with " \
"numbers broken up in threes")
end
end
Expand All @@ -108,7 +108,7 @@ def table_extract_columns(table)
ret.map { |x| x.is_a?(Array) ? x : [] }
end

def title_validate(xml)
def title_validate(xml)
title_validate_type(xml)
title_validate_capitalisation(xml)
end
Expand All @@ -118,8 +118,6 @@ def title_validate_type(xml)
title = xml.at("//bibdata/title") or return
draft = xml.at("//bibdata//draft")
type = xml.at("//bibdata/ext/doctype")
subtype = xml.at("//bibdata/ext/subdoctype")
subtype = "" if subtype == "document"
trial = xml.at("//bibdata/ext/trial-use[text() = 'true']")
target = draft ? "Draft " : ""
target += trial ? "Trial-Use " : ""
Expand Down
84 changes: 25 additions & 59 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
The Aforementioned Citation
</eref>
</concept></li>
<li><concept><refterm>term</refterm>
<li><concept><refterm>term</refterm></concept></li>
<li><concept><refterm>term</refterm>
<renderterm>word</renderterm>
<termref base='IEV' target='135-13-13'/>
Expand Down Expand Up @@ -404,64 +404,30 @@
</iso-standard>
INPUT
presxml = <<~OUTPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
<preface>
<foreword displayorder='1'>
<p>
<ul>
<li> </li>
<li> term </li>
<li> w[o]rd </li>
<li> term </li>
<li> word </li>
<li> word </li>
<li> word </li>
<li> word </li>
<li>
<li> word </li>
<li> word </li>
<li>
<strong>error!</strong>
</li>
</li>
</ul>
</p>
<sections>
<clause id='clause1' displayorder='3'>
<title depth='1'>
2.
<tab/>
Clause 1
</title>
</clause>
</sections>
<bibliography>
<references id='_normative_references' obligation='informative' normative='true' displayorder='2'>
<title depth='1'>
1.
<tab/>
Normative References
</title>
<p>
The following documents are referred to in the text in such a way
that some or all of their content constitutes requirements of this
document. For dated references, only the edition cited applies. For
undated references, the latest edition of the referenced document
(including any amendments) applies.
</p>
<bibitem id='ISO712' type='standard'>
<formattedref>Cereals and cereal products.</formattedref>
<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>
</bibitem>
</references>
</bibliography>
</foreword>
</preface>
</iso-standard>
<foreword displayorder='1'>
<p>
<ul>
<li> </li>
<li>term</li>
<li>w[o]rd</li>
<li>term</li>
<li>word</li>
<li>word</li>
<li>word</li>
<li>word</li>
<li/>
<li>word</li>
<li>word</li>
<li>
<strong>error!</strong>
</li>
</ul>
</p>
</foreword>
OUTPUT
expect(xmlpp(IsoDoc::IEEE::PresentationXMLConvert.new({})
.convert("test", input, true))).to be_equivalent_to xmlpp(presxml)
xml = Nokogiri::XML(IsoDoc::IEEE::PresentationXMLConvert.new({})
.convert("test", input, true))
expect(xmlpp(xml.at("//xmlns:foreword").to_xml))
.to be_equivalent_to xmlpp(presxml)
end
end
22 changes: 11 additions & 11 deletions spec/vcr_cassettes/iso123.yml

Large diffs are not rendered by default.