metanorma-itu 1.0.13 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +8 -7
  3. data/.github/workflows/ubuntu.yml +12 -9
  4. data/.github/workflows/windows.yml +8 -8
  5. data/lib/asciidoctor/itu/biblio.rng +89 -32
  6. data/lib/asciidoctor/itu/cleanup.rb +80 -71
  7. data/lib/asciidoctor/itu/converter.rb +7 -11
  8. data/lib/asciidoctor/itu/front.rb +47 -18
  9. data/lib/asciidoctor/itu/isodoc.rng +475 -2
  10. data/lib/asciidoctor/itu/reqt.rng +23 -0
  11. data/lib/isodoc/itu/base_convert.rb +66 -16
  12. data/lib/isodoc/itu/html/_coverpage.scss +7 -3
  13. data/lib/isodoc/itu/html/header.html +8 -8
  14. data/lib/isodoc/itu/html/html_itu_titlepage.html +6 -7
  15. data/lib/isodoc/itu/html/htmlstyle.scss +9 -5
  16. data/lib/isodoc/itu/html/itu.scss +28 -1
  17. data/lib/isodoc/itu/html/scripts.html +14 -27
  18. data/lib/isodoc/itu/html/word_itu_intro.html +11 -1
  19. data/lib/isodoc/itu/html/word_itu_titlepage.html +3 -6
  20. data/lib/isodoc/itu/html/wordstyle.scss +6 -5
  21. data/lib/isodoc/itu/html_convert.rb +3 -3
  22. data/lib/isodoc/itu/i18n-en.yaml +2 -1
  23. data/lib/isodoc/itu/itu.recommendation-annex.xsl +3903 -0
  24. data/lib/isodoc/itu/itu.recommendation.xsl +3903 -0
  25. data/lib/isodoc/itu/itu.resolution.xsl +3903 -0
  26. data/lib/isodoc/itu/metadata.rb +16 -6
  27. data/lib/isodoc/itu/pdf_convert.rb +17 -44
  28. data/lib/isodoc/itu/ref.rb +48 -21
  29. data/lib/isodoc/itu/terms.rb +5 -6
  30. data/lib/isodoc/itu/word_convert.rb +10 -8
  31. data/lib/isodoc/itu/xref.rb +27 -16
  32. data/lib/metanorma/itu/processor.rb +8 -0
  33. data/lib/metanorma/itu/version.rb +1 -1
  34. data/metanorma-itu.gemspec +1 -1
  35. metadata +7 -5
  36. data/lib/isodoc/itu/html/scripts.pdf.html +0 -72
@@ -11,12 +11,15 @@ module IsoDoc
11
11
  File.expand_path(File.join(here, "html", "International_Telecommunication_Union_Logo.svg")))
12
12
  set(:logo_comb,
13
13
  File.expand_path(File.join(here, "html", "itu-document-comb.png")))
14
- set(:logo_word, File.expand_path(File.join(here, "html", "International_Telecommunication_Union_Logo.svg")))
14
+ set(:logo_word,
15
+ File.expand_path(File.join(here, "html", "International_Telecommunication_Union_Logo.svg")))
15
16
  end
16
17
 
17
18
  def title(isoxml, _out)
18
- main = isoxml&.at(ns("//bibdata/title[@language='en']"))&.text
19
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}'][@type = 'main']"))&.text
19
20
  set(:doctitle, main)
21
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}'][@type = 'subtitle']"))&.text
22
+ set(:docsubtitle, main)
20
23
  series = isoxml&.at(ns("//bibdata/series[@type='main']/title"))&.text
21
24
  set(:series, series)
22
25
  series1 =
@@ -66,11 +69,18 @@ module IsoDoc
66
69
  end
67
70
 
68
71
  def keywords(isoxml, _out)
69
- keywords = []
70
- isoxml.xpath(ns("//bibdata/keyword")).each do |kw|
71
- keywords << kw.text
72
+ super
73
+ set(:keywords, get[:keywords].sort)
74
+ end
75
+
76
+ def doctype(isoxml, _out)
77
+ d = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
78
+ set(:doctype_original, d)
79
+ if d == "recommendation-annex"
80
+ set(:doctype, "Recommendation")
81
+ else
82
+ super
72
83
  end
73
- set(:keywords, keywords.sort)
74
84
  end
75
85
 
76
86
  def ip_notice_received(isoxml, _out)
@@ -6,61 +6,34 @@ module IsoDoc
6
6
  module ITU
7
7
  # A {Converter} implementation that generates PDF HTML output, and a
