metanorma-itu 1.0.11 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +10 -10
  3. data/.github/workflows/ubuntu.yml +25 -11
  4. data/.github/workflows/windows.yml +11 -12
  5. data/README.adoc +9 -49
  6. data/lib/asciidoctor/itu/biblio.rng +131 -46
  7. data/lib/asciidoctor/itu/cleanup.rb +90 -78
  8. data/lib/asciidoctor/itu/converter.rb +8 -12
  9. data/lib/asciidoctor/itu/front.rb +47 -18
  10. data/lib/asciidoctor/itu/isodoc.rng +32 -4
  11. data/lib/asciidoctor/itu/validate.rb +1 -1
  12. data/lib/isodoc/itu/base_convert.rb +9 -6
  13. data/lib/isodoc/itu/html/_coverpage.scss +1 -1
  14. data/lib/isodoc/itu/html/header.html +8 -8
  15. data/lib/isodoc/itu/html/html_itu_titlepage.html +5 -3
  16. data/lib/isodoc/itu/html/htmlstyle.scss +9 -5
  17. data/lib/isodoc/itu/html/itu.scss +24 -1
  18. data/lib/isodoc/itu/html/scripts.html +14 -27
  19. data/lib/isodoc/itu/html/word_itu_intro.html +2 -0
  20. data/lib/isodoc/itu/html/word_itu_titlepage.html +3 -3
  21. data/lib/isodoc/itu/html/wordstyle.scss +1 -1
  22. data/lib/isodoc/itu/html_convert.rb +3 -3
  23. data/lib/isodoc/itu/itu.recommendation-annex.xsl +3589 -0
  24. data/lib/isodoc/itu/itu.recommendation.xsl +3589 -0
  25. data/lib/isodoc/itu/itu.resolution.xsl +3589 -0
  26. data/lib/isodoc/itu/metadata.rb +6 -26
  27. data/lib/isodoc/itu/pdf_convert.rb +17 -44
  28. data/lib/isodoc/itu/ref.rb +26 -21
  29. data/lib/isodoc/itu/terms.rb +3 -4
  30. data/lib/isodoc/itu/word_convert.rb +5 -2
  31. data/lib/isodoc/itu/xref.rb +16 -12
  32. data/lib/metanorma/itu/processor.rb +8 -0
  33. data/lib/metanorma/itu/version.rb +1 -1
  34. metadata +5 -3
  35. data/lib/isodoc/itu/html/scripts.pdf.html +0 -72
@@ -3,9 +3,6 @@ module Asciidoctor
3
3
  class Converter < Standoc::Converter
4
4
  def sections_cleanup(x)
5
5
  super
6
- x.xpath("//*[@inline-header]").each do |h|
7
- h.delete("inline-header")
8
- end
9
6
  insert_missing_sections(x) unless @no_insert_missing_sections
10
7
  end
11
8
 
@@ -30,7 +27,7 @@ module Asciidoctor
30
27
  x.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
31
28
  "<sections><sentinel/></sections>"
32
29
  x.at("./*/sections/*") or x.at("./*/sections") << "<sentinel/>"
33
- ins = x.at("//sections").children.first
30
+ ins = x.at("//sections").elements.first
34
31
  unless x.at("//sections/clause/title[text() = 'Scope']")
35
32
  ins.previous = "<clause><title>Scope</title><p>"\
36
33
  "#{@labels['clause_empty']}</p></clause>"
@@ -39,73 +36,81 @@ module Asciidoctor
39
36
  end
40
37
 
41
38
  def insert_norm_ref(x)
42
- x.at("//bibliography") or x.at("./*/annex[last()] | ./*/sections").next =
39
+ x.at("//bibliography") or
40
+ x.at("./*/annex[last()] | ./*/sections").next =
43
41
  "<bibliography><sentinel/></bibliography>"
44
- ins = x.at("//bibliography").children.first
45
- unless x.at("//bibliography/references/title[text() = 'References']")
46
- ins.previous = "<references><title>References</title><p>"\
47
- "#{@labels['clause_empty']}</p></references>"
42
+ ins = x.at("//bibliography").elements.first
43
+ unless x.at("//bibliography/references[@normative = 'true']")
44
+ #ins.previous = "<references normative='true'><title>References</title><p>"\
45
+ # "#{@labels['clause_empty']}</p></references>"
46
+ ins.previous = "<references normative='true'><title>References</title>"\
47
+ "</references>"
48
48
  end
