metanorma-itu 1.0.15 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +8 -1
  3. data/.github/workflows/ubuntu.yml +20 -7
  4. data/.github/workflows/windows.yml +8 -1
  5. data/lib/asciidoctor/itu/biblio.rng +36 -6
  6. data/lib/asciidoctor/itu/cleanup.rb +7 -7
  7. data/lib/asciidoctor/itu/converter.rb +18 -16
  8. data/lib/asciidoctor/itu/front.rb +25 -0
  9. data/lib/asciidoctor/itu/isodoc.rng +444 -1
  10. data/lib/asciidoctor/itu/reqt.rng +23 -0
  11. data/lib/isodoc/itu.rb +1 -0
  12. data/lib/isodoc/itu/base_convert.rb +71 -17
  13. data/lib/isodoc/itu/html/_coverpage.scss +7 -3
  14. data/lib/isodoc/itu/html/html_itu_titlepage.html +4 -5
  15. data/lib/isodoc/itu/html/htmlstyle.scss +9 -5
  16. data/lib/isodoc/itu/html/itu.scss +27 -0
  17. data/lib/isodoc/itu/html/scripts.html +10 -7
  18. data/lib/isodoc/itu/html/word_itu_intro.html +11 -1
  19. data/lib/isodoc/itu/html/word_itu_titlepage.html +1 -4
  20. data/lib/isodoc/itu/html/wordstyle.scss +6 -5
  21. data/lib/isodoc/itu/i18n-en.yaml +2 -1
  22. data/lib/isodoc/itu/itu.recommendation-annex.xsl +1186 -417
  23. data/lib/isodoc/itu/itu.recommendation.xsl +1186 -417
  24. data/lib/isodoc/itu/itu.resolution.xsl +1186 -417
  25. data/lib/isodoc/itu/metadata.rb +16 -6
  26. data/lib/isodoc/itu/pdf_convert.rb +0 -13
  27. data/lib/isodoc/itu/presentation_xml_convert.rb +10 -0
  28. data/lib/isodoc/itu/ref.rb +46 -22
  29. data/lib/isodoc/itu/terms.rb +9 -22
  30. data/lib/isodoc/itu/word_convert.rb +10 -8
  31. data/lib/isodoc/itu/xref.rb +43 -12
  32. data/lib/metanorma/itu/processor.rb +11 -9
  33. data/lib/metanorma/itu/version.rb +1 -1
  34. data/metanorma-itu.gemspec +2 -2
  35. metadata +11 -12
  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)
@@ -21,19 +21,6 @@ module IsoDoc
21
21
  "itu.recommendation.xsl"
22
22
  end
23
23
  end
24
-
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
32
- end
33
- FileUtils.rm_rf dir
34
- ::Metanorma::Output::XslfoPdf.new.convert(
35
- filename, outname_html + ".pdf", File.join(@libdir, pdf_stylesheet(docxml)))
36
- end
37
24
  end
38
25
  end
39
26
  end
@@ -0,0 +1,10 @@
1
+ require_relative "base_convert"
2
+ require "isodoc"
3
+
4
+ module IsoDoc
5
+ module ITU
6
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
7
+ end
8
+ end
9
+ end
10
+
@@ -5,6 +5,7 @@ require "fileutils"
5
5
  module IsoDoc
6
6
  module ITU
7
7
  module BaseConvert
8
+ =begin
8
9
  def norm_ref(isoxml, out, num)
9
10
  q = "//bibliography/references[@normative = 'true']"
10
11
  f = isoxml.at(ns(q)) or return num
@@ -15,13 +16,17 @@ module IsoDoc
15
16
  end
16
17
  num
17
18
  end
19
+ =end
18
20
 
19
21
  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)
22
+ list.tr **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
23
+ id = render_identifier(bibitem_ref_code(b))
24
+ ref.td **{style: "vertical-align:top"} do |td|
25
+ td << (id[0] || "[#{id[1]}]")&.
26
+ gsub(/-/, "&#x2011;")&.gsub(/ /, "&#xa0;")
27
+ date_note_process(b, td)
28
+ end
29
+ ref.td { |td| reference_format(b, td) }
25
30
  end