8
8
  # document schema encapsulation of the document for validation
9
- class PdfConvert < IsoDoc::PdfConvert
9
+ class PdfConvert < IsoDoc::XslfoPdfConvert
10
10
  def initialize(options)
11
11
  @libdir = File.dirname(__FILE__)
12
12
  @hierarchical_assets = options[:hierarchical_assets]
13
13
  super
14
14
  end
15
15
 
16
- def html_toc(docxml)
17
- docxml
18
- end
19
-
20
- def default_fonts(options)
21
- {
22
- bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Open Sans",sans-serif'),
23
- headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Open Sans",sans-serif'),
24
- monospacefont: '"Space Mono",monospace'
25
- }
26
- end
27
-
28
- def default_file_locations(_options)
29
- {
30
- htmlstylesheet: html_doc_path("htmlstyle.scss"),
31
- htmlcoverpage: html_doc_path("html_itu_titlepage.html"),
32
- htmlintropage: html_doc_path("html_itu_intro.html"),
33
- scripts_pdf: html_doc_path("scripts.pdf.html"),
34
- }
35
- end
36
-
37
- def googlefonts()
38
- <<~HEAD.freeze
39
- <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,800|Space+Mono:400,700" rel="stylesheet">
40
- HEAD
41
- end
42
-
43
- def make_body(xml, docxml)
44
- body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" }
45
- xml.body **body_attr do |body|
46
- make_body1(body, docxml)
47
- make_body2(body, docxml)
48
- make_body3(body, docxml)
16
+ def pdf_stylesheet(docxml)
17
+ case doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
18
+ when "resolution" then "itu.resolution.xsl"
19
+ when "recommendation-annex" then "itu.recommendation-annex.xsl"
20
+ else
21
+ "itu.recommendation.xsl"
49
22
  end
50
23
  end
51
24
 
52
- def make_body3(body, docxml)
53
- body.div **{ class: "main-section" } do |div3|
54
- boilerplate docxml, div3
55
- abstract docxml, div3
56
- preface docxml, div3
57
- middle docxml, div3
58
- footnotes div3
59
- comments div3
25
+ def convert(filename, file = nil, debug = false)
26
+ file = File.read(filename, encoding: "utf-8") if file.nil?
27
+ docxml, outname_html, dir = convert_init(file, filename, debug)
28
+ /\.xml$/.match(filename) or
29
+ filename = Tempfile.open([outname_html, ".xml"], encoding: "utf-8") do |f|
30
+ f.write file
31
+ f.path
60
32
  end
33
+ FileUtils.rm_rf dir
34
+ ::Metanorma::Output::XslfoPdf.new.convert(
35
+ filename, outname_html + ".pdf", File.join(@libdir, pdf_stylesheet(docxml)))
61
36
  end
62
-
63
- include BaseConvert
64
37
  end
65
38
  end
66
39
  end
@@ -6,7 +6,7 @@ module IsoDoc
6
6
  module ITU
7
7
  module BaseConvert
8
8
  def norm_ref(isoxml, out, num)
9
- q = "//bibliography/references[title = 'References']"
9
+ q = "//bibliography/references[@normative = 'true']"
10
10
  f = isoxml.at(ns(q)) or return num
11
11
  out.div do |div|
12
12
  num = num + 1
@@ -17,11 +17,14 @@ module IsoDoc
17
17
  end
18
18
 
19
19
  def nonstd_bibitem(list, b, ordinal, biblio)
20
- list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
21
- ref << "[#{render_identifier(bibitem_ref_code(b))}]"
22
- date_note_process(b, ref)
23
- insert_tab(ref, 1)
24
- reference_format(b, ref)
20
+ list.tr **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
21
+ id = render_identifier(bibitem_ref_code(b))
22
+ ref.td **{style: "vertical-align:top"} do |td|
23
+ td << (id[0] || "[#{id[1]}]")&.
24
+ gsub(/-/, "&#x2011;")&.gsub(/ /, "&#xa0;")
25
+ date_note_process(b, td)
26
+ end
27
+ ref.td { |td| reference_format(b, td) }
25
28
  end
26
29
  end
27
30
 
@@ -29,6 +32,36 @@ module IsoDoc
29
32
  nonstd_bibitem(list, b, ordinal, biblio)
30
33
  end
31
34
 