49
49
  x&.at("//sentinel")&.remove
50
50
  end
51
51
 
52
52
  def insert_terms(x)
53
- ins = x.at("//sections/clause/title[text() = 'Scope']")
54
- unless x.at("//sections/terms")
53
+ ins = x.at("//sections/clause/title[text() = 'Scope']/..")
54
+ unless x.at("//sections//terms")
55
55
  ins.next = "<terms><title>Definitions</title><p>"\
56
56
  "#{@labels['clause_empty']}</p></terms>"
57
57
  end
58
58
  end
59
59
 
60
60
  def insert_symbols(x)
61
- ins = x.at("//terms")
61
+ ins = x.at("//sections/terms") ||
62
+ x.at("//sections/clause[descendant::terms]")
62
63
  unless x.at("//sections//definitions")
63
- ins.next = "<definitions><title>Definitions</title><p>"\
64
+ ins.next = "<definitions><title>Abbreviations and acronyms</title><p>"\
64
65
  "#{@labels['clause_empty']}</p></definitions>"
65
66
  end
66
67
  end
67
68
 
68
69
  def insert_conventions(x)
69
- ins = x.at("//sections//definitions")
70
+ ins = x.at("//sections//definitions") ||
71
+ x.at("//sections/clause[descendant::definitions]")
70
72
  unless x.at("//sections/clause/title[text() = 'Conventions']")
71
- ins.next = "<clause><title>Conventions</title><p>"\
72
- "#{@labels['clause_empty']}</p></clause>"
73
- end
74
- end
73
+ ins.next = "<clause id='_#{UUIDTools::UUID.random_create}'>"\
74
+ "<title>Conventions</title><p>"\
75
+ "#{@labels['clause_empty']}</p></clause>"
76
+ end
77
+ end
75
78
 
76
- def cleanup(xmldoc)
77
- symbols_cleanup(xmldoc)
78
- super
79
- end
79
+ def cleanup(xmldoc)
80
+ symbols_cleanup(xmldoc)
81
+ super
82
+ obligations_cleanup(xmldoc)
83
+ xmldoc
84
+ end
80
85
 
81
- def smartquotes_cleanup(xmldoc)
82
- return super if @smartquotes
83
- xmldoc.traverse do |n|
86
+ def smartquotes_cleanup(xmldoc)
87
+ return super if @smartquotes
88
+ xmldoc.traverse do |n|
84
89
  next unless n.text?
85
90
  n.replace(HTMLEntities.new.encode(
86
91
  n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'").
87
92
  gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic))
88
- end
89
- xmldoc
90
- end
93
+ end
94
+ xmldoc
95
+ end
91
96
 
92
- def termdef_cleanup(xmldoc)
93
- xmldoc.xpath("//term/preferred").each do |p|
97
+ def termdef_cleanup(xmldoc)
98
+ xmldoc.xpath("//term/preferred").each do |p|
94
99
  if ["terms defined elsewhere",
95
- "terms defined in this recommendation"].include? p.text.downcase
96
- p.name = "title"
97
- p.parent.name = "terms"
100
+ "terms defined in this recommendation"].include? p.text.downcase
101
+ p.name = "title"
102
+ p.parent.name = "terms"
103
+ end
104
+ end
105
+ super
98
106
  end
99
- end
100
- super
101
- end
102
107
 
103
- def termdef_boilerplate_cleanup(xmldoc)
104
- end
108
+ def termdef_boilerplate_cleanup(xmldoc)
109
+ end
105
110
 
106
- def symbols_cleanup(xmldoc)
107
- sym = xmldoc.at("//definitions/title")
108
- sym and sym&.next_element&.name == "dl" and
111
+ def symbols_cleanup(xmldoc)
112
+ sym = xmldoc.at("//definitions/title")
113
+ sym and sym&.next_element&.name == "dl" and
109
114
  sym.next = "<p>#{@symbols_boilerplate}</p>"
110
115
  end
111
116
 
@@ -113,48 +118,55 @@ module Asciidoctor
113
118
 
114
119
  def pub_class(bib)
115
120
  return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ITU']")