26
31
  end
27
32
 
@@ -29,6 +34,36 @@ module IsoDoc
29
34
  nonstd_bibitem(list, b, ordinal, biblio)
30
35
  end
31
36
 
37
+ def biblio_list(f, div, biblio)
38
+ div.table **{ class: "biblio", border: "0" } do |t|
39
+ i = 0
40
+ t.tbody do |tbody|
41
+ f.elements.each do |b|
42
+ if b.name == "bibitem"
43
+ next if implicit_reference(b)
44
+ i += 1
45
+ nonstd_bibitem(tbody, b, i, biblio)
46
+ else
47
+ unless %w(title clause references).include? b.name
48
+ tbody.tx do |tx|
49
+ parse(b, tx)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ f.xpath(ns("./clause | ./references")).each do |x|
57
+ parse(x, div)
58
+ end
59
+ end
60
+
61
+ def bracket_if_num(x)
62
+ return nil if x.nil?
63
+ x = x.text.sub(/^\[/, "").sub(/\]$/, "")
64
+ "[#{x}]"
65
+ end
66
+
32
67
  def reference_format(b, r)
33
68
  reference_format_start(b, r)
34
69
  reference_format_title(b, r)
@@ -38,20 +73,13 @@ module IsoDoc
38
73
  s.gsub(/ |\_|\-/, " ").split(/ /).map(&:capitalize).join(" ")
39
74
  end
40
75
 
76
+ def pref_ref_code(b)
77
+ b.at(ns("./docidentifier[@type = 'ITU']")) || super
78
+ end
79
+
41
80
  IGNORE_IDS =
42
81
  "@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor'".freeze
43
82
 
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
83
  def multi_bibitem_ref_code(b)
56
84
  id = b.xpath(ns("./docidentifier[not(@type = 'metanorma' or #{IGNORE_IDS})]"))
57
85
  id.empty? and id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
@@ -59,7 +87,7 @@ module IsoDoc
59
87
  id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
60
88
  end
61
89
 
62
- def render_identifiers(ids)
90
+ def render_multi_identifiers(ids)
63
91
  ids.map do |id|
64
92
  id["type"] == "ITU" ? doctype_title(id) :
65
93
  docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
@@ -78,7 +106,7 @@ module IsoDoc
78
106
 
79
107
  def reference_format_start(b, r)
80
108
  id = multi_bibitem_ref_code(b)
81
- id1 = render_identifiers(id)
109
+ id1 = render_multi_identifiers(id)
82
110
  r << id1
83
111
  date = b.at(ns("./date[@type = 'published']")) and
84
112
  r << " (#{date.text.sub(/-.*$/, '')})"
@@ -96,10 +124,6 @@ module IsoDoc
96
124
  /\.$/.match(title&.text) or r << "."
97
125
  end
98
126
  end
99
-
100
- def format_ref(ref, prefix, isopub, date, allparts)
101
- docid_prefix(prefix, ref).sub(/^\[/, "").sub(/\]$/, "")
102
- end
103
127
  end
104
128
  end
105
129
  end
@@ -1,8 +1,8 @@
1
1
  module IsoDoc
2
2
  module ITU
3
3
  module BaseConvert
4
- def term_def_title(node)
5
- node
4
+ def term_def_title(node)
5
+ node
6
6
  end
7
7
 
8
8
  def terms_defs(node, out, num)
@@ -35,11 +35,11 @@ module IsoDoc
35
35
  def termdef_parse1(node, div, term, defn, source)
36
36
  div.p **{ class: "TermNum", id: node["id"] } do |p|
37
37
  p.b do |b|
38
- b << anchor(node["id"], :label)
38
+ b << @xrefs.anchor(node["id"], :label)
39
39
  insert_tab(b, 1)
40
40
  term.children.each { |n| parse(n, b) }
41
41
  end
