diff --git a/lib/isodoc/itu/presentation_ref.rb b/lib/isodoc/itu/presentation_ref.rb
new file mode 100644
index 00000000..03fdf630
--- /dev/null
+++ b/lib/isodoc/itu/presentation_ref.rb
@@ -0,0 +1,96 @@
+require_relative "init"
+require "roman-numerals"
+require "isodoc"
+require_relative "../../relaton/render/general"
+require_relative "presentation_bibdata"
+require_relative "presentation_preface"
+
+module IsoDoc
+ module ITU
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
+ def bibrenderer
+ ::Relaton::Render::ITU::General.new(language: @lang)
+ end
+
+ def bibrender_formattedref(formattedref, _xml)
+ formattedref << "." unless /\.$/.match?(formattedref.text)
+ id = reference_format_start(formattedref.parent) and
+ formattedref.children.first.previous = id
+ end
+
+ def bibrender_relaton(xml, renderings)
+ f = renderings[xml["id"]][:formattedref]
+ ids = reference_format_start(xml)
+ f &&= "#{ids}#{f}"
+ # retain date in order to generate reference tag
+ keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag"
+ xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
+ end
+
+ def multi_bibitem_ref_code(bib)
+ skip = IsoDoc::Function::References::SKIP_DOCID
+ skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
+ prim = "[@primary = 'true']"
+ id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
+ id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
+ id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
+ id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
+ id.empty? and return id
+ id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
+ end
+
+ def render_multi_identifiers(ids)
+ ids.map do |id|
+ if id["type"] == "ITU" then doctype_title(id)
+ else
+ docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
+ end
+ end.join(" | ")
+ end
+
+ def reference_format_start(bib)
+ id = multi_bibitem_ref_code(bib)
+ id1 = render_multi_identifiers(id)
+ out = id1
+ date = bib.at(ns("./date[@type = 'published']/on | " \
+ "./date[@type = 'published']/from")) and
+ out << " (#{date.text.sub(/-.*$/, '')})"
+ out += ", " if date || !id1.empty?
+ out
+ end
+
+ def bibliography_bibitem_number1(bib, idx)
+ mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
+ /^\[?\d+\]?$/.match?(mn.text) and
+ mn["type"] = "metanorma-ordinal"
+ if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
+ !bibliography_bibitem_number_skip(bib)
+ idx += 1
+ mn.children = "[#{idx}]"
+ end
+ idx
+ end
+
+ def bibliography_bibitem_number_skip(bibitem)
+ @xrefs.klass.implicit_reference(bibitem) ||
+ bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
+ end
+
+ def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
+ ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
+ /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
+ ret += datefn
+ ret.empty? and return ret
+ ret.gsub("-", "‑").gsub(/ /, " ")
+ end
+
+ def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
+ ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
+ /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
+ ret += datefn
+ ret.empty? and return ret
+ ret.gsub("-", "‑").gsub(/ /, " ")
+ end
+ end
+ end
+end
diff --git a/lib/isodoc/itu/presentation_xml_convert.rb b/lib/isodoc/itu/presentation_xml_convert.rb
index 79bfa691..15a5b2ca 100644
--- a/lib/isodoc/itu/presentation_xml_convert.rb
+++ b/lib/isodoc/itu/presentation_xml_convert.rb
@@ -4,6 +4,18 @@
require_relative "../../relaton/render/general"
require_relative "presentation_bibdata"
require_relative "presentation_preface"
+require_relative "presentation_ref"
+
+module Nokogiri
+ module XML
+ class Node
+ def traverse_topdown(&block)
+ yield(self)
+ children.each { |j| j.traverse_topdown(&block) }
+ end
+ end
+ end
+end
module IsoDoc
module ITU
@@ -39,6 +51,25 @@ def note1(elem)
super
end
+ def table1(elem)
+ elem.xpath(ns("./name | ./thead/tr/th")).each do |n|
+ capitalise_unless_text_transform(n)
+ end
+ super
+ end
+
+ def capitalise_unless_text_transform(elem)
+ css = nil
+ elem.traverse_topdown do |n|
+ n.name == "span" && /text-transform:/.match?(n["style"]) and
+ css = n
+ n.text? && /\S/.match?(n.text) or next
+ css && n.ancestors.include?(css) or
+ n.replace(::Metanorma::Utils.strict_capitalize_first(n.text))
+ break
+ end
+ end
+
def get_eref_linkend(node)
non_locality_elems(node).select do |c|
!c.text? || /\S/.match(c)
@@ -52,57 +83,6 @@ def get_eref_linkend(node)
node.add_child(link)
end
- def bibrenderer
- ::Relaton::Render::ITU::General.new(language: @lang)
- end
-
- def bibrender_formattedref(formattedref, _xml)
- formattedref << "." unless /\.$/.match?(formattedref.text)
- id = reference_format_start(formattedref.parent) and
- formattedref.children.first.previous = id
- end
-
- def bibrender_relaton(xml, renderings)
- f = renderings[xml["id"]][:formattedref]
- ids = reference_format_start(xml)
- f &&= "#{ids}#{f}"
- # retain date in order to generate reference tag
- keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag"
- xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
- end
-
- def multi_bibitem_ref_code(bib)
- skip = IsoDoc::Function::References::SKIP_DOCID
- skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
- prim = "[@primary = 'true']"
- id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
- id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
- id.empty? and return id
- id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
- end
-
- def render_multi_identifiers(ids)
- ids.map do |id|
- if id["type"] == "ITU" then doctype_title(id)
- else
- docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
- end
- end.join(" | ")
- end
-
- def reference_format_start(bib)
- id = multi_bibitem_ref_code(bib)
- id1 = render_multi_identifiers(id)
- out = id1
- date = bib.at(ns("./date[@type = 'published']/on | " \
- "./date[@type = 'published']/from")) and
- out << " (#{date.text.sub(/-.*$/, '')})"
- out += ", " if date || !id1.empty?
- out
- end
-
def titlecase(str)
str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
end
@@ -165,39 +145,6 @@ def info(isoxml, out)
super
end
- def bibliography_bibitem_number1(bib, idx)
- mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
- /^\[?\d+\]?$/.match?(mn.text) and
- mn["type"] = "metanorma-ordinal"
- if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
- !bibliography_bibitem_number_skip(bib)
- idx += 1
- mn.children = "[#{idx}]"
- end
- idx
- end
-
- def bibliography_bibitem_number_skip(bibitem)
- @xrefs.klass.implicit_reference(bibitem) ||
- bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
- end
-
- def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
- ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
- /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
- ret += datefn
- ret.empty? and return ret
- ret.gsub("-", "‑").gsub(/ /, " ")
- end
-
- def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
- ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
- /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
- ret += datefn
- ret.empty? and return ret
- ret.gsub("-", "‑").gsub(/ /, " ")
- end
-
def toc_title(docxml)
@doctype == "resolution" and return
super
diff --git a/lib/metanorma/itu/cleanup.rb b/lib/metanorma/itu/cleanup.rb
index 95a8783b..adc5cf40 100644
--- a/lib/metanorma/itu/cleanup.rb
+++ b/lib/metanorma/itu/cleanup.rb
@@ -24,6 +24,13 @@ def table_cleanup(xmldoc)
end
end
+ def header_rows_cleanup(xmldoc)
+ super
+ xmldoc.xpath("//table/thead/tr/th").each do |x|
+ x["align"] = "center"
+ end
+ end
+
def insert_missing_sections(xml)
xml.at("//metanorma-extension/semantic-metadata/" \
"headless[text() = 'true']") and return nil
diff --git a/lib/metanorma/itu/converter.rb b/lib/metanorma/itu/converter.rb
index fd61c42c..4a8ccf7d 100644
--- a/lib/metanorma/itu/converter.rb
+++ b/lib/metanorma/itu/converter.rb
@@ -36,7 +36,8 @@ def makexml(node)
end
def doctype(node)
- ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase || "recommendation"
+ ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase ||
+ "recommendation"
ret = "recommendation" if ret == "article"
ret
end
@@ -87,7 +88,7 @@ def sectiontype_streamline(ret)
def sectiontype(node, level = true)
ret = super
- hdr = sectiontype_streamline(node&.attr("heading")&.downcase)
+ hdr = sectiontype_streamline(node.attr("heading")&.downcase)
return nil if ret == "terms and definitions" &&
hdr != "terms and definitions" && node.level > 1
return nil if ret == "symbols and abbreviated terms" &&
@@ -120,10 +121,8 @@ def clause_parse(attrs, xml, node)
node.option?("unnumbered") and attrs[:unnumbered] = true
case sectiontype1(node)
when "conventions" then attrs = attrs.merge(type: "conventions")
- when "history"
- attrs[:preface] and attrs = attrs.merge(type: "history")
- when "source"
- attrs[:preface] and attrs = attrs.merge(type: "source")
+ when "history", "source"
+ attrs[:preface] and attrs = attrs.merge(type: sectiontype1(node))
end
super
end
@@ -141,7 +140,8 @@ def doc_extract_attributes(node)
def presentation_xml_converter(node)
IsoDoc::ITU::PresentationXMLConvert
.new(html_extract_attributes(node)
- .merge(output_formats: ::Metanorma::ITU::Processor.new.output_formats))
+ .merge(output_formats: ::Metanorma::ITU::Processor.new
+ .output_formats))
end
def html_converter(node)
diff --git a/metanorma-itu.gemspec b/metanorma-itu.gemspec
index 748ebfff..8e134c17 100644
--- a/metanorma-itu.gemspec
+++ b/metanorma-itu.gemspec
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
spec.add_dependency "metanorma-standoc", "~> 2.8.2"
+ spec.add_dependency "pubid-itu"
spec.add_dependency "twitter_cldr", ">= 3.0.0"
spec.add_dependency "tzinfo-data" # we need this for windows only
diff --git a/spec/isodoc/blocks_spec.rb b/spec/isodoc/blocks_spec.rb
index 98553589..e09ec8ff 100644
--- a/spec/isodoc/blocks_spec.rb
+++ b/spec/isodoc/blocks_spec.rb
@@ -148,7 +148,8 @@
OUTPUT
- expect(xmlpp(strip_guid(IsoDoc::ITU::PresentationXMLConvert.new(presxml_options)
+ expect(xmlpp(strip_guid(IsoDoc::ITU::PresentationXMLConvert
+ .new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to xmlpp(presxml)
expect(xmlpp(IsoDoc::ITU::WordConvert.new({})
.convert("test", presxml, true)
@@ -159,59 +160,59 @@
it "processes tables (Word)" do
input = <<~INPUT
-
-
-
- Table 1 — Repeatability and reproducibility of husked rice yield
-
-
- Description |
- Rice sample |
-
-
- Arborio |
- Drago
- Parboiled rice.
- |
- Balilla
- Parboiled rice.
- |
- Thaibonnet |
-
-
-
-
- Number of laboratories retained after eliminating outliers
- | 13 |
- 11 |
- 13 |
- 13 |
-
-
- Mean value, g/100 g |
- 81,2 |
- 82,0 |
- 81,8 |
- 77,7 |
-
-
-
-
- Reproducibility limit, R (= 2,83 s_R) |
- 2,89 |
- 0,57 |
- 2,26 |
- 6,06 |
-
-
-
- - Drago
- - A type of rice
-
- NOTEThis is a table about rice
-
-
-
+
+
+
+ Table 1 — Repeatability and reproducibility of husked rice yield
+
+
+ Description |
+ Rice sample |
+
+
+ Arborio |
+ Drago
+ Parboiled rice.
+ |
+ Balilla
+ Parboiled rice.
+ |
+ Thaibonnet |
+
+
+
+
+ Number of laboratories retained after eliminating outliers
+ | 13 |
+ 11 |
+ 13 |
+ 13 |
+
+
+ Mean value, g/100 g |
+ 81,2 |
+ 82,0 |
+ 81,8 |
+ 77,7 |
+
+
+
+
+ Reproducibility limit, R (= 2,83 s_R) |
+ 2,89 |
+ 0,57 |
+ 2,26 |
+ 6,06 |
+
+
+
+ - Drago
+ - A type of rice
+
+ NOTEThis is a table about rice
+
+
+
INPUT
output = <<~OUTPUT
@@ -420,6 +421,104 @@
.to be_equivalent_to xmlpp(doc)
end
+ it "capitalises table titles" do
+ input = <<~INPUT
+
+
+ title title
+
+ title title1 | title Title2 | title title3 |
+
+
+ title title4 | title title5 | title title6 |
+
+
+
+
+ INPUT
+ presxml = <<~OUTPUT
+
+
+
+ Table of Contents
+
+
+
+ Table — Title title
+
+
+ Title title1 |
+ Title Title2 |
+ title title3 |
+
+
+
+
+ title title4 |
+ title title5 |
+ title title6 |
+
+
+
+
+
+
+ OUTPUT
+ expect(xmlpp(strip_guid(IsoDoc::ITU::PresentationXMLConvert
+ .new(presxml_options)
+ .convert("test", input, true)
+ .gsub(%r{
.*}m, ""))))
+ .to be_equivalent_to xmlpp(presxml)
+
+ input = <<~INPUT
+
+
+ title title
+
+ title title1 | title title2 | title title3 |
+
+
+ title title4 | title title5 | title title6 |
+
+
+
+
+ INPUT
+ presxml = <<~OUTPUT
+
+
+
+ Table of Contents
+
+
+
+ Table — title title
+
+
+ title title1 |
+ title title2 |
+ title title3 |
+
+
+
+
+ title title4 |
+ title title5 |
+ title title6 |
+
+
+
+
+
+
+ OUTPUT
+ expect(xmlpp(strip_guid(IsoDoc::ITU::PresentationXMLConvert
+ .new(presxml_options)
+ .convert("test", input, true)
+ .gsub(%r{
.*}m, ""))))
+ .to be_equivalent_to xmlpp(presxml)
+ end
+
it "post-processes steps class of ordered lists (Word)" do
FileUtils.rm_f "test.doc"
FileUtils.rm_f "test.html"
diff --git a/spec/metanorma/base_spec.rb b/spec/metanorma/base_spec.rb
index 2ef4d695..8596a8cb 100644
--- a/spec/metanorma/base_spec.rb
+++ b/spec/metanorma/base_spec.rb
@@ -666,7 +666,8 @@
OUTPUT
- xml.xpath("//xmlns:boilerplate | //xmlns:metanorma-extension | //xmlns:fetched")
+ xml.xpath("//xmlns:boilerplate | //xmlns:metanorma-extension | " \
+ "//xmlns:fetched")
.each(&:remove)
expect(xmlpp(xml.to_xml))
.to be_equivalent_to xmlpp(output)
@@ -1838,7 +1839,7 @@
.to be_equivalent_to xmlpp(output)
end
- it "capitalises table header" do
+ it "capitalises and centers table header" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
[headerrows=2]
@@ -1856,14 +1857,14 @@
- A b |
- B c |
- C |
+ A b |
+ B c |
+ C |
- a |
- b |
- c |
+ a |
+ b |
+ c |