116
- return 1 if bib.at("#{PUBLISHER}[name = 'International "\
117
- "Telecommunication Union']")
118
- return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
119
- return 2 if bib.at("#{PUBLISHER}[name = 'International Organization "\
120
- "for Standardization']")
121
- return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
122
- return 3 if bib.at("#{PUBLISHER}[name = 'International "\
123
- "Electrotechnical Commission']")
124
- return 4 if bib.at("./docidentifier[@type][not(@type = 'DOI' or "\
125
- "@type = 'metanorma' or @type = 'ISSN' or @type = "\
126
- "'ISBN')]")
127
- 5
128
- end
121
+ return 1 if bib.at("#{PUBLISHER}[name = 'International "\
122
+ "Telecommunication Union']")
123
+ return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
124
+ return 2 if bib.at("#{PUBLISHER}[name = 'International Organization "\
125
+ "for Standardization']")
126
+ return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
127
+ return 3 if bib.at("#{PUBLISHER}[name = 'International "\
128
+ "Electrotechnical Commission']")
129
+ return 4 if bib.at("./docidentifier[@type][not(@type = 'DOI' or "\
130
+ "@type = 'metanorma' or @type = 'ISSN' or @type = "\
131
+ "'ISBN')]")
132
+ 5
133
+ end
129
134
 
130
- def sort_biblio(bib)
131
- bib.sort do |a, b|
132
- sort_biblio_key(a) <=> sort_biblio_key(b)
135
+ def sort_biblio(bib)
136
+ bib.sort do |a, b|
137
+ sort_biblio_key(a) <=> sort_biblio_key(b)
138
+ end
133
139
  end
134
- end
135
140
 
136
- # sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other
137
- # then standard class (docid class other than DOI &c)
138
- # then alphanumeric doc id (not DOI &c)
139
- # then title
140
- def sort_biblio_key(bib)
141
- pubclass = pub_class(bib)
142
- num = bib&.at("./docnumber")&.text
143
- id = bib&.at("./docidentifier[not(@type = 'DOI' or @type = "\
144
- "'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")
145
- metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
146
- abbrid = metaid unless /^\[\d+\]$/.match(metaid)
147
- type = id['type'] if id
148
- title = bib&.at("./title[@type = 'main']")&.text ||
149
- bib&.at("./title")&.text || bib&.at("./formattedref")&.text
150
- "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{title}"
151
- end
141
+ # sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other
142
+ # then standard class (docid class other than DOI &c)
143
+ # then alphanumeric doc id (not DOI &c)
144
+ # then title
145
+ def sort_biblio_key(bib)
146
+ pubclass = pub_class(bib)
147
+ num = bib&.at("./docnumber")&.text
148
+ id = bib&.at("./docidentifier[not(@type = 'DOI' or @type = "\
149
+ "'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")
150
+ metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
151
+ abbrid = metaid unless /^\[\d+\]$/.match(metaid)
152
+ type = id['type'] if id
153
+ title = bib&.at("./title[@type = 'main']")&.text ||
154
+ bib&.at("./title")&.text || bib&.at("./formattedref")&.text
155
+ "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{title}"
156
+ end
157
+
158
+ def biblio_reorder(xmldoc)
159
+ xmldoc.xpath("//references").each do |r|
160
+ biblio_reorder1(r)
161
+ end
162
+ end
152
163
 
153
- def biblio_reorder(xmldoc)
154
- xmldoc.xpath("//references").each do |r|
155
- biblio_reorder1(r)
164
+ def normref_cleanup(xmldoc)
165
+ super
166
+ r = xmldoc.at(NORM_REF) || return
167
+ title = r.at("./title") and
168
+ title.content = "References"
156
169
  end
157
170
  end
158
171
  end
159
172
  end
160
- end
@@ -65,7 +65,7 @@ module Asciidoctor
65
65
  word_converter(node).convert filename unless node.attr("nodoc")
66
66
  pdf_converter(node).convert filename unless node.attr("nodoc")
67
67
  end
68
- @log.write(@filename + ".err") unless @novalid
68
+ @log.write(@localdir + @filename + ".err") unless @novalid
69
69
  @files_to_delete.each { |f| FileUtils.rm f }
70
70
  ret
71
71
  end
@@ -90,15 +90,6 @@ module Asciidoctor
90
90
  end
91
91
  end
92
92
 