35
+ def biblio_list(f, div, biblio)
36
+ div.table **{ class: "biblio", border: "0" } do |t|
37
+ i = 0
38
+ t.tbody do |tbody|
39
+ f.elements.each do |b|
40
+ if b.name == "bibitem"
41
+ next if implicit_reference(b)
42
+ i += 1
43
+ nonstd_bibitem(tbody, b, i, biblio)
44
+ else
45
+ unless %w(title clause references).include? b.name
46
+ tbody.tx do |tx|
47
+ parse(b, tx)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ f.xpath(ns("./clause | ./references")).each do |x|
55
+ parse(x, div)
56
+ end
57
+ end
58
+
59
+ def bracket_if_num(x)
60
+ return nil if x.nil?
61
+ x = x.text.sub(/^\[/, "").sub(/\]$/, "")
62
+ "[#{x}]"
63
+ end
64
+
32
65
  def reference_format(b, r)
33
66
  reference_format_start(b, r)
34
67
  reference_format_title(b, r)
@@ -38,20 +71,13 @@ module IsoDoc
38
71
  s.gsub(/ |\_|\-/, " ").split(/ /).map(&:capitalize).join(" ")
39
72
  end
40
73
 
74
+ def pref_ref_code(b)
75
+ b.at(ns("./docidentifier[@type = 'ITU']")) || super
76
+ end
77
+
41
78
  IGNORE_IDS =
42
79
  "@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor'".freeze
43
80
 
44
- def bibitem_ref_code(b)
45
- id = b.at(ns("./docidentifier[@type = 'metanorma']"))
46
- id ||= b.at(ns("./docidentifier[@type = 'ITU']"))
47
- id ||= b.at(ns("./docidentifier[not(#{IGNORE_IDS})]"))
48
- id ||= b.at(ns("./docidentifier"))
49
- return id if id
50
- id = Nokogiri::XML::Node.new("docidentifier", b.document)
51
- id.text = "(NO ID)"
52
- id
53
- end
54
-
55
81
  def multi_bibitem_ref_code(b)
56
82
  id = b.xpath(ns("./docidentifier[not(@type = 'metanorma' or #{IGNORE_IDS})]"))
57
83
  id.empty? and id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
@@ -59,7 +85,7 @@ module IsoDoc
59
85
  id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
60
86
  end
61
87
 
62
- def render_identifiers(ids)
88
+ def render_multi_identifiers(ids)
63
89
  ids.map do |id|
64
90
  id["type"] == "ITU" ? doctype_title(id) :
65
91
  docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
@@ -78,7 +104,7 @@ module IsoDoc
78
104
 
79
105
  def reference_format_start(b, r)
80
106
  id = multi_bibitem_ref_code(b)
81
- id1 = render_identifiers(id)
107
+ id1 = render_multi_identifiers(id)
82
108
  r << id1
83
109
  date = b.at(ns("./date[@type = 'published']")) and
84
110
  r << " (#{date.text.sub(/-.*$/, '')})"
@@ -97,8 +123,9 @@ module IsoDoc
97
123
  end
98
124
  end
99
125
 
100
- def format_ref(ref, prefix, isopub, date, allparts)
101
- docid_prefix(prefix, ref).sub(/^\[/, "").sub(/\]$/, "")
126
+ def reference_names(ref)
127
+ super
128
+ @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
102
129
  end
103
130
  end
104
131
  end
@@ -1,16 +1,15 @@
1
1
  module IsoDoc
2
2
  module ITU
3
3
  module BaseConvert
4
- def terms_defs_title(node)
5
- t = node.at(ns("./title")) and return t.text
6
- super
4
+ def term_def_title(node)
5
+ node
7
6
  end
8
7
 
9
8
  def terms_defs(node, out, num)
10
9
  f = node.at(ns(IsoDoc::Convert::TERM_CLAUSE)) or return num
11
10
  out.div **attr_code(id: f["id"]) do |div|
12
11
  num = num + 1
13
- clause_name(num, terms_defs_title(f), div, nil)
12
+ clause_name(num, term_def_title(f.at(ns("./title"))), div, nil)
14
13
  if f.at(ns("./clause | ./terms | ./term")).nil? then out.p "None."
15
14
  else
16
15
  f.children.reject { |c1| c1.name == "title" }.each do |c1|
@@ -40,7 +39,7 @@ module IsoDoc
40
39
  insert_tab(b, 1)
41
40
  term.children.each { |n| parse(n, b) }
42
41
  end
43
- source and p << " [#{source.value}]"
42
+ source and p << " #{bracket_opt(source.value)}"
44
43
  p << ": "
45
44
  end
46
45
  defn and defn.children.each { |n| parse(n, div) }
@@ -61,7 +60,7 @@ module IsoDoc
61
60
  end