42
- source and p << " [#{source.value}]"
42
+ source and p << " #{bracket_opt(source.value)}"
43
43
  p << ": "
44
44
  end
45
45
  defn and defn.children.each { |n| parse(n, div) }
@@ -60,24 +60,11 @@ module IsoDoc
60
60
  end
61
61
 
62
62
  def termnote_parse(node, out)
63
- out.div **{ class: "Note" } do |div|
64
- first = node.first_element_child
65
- div.p do |p|
66
- p << note_label(node) # "#{anchor(node['id'], :label) || '???'}: "
67
- para_then_remainder(first, node, p, div)
68
- end
69
- end
70
- end
71
-
72
- def termnote_anchor_names(docxml)
73
- docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
74
- c = IsoDoc::Function::XrefGen::Counter.new
75
- notes = t.xpath(ns(".//termnote"))
76
- notes.each do |n|
77
- return if n["id"].nil? || n["id"].empty?
78
- idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
79
- @anchors[n["id"]] = anchor_struct(idx, n, @note_xref_lbl,
80
- "termnote", false)
63
+ out.div **note_attrs(node) do |div|
64
+ first = node.first_element_child
65
+ div.p do |p|
66
+ p << note_label(node) # "#{@xrefs.anchor(node['id'], :label) || '???'}: "
67
+ para_then_remainder(first, node, p, div)
81
68
  end
82
69
  end
83
70
  end
@@ -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,21 +105,24 @@ 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
123
  insert_tab(div, 1)
121
124
  parse(node.at(ns("./stem")), div)
122
- lbl = anchor(node['id'], :label, false)
125
+ lbl = @xrefs.anchor(node['id'], :label, false)
123
126
  unless lbl.nil?
124
127
  insert_tab(div, 1)
125
128
  div << "(#{lbl})"
@@ -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)
@@ -4,14 +4,19 @@ require "fileutils"
4
4
 
5
5
  module IsoDoc
6
6
  module ITU
7
- module BaseConvert
7
+ class Xref < IsoDoc::Xref
8
+ def initialize(lang, script, klass, labels, options)
9
+ super
10
+ @hierarchical_assets = options[:hierarchical_assets]
11
+ end
12
+
8
13
  def annex_name_lbl(clause, num)
9
- lbl = clause["obligation"] == "informative" ? @appendix_lbl : @annex_lbl
14
+ lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
10
15
  l10n("<b>#{lbl} #{num}</b>")
11
16
  end
12
17
 
13
18
  def annex_names(clause, num)
14
- lbl = clause["obligation"] == "informative" ? @appendix_lbl : @annex_lbl
19
+ lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
15
20
  @anchors[clause["id"]] =
16
21
  { label: annex_name_lbl(clause, num), type: "clause",
17
22
  xref: "#{lbl} #{num}", level: 1 }
@@ -67,10 +72,6 @@ module IsoDoc
67
72
  termexample_anchor_names(d)
68
73
  end
69
74
 
70
- def hiersep
71
- "-"
72
- end
73
-
74
75
  MIDDLE_SECTIONS = "//clause[title = 'Scope'] | "\
75
76
  "//foreword | //introduction | //acknowledgements | "\
76
77
  "//references[@normative = 'true'] | "\
@@ -85,7 +86,7 @@ module IsoDoc
85
86
  end
86
87
 
87
88
  def sequential_figure_names(clause)
88
- c = IsoDoc::Function::XrefGen::Counter.new
89
+ c = IsoDoc::XrefGen::Counter.new
89
90
  j = 0
90
91
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).each do |t|
91
92
  if t.parent.name == "figure" then j += 1
@@ -96,12 +97,12 @@ module IsoDoc
96
97
  label = c.print + (j.zero? ? "" : "-#{(96 + j).chr.to_s}")
97
98
  next if t["id"].nil? || t["id"].empty?
98
99
  @anchors[t["id"]] =
99
- anchor_struct(label, nil, @figure_lbl, "figure", t["unnumbered"])
100
+ anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
100
101
  end
101
102
  end
102
103
 