93
- def norm_ref_parse(attrs, xml, node)
94
- @norm_ref = true
95
- xml.references **attr_code(attrs) do |xml_section|
96
- xml_section.title { |t| t << "References" }
97
- xml_section << node.content
98
- end
99
- @norm_ref = false
100
- end
101
-
102
93
  def term_def_title(toplevel, node)
103
94
  return node.title unless toplevel
104
95
  "Definitions"
@@ -131,8 +122,6 @@ module Asciidoctor
131
122
  div.next = "<p>#{@term_def_boilerplate}</p>"
132
123
  end
133
124
 
134
- NORM_REF = "//bibliography/references[title = 'References']".freeze
135
-
136
125
  def load_yaml(lang, script)
137
126
  y = if @i18nyaml then YAML.load_file(@i18nyaml)
138
127
  elsif lang == "en"
@@ -148,6 +137,13 @@ module Asciidoctor
148
137
  super
149
138
  end
150
139
 
140
+ def metadata_keywords(node, xml)
141
+ return unless node.attr("keywords")
142
+ node.attr("keywords").split(/,[ ]*/).sort.each_with_index do |kw, i|
143
+ xml.keyword (i == 0 ? kw.capitalize : kw)
144
+ end
145
+ end
146
+
151
147
  def html_extract_attributes(node)
152
148
  super.merge(hierarchical_assets: node.attr("hierarchical-object-numbering"))
153
149
  end
@@ -4,36 +4,63 @@ require "fileutils"
4
4
 
5
5
  module Asciidoctor
6
6
  module ITU
7
-
8
- # A {Converter} implementation that generates RSD output, and a document
9
- # schema encapsulation of the document for validation
10
- #
11
7
  class Converter < Standoc::Converter
12
8
  def metadata_status(node, xml)
13
9
  xml.status do |s|
14
10
  s.stage (node.attributes.has_key?("draft") ? "draft" :
15
- (node.attr("status") || node.attr("docstage") || "published" ))
11
+ (node.attr("status") || node.attr("docstage") ||
12
+ "published" ))
16
13
  end
17
14
  end
18
15
 
19
16
  def title_english(node, xml)
20
- ["en"].each do |lang|
21
- at = { language: lang, format: "text/plain", type: "main" }
22
- a = node.attr("title") || node.attr("title-en") || node.title
23
- xml.title Asciidoctor::Standoc::Utils::asciidoc_sub(a), **attr_code(at)
24
- if a = node.attr("annextitle") || node.attr("annextitle-en")
25
- at[:type] = "annex"
26
- xml.title Asciidoctor::Standoc::Utils::asciidoc_sub(a), **attr_code(at)
17
+ at = { language: "en", format: "text/plain", type: "main" }
18
+ a = node.attr("title") || node.attr("title-en")
19
+ xml.title **attr_code(at) do |t|
20
+ t << (Asciidoctor::Standoc::Utils::asciidoc_sub(a) || node.title)
21
+ end
22
+ if a = node.attr("annextitle") || node.attr("annextitle-en")
23
+ at[:type] = "annex"
24
+ xml.title **attr_code(at) do |t|
25
+ t << Asciidoctor::Standoc::Utils::asciidoc_sub(a)
27
26
  end
28
27
  end
29
28
  end
30
29
 
31
30
  def title_otherlangs(node, xml)
32
31
  node.attributes.each do |k, v|
33
- next unless /^(annex)?title-(?<titlelang>.+)$/ =~ k
34
- next if titlelang == "en"
35
- xml.title v, { language: titlelang, format: "text/plain",
36
- type: /^annex/.match(k) ? "annex" : "main" }
32
+ next unless /^(annex)?title-(?<lang>.+)$/ =~ k
33
+ next if lang == "en"
34
+ type = /^annex/.match(k) ? "annex" : "main"
35
+ xml.title **attr_code(language: lang, format: "text/plain",
36
+ type: type) do |t|
37
+ t << v
38
+ end
39
+ end
40
+ end
41
+
42
+ def title(node, xml)
43
+ super
44
+ subtitle_english(node, xml)
45
+ subtitle_otherlangs(node, xml)
46
+ end
47
+
48
+ def subtitle_english(node, xml)
49
+ at = { language: "en", format: "text/plain", type: "subtitle" }
50
+ a = node.attr("subtitle") || node.attr("subtitle-en")
51
+ xml.title **attr_code(at) do |t|
52
+ t << Asciidoctor::Standoc::Utils::asciidoc_sub(a)
53
+ end
54
+ end
55
+
56
+ def subtitle_otherlangs(node, xml)
57
+ node.attributes.each do |k, v|
58
+ next unless /^subtitle-(?<lang>.+)$/ =~ k
59
+ next if lang == "en"
60
+ xml.title **attr_code(language: lang, format: "text/plain",
61
+ type: "subtitle") do |t|
62
+ t << v
63
+ end
37
64
  end