62
61
 
63
62
  def termnote_parse(node, out)
64
- out.div **{ class: "Note" } do |div|
63
+ out.div **note_attrs(node) do |div|
65
64
  first = node.first_element_child
66
65
  div.p do |p|
67
66
  p << note_label(node) # "#{anchor(node['id'], :label) || '???'}: "
@@ -48,7 +48,7 @@ module IsoDoc
48
48
  kw.nil? || kw.empty? and return
49
49
  out.div do |div|
50
50
  clause_name(nil, "Keywords", div, class: "IntroTitle")
51
- div.p kw.sort.join(", ") + "."
51
+ div.p kw.join(", ") + "."
52
52
  end
53
53
  end
54
54
 
@@ -105,19 +105,22 @@ module IsoDoc
105
105
  super
106
106
  abstractbox = docxml.at("//div[@id='abstractbox']")
107
107
  historybox = docxml.at("//div[@id='historybox']")
108
+ sourcebox = docxml.at("//div[@id='sourcebox']")
108
109
  keywordsbox = docxml.at("//div[@id='keywordsbox']")
109
110
  abstract = docxml.at("//p[@class = 'h1Preface' and text() = 'Summary']/..")
110
111
  history = docxml.at("//p[@class = 'h1Preface' and text() = 'History']/..")
112
+ source = docxml.at("//p[@class = 'h1Preface' and text() = 'Source']/..")
111
113
  keywords = docxml.at("//p[@class = 'h1Preface' and text() = 'Keywords']/..")
112
114
  abstract.parent = abstractbox if abstract && abstractbox
113
115
  history.parent = historybox if history && historybox
116
+ source.parent = sourcebox if source && sourcebox
114
117
  keywords.parent = keywordsbox if keywords && keywordsbox
115
118
  end
116
119
 
117
120
  def formula_parse1(node, out)
118
- out.div **attr_code(id: node["id"], class: "formula") do |div|
121
+ out.div **attr_code(class: "formula") do |div|
119
122
  div.p **attr_code(class: "formula") do |p|
120
- insert_tab(div, 2)
123
+ insert_tab(div, 1)
121
124
  parse(node.at(ns("./stem")), div)
122
125
  lbl = anchor(node['id'], :label, false)
123
126
  unless lbl.nil?
@@ -150,10 +153,8 @@ module IsoDoc
150
153
  super.merge(valign: "top")
151
154
  end
152
155
 
153
- def ol_parse(node, out)
154
- out.ol **attr_code(class: node["class"], id: node["id"] ) do |ol|
155
- node.children.each { |n| parse(n, ol) }
156
- end
156
+ def ol_attrs(node)
157
+ { class: node["class"], id: node["id"], style: keep_style(node) }
157
158
  end
158
159
 
159
160
  def toWord(result, filename, dir, header)
@@ -211,8 +212,9 @@ module IsoDoc
211
212
  next unless auth && dest
212
213
  t == "copyright" and p = auth&.at(".//p") and
213
214
  p["class"] = "boilerplateHdr"
214
- auth&.xpath(".//p[not(@class)]")&.each do |p|
215
+ auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
215
216
  p["class"] = "boilerplate"
217
+ i == 0 && t == "copyright" and p["style"] = "text-align:center;"
216
218
  end
217
219
  auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>" unless t == "copyright"
218
220
  dest.replace(auth.remove)
@@ -15,9 +15,13 @@ module IsoDoc
15
15
  @anchors[clause["id"]] =
16
16
  { label: annex_name_lbl(clause, num), type: "clause",
17
17
  xref: "#{lbl} #{num}", level: 1 }
18
- clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).
19
- each_with_index do |c, i|
20
- annex_names1(c, "#{num}.#{i + 1}", 2)
18
+ if a = single_annex_special_section(clause)
19
+ annex_names1(a, "#{num}", 1)
20
+ else
21
+ clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).
22
+ each_with_index do |c, i|
23
+ annex_names1(c, "#{num}.#{i + 1}", 2)
24
+ end
21
25
  end
22
26
  hierarchical_asset_names(clause, num)
23
27
  end
@@ -52,8 +56,8 @@ module IsoDoc
52
56
  hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"), "Preface") :
53
57
  sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
54
58
  n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1)
55
- n = section_names(d.at(ns("//bibliography/clause[title = 'References'] | "\
56
- "//bibliography/references[title = 'References']")), n, 1)
59
+ n = section_names(d.at(ns("//bibliography/clause[.//references[@normative = 'true']] | "\
60
+ "//bibliography/references[@normative = 'true']")), n, 1)
57
61
  n = section_names(d.at(ns("//sections/terms | "\
58
62
  "//sections/clause[descendant::terms]")), n, 1)