103
104
  def hierarchical_figure_names(clause, num)
104
- c = IsoDoc::Function::XrefGen::Counter.new
105
+ c = IsoDoc::XrefGen::Counter.new
105
106
  j = 0
106
107
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).each do |t|
107
108
  if t.parent.name == "figure" then j += 1
@@ -112,7 +113,7 @@ module IsoDoc
112
113
  label = "#{num}#{hiersep}#{c.print}" +
113
114
  (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
114
115
  next if t["id"].nil? || t["id"].empty?
115
- @anchors[t["id"]] = anchor_struct(label, nil, @figure_lbl, "figure",
116
+ @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure",
116
117
  t["unnumbered"])
117
118
  end
118
119
  end
@@ -120,12 +121,42 @@ module IsoDoc
120
121
  def sequential_formula_names(clause)
121
122
  clause&.first&.xpath(ns(MIDDLE_SECTIONS))&.each do |c|
122
123
  if c["id"] && @anchors[c["id"]]
123
- hierarchical_formula_names(c, @anchors[c["id"]][:label] || @anchors[c["id"]][:xref] || "???")
124
+ hierarchical_formula_names(c, @anchors[c["id"]][:label] ||
125
+ @anchors[c["id"]][:xref] || "???")
124
126
  else
125
127
  hierarchical_formula_names(c, "???")
126
128
  end
127
129
  end
128
130
  end
131
+
132
+ def hierarchical_formula_names(clause, num)
133
+ c = IsoDoc::XrefGen::Counter.new
134
+ clause.xpath(ns(".//formula")).each do |t|
135
+ next if t["id"].nil? || t["id"].empty?
136
+ @anchors[t["id"]] =
137
+ anchor_struct("#{num}-#{c.increment(t).print}", nil,
138
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
139
+ "formula", t["unnumbered"])
140
+ end
141
+ end
142
+
143
+ def reference_names(ref)
144
+ super
145
+ @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
146
+ end
147
+
148
+ def termnote_anchor_names(docxml)
149
+ docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
150
+ c = IsoDoc::XrefGen::Counter.new
151
+ notes = t.xpath(ns(".//termnote"))
152
+ notes.each do |n|
153
+ return if n["id"].nil? || n["id"].empty?
154
+ idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
155
+ @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
156
+ "termnote", false)
157
+ end
158
+ end
159
+ end
129
160
  end
130
161
  end
131
162
  end
@@ -3,7 +3,11 @@ require "metanorma/processor"
3
3
  module Metanorma
4
4
  module ITU
5
5
  def self.fonts_used
6
- ["Arial", "Courier New", "Times New Roman"]
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
+ }
7
11
  end
8
12
 
9
13
  class Processor < Metanorma::Processor
@@ -26,18 +30,16 @@ module Metanorma
26
30
  "Metanorma::ITU #{Metanorma::ITU::VERSION}"
27
31
  end
28
32
 
29
- def input_to_isodoc(file, filename)
30
- Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
31
- end
32
-
33
- def output(isodoc_node, outname, format, options={})
33
+ def output(isodoc_node, inname, outname, format, options={})
34
34
  case format
35
35
  when :html
36
- IsoDoc::ITU::HtmlConvert.new(options).convert(outname, isodoc_node)
36
+ IsoDoc::ITU::HtmlConvert.new(options).convert(inname, isodoc_node, nil, outname)
37
37
  when :doc
38
- IsoDoc::ITU::WordConvert.new(options).convert(outname, isodoc_node)
38
+ IsoDoc::ITU::WordConvert.new(options).convert(inname, isodoc_node, nil, outname)
39
39
  when :pdf
40
- IsoDoc::ITU::PdfConvert.new(options).convert(outname, isodoc_node)
40
+ IsoDoc::ITU::PdfConvert.new(options).convert(inname, isodoc_node, nil, outname)
41
+ when :presentation
42
+ IsoDoc::ITU::PresentationXMLConvert.new(options).convert(inname, isodoc_node, nil, outname)
41
43
  else
42
44
  super
43
45
  end