38
65
  end
39
66
 
@@ -89,11 +116,13 @@ module Asciidoctor
89
116
 
90
117
  def metadata_committee2(node, g, suffix, prefix)
91
118
  g.name node.attr("#{prefix}group#{suffix}")
92
- g.acronym node.attr("#{prefix}groupacronym#{suffix}") if node.attr("#{prefix}groupacronym#{suffix}")
119
+ node.attr("#{prefix}groupacronym#{suffix}") and
120
+ g.acronym node.attr("#{prefix}groupacronym#{suffix}")
93
121
  if node.attr("#{prefix}groupyearstart#{suffix}")
94
122
  g.period do |p|
95
123
  p.start node.attr("#{prefix}groupyearstart#{suffix}")
96
- p.end node.attr("#{prefix}groupyearend#{suffix}") if node.attr("#{prefix}groupacronym#{suffix}")
124
+ node.attr("#{prefix}groupacronym#{suffix}") and
125
+ p.end node.attr("#{prefix}groupyearend#{suffix}")
97
126
  end
98
127
  end
99
128
  end
@@ -101,9 +101,7 @@
101
101
  <ref name="structuredidentifier"/>
102
102
  </zeroOrMore>
103
103
  </define>
104
- <define name="TitleType">
105
- <text/>
106
- </define>
104
+ <!-- TitleType = text -->
107
105
  <define name="sections">
108
106
  <element name="sections">
109
107
  <oneOrMore>
@@ -131,6 +129,9 @@
131
129
  </choice>
132
130
  </attribute>
133
131
  </optional>
132
+ <attribute name="normative">
133
+ <data type="boolean"/>
134
+ </attribute>
134
135
  <optional>
135
136
  <ref name="section-title"/>
136
137
  </optional>
@@ -307,6 +308,21 @@
307
308
  </define>
308
309
  </include>
309
310
  <!-- end overrides -->
311
+ <define name="TextElement" combine="choice">
312
+ <ref name="concept"/>
313
+ </define>
314
+ <define name="concept">
315
+ <element name="concept">
316
+ <optional>
317
+ <attribute name="term"/>
318
+ </optional>
319
+ <choice>
320
+ <ref name="eref"/>
321
+ <ref name="xref"/>
322
+ <ref name="termref"/>
323
+ </choice>
324
+ </element>
325
+ </define>
310
326
  <define name="BasicBlock" combine="choice">
311
327
  <choice>
312
328
  <ref name="requirement"/>
@@ -913,7 +929,10 @@
913
929
  </define>
914
930
  <define name="origin">
915
931
  <element name="origin">
916
- <ref name="erefType"/>
932
+ <choice>
933
+ <ref name="erefType"/>
934
+ <ref name="termref"/>
935
+ </choice>
917
936
  </element>
918
937
  </define>
919
938
  <define name="modification">
@@ -921,6 +940,15 @@
921
940
  <ref name="paragraph"/>
922
941
  </element>
923
942
  </define>
943
+ <define name="termref">
944
+ <element name="termref">
945
+ <attribute name="base"/>
946
+ <attribute name="target"/>
947
+ <optional>
948
+ <text/>
949
+ </optional>
950
+ </element>
951
+ </define>
924
952
  <define name="structuredidentifier">
925
953
  <element name="structuredidentifier">
926
954
  <optional>
@@ -45,7 +45,7 @@ module Asciidoctor
45
45
  def extract_text(node)
46
46
  return "" if node.nil?
47
47
  node1 = Nokogiri::XML.fragment(node.to_s)
48
- node1.xpath("//link | //locality").each(&:remove)
48
+ node1.xpath("//link | //locality | //localityStack").each(&:remove)
49
49
  ret = ""
50
50
  node1.traverse { |x| ret += x.text if x.text? }
51
51
  ret