59
63
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
@@ -63,15 +67,11 @@ module IsoDoc
63
67
  termexample_anchor_names(d)
64
68
  end
65
69
 
66
- def hiersep
67
- "-"
68
- end
69
-
70
70
  MIDDLE_SECTIONS = "//clause[title = 'Scope'] | "\
71
- "//foreword | //introduction | //acknowledgements | "\
72
- "//references[title = 'References' or title = 'references'] | "\
73
- "//sections/terms | //preface/clause | "\
74
- "//sections/definitions | //clause[parent::sections]".freeze
71
+ "//foreword | //introduction | //acknowledgements | "\
72
+ "//references[@normative = 'true'] | "\
73
+ "//sections/terms | //preface/clause | "\
74
+ "//sections/definitions | //clause[parent::sections]".freeze
75
75
 
76
76
  def middle_section_asset_names(d)
77
77
  return super unless @hierarchical_assets
@@ -89,7 +89,7 @@ module IsoDoc
89
89
  j = 0
90
90
  c.increment(t)
91
91
  end
92
- label = c.print + (j.zero? ? "" : "-#{(97 + j).chr.to_s}")
92
+ label = c.print + (j.zero? ? "" : "-#{(96 + j).chr.to_s}")
93
93
  next if t["id"].nil? || t["id"].empty?
94
94
  @anchors[t["id"]] =
95
95
  anchor_struct(label, nil, @figure_lbl, "figure", t["unnumbered"])
@@ -106,7 +106,7 @@ module IsoDoc
106
106
  c.increment(t)
107
107
  end
108
108
  label = "#{num}#{hiersep}#{c.print}" +
109
- (j.zero? ? "" : "#{hierfigsep}#{(97 + j).chr.to_s}")
109
+ (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
110
110
  next if t["id"].nil? || t["id"].empty?
111
111
  @anchors[t["id"]] = anchor_struct(label, nil, @figure_lbl, "figure",
112
112
  t["unnumbered"])
@@ -116,12 +116,23 @@ module IsoDoc
116
116
  def sequential_formula_names(clause)
117
117
  clause&.first&.xpath(ns(MIDDLE_SECTIONS))&.each do |c|
118
118
  if c["id"] && @anchors[c["id"]]
119
- hierarchical_formula_names(c, @anchors[c["id"]][:label] || @anchors[c["id"]][:xref] || "???")
119
+ hierarchical_formula_names(c, @anchors[c["id"]][:label] || @anchors[c["id"]][:xref] || "???")
120
120
  else
121
121
  hierarchical_formula_names(c, "???")
122
122
  end
123
123
  end
124
124
  end
125
+
126
+ def hierarchical_formula_names(clause, num)
127
+ c = IsoDoc::Function::XrefGen::Counter.new
128
+ clause.xpath(ns(".//formula")).each do |t|
129
+ next if t["id"].nil? || t["id"].empty?
130
+ @anchors[t["id"]] =
131
+ anchor_struct("#{num}-#{c.increment(t).print}", nil,
132
+ t["inequality"] ? @inequality_lbl : @formula_lbl,
133
+ "formula", t["unnumbered"])
134
+ end
135
+ end
125
136
  end
126
137
  end
127
138
  end
@@ -2,6 +2,14 @@ require "metanorma/processor"
2
2
 
3
3
  module Metanorma
4
4
  module ITU
5
+ def self.fonts_used
6
+ {
7
+ html: ["Arial", "Courier New", "Times New Roman"],
8
+ doc: ["Arial", "Courier New", "Times New Roman"],
9
+ pdf: ["Arial", "Courier New", "Times New Roman"]
10
+ }
11
+ end
12
+
5
13
  class Processor < Metanorma::Processor
6
14
 
7
15
  def initialize
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ITU
3
- VERSION = "1.0.13"
3
+ VERSION = "1.0.18"
4
4
  end
5
5
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "htmlentities", "~> 4.3.4"
28
28
  spec.add_dependency "ruby-jing"
29
- spec.add_dependency "metanorma-standoc", "~> 1.3.0"
29
+ spec.add_dependency "metanorma-standoc", "~> 1.4.0"
30
30
  spec.add_dependency "isodoc", "~> 1.0.0"
31
31
 
32
32
  spec.add_development_dependency "byebug", "~> 9.1"