metanorma-iso 1.3.20 → 1.3.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +10 -10
  3. data/.github/workflows/ubuntu.yml +11 -11
  4. data/.github/workflows/windows.yml +11 -12
  5. data/Gemfile +2 -0
  6. data/README.adoc +3 -2
  7. data/lib/asciidoctor/iso/base.rb +17 -1
  8. data/lib/asciidoctor/iso/biblio.rng +131 -46
  9. data/lib/asciidoctor/iso/cleanup.rb +19 -2
  10. data/lib/asciidoctor/iso/front.rb +116 -17
  11. data/lib/asciidoctor/iso/isodoc.rng +32 -4
  12. data/lib/asciidoctor/iso/isostandard-amd.rng +98 -0
  13. data/lib/asciidoctor/iso/isostandard.rng +10 -0
  14. data/lib/asciidoctor/iso/macros.rb +21 -0
  15. data/lib/asciidoctor/iso/section.rb +18 -32
  16. data/lib/asciidoctor/iso/term_lookup_cleanup.rb +90 -0
  17. data/lib/asciidoctor/iso/validate.rb +41 -21
  18. data/lib/asciidoctor/iso/validate_section.rb +2 -2
  19. data/lib/asciidoctor/iso/validate_style.rb +1 -1
  20. data/lib/isodoc/iso/base_convert.rb +57 -41
  21. data/lib/isodoc/iso/html/header.html +5 -5
  22. data/lib/isodoc/iso/html/html_iso_titlepage.html +18 -18
  23. data/lib/isodoc/iso/html/isodoc.scss +28 -28
  24. data/lib/isodoc/iso/html/scripts.html +23 -21
  25. data/lib/isodoc/iso/html/style-human.scss +259 -423
  26. data/lib/isodoc/iso/html/style-iso.scss +151 -382
  27. data/lib/isodoc/iso/html/word_iso_titlepage.html +23 -2
  28. data/lib/isodoc/iso/html/wordstyle.scss +66 -39
  29. data/lib/isodoc/iso/html_convert.rb +7 -9
  30. data/lib/isodoc/iso/iso.international-standard.xsl +4386 -0
  31. data/lib/isodoc/iso/metadata.rb +48 -22
  32. data/lib/isodoc/iso/pdf_convert.rb +32 -0
  33. data/lib/metanorma-iso.rb +1 -0
  34. data/lib/metanorma/iso/processor.rb +13 -1
  35. data/lib/metanorma/iso/version.rb +1 -1
  36. data/spec/asciidoctor-iso/amd_spec.rb +318 -0
  37. data/spec/asciidoctor-iso/base_spec.rb +37 -17
  38. data/spec/asciidoctor-iso/blocks_spec.rb +21 -9
  39. data/spec/asciidoctor-iso/cleanup_spec.rb +203 -175
  40. data/spec/asciidoctor-iso/inline_spec.rb +2 -1
  41. data/spec/asciidoctor-iso/macros_spec.rb +273 -0
  42. data/spec/asciidoctor-iso/refs_spec.rb +7 -4
  43. data/spec/asciidoctor-iso/section_spec.rb +8 -8
  44. data/spec/asciidoctor-iso/validate_spec.rb +1 -1
  45. data/spec/assets/iso.xml +64 -1
  46. data/spec/isodoc/blocks_spec.rb +115 -0
  47. data/spec/isodoc/i18n_spec.rb +12 -20
  48. data/spec/isodoc/inline_spec.rb +2 -2
  49. data/spec/isodoc/iso_spec.rb +1 -1
  50. data/spec/isodoc/metadata_spec.rb +13 -4
  51. data/spec/isodoc/postproc_spec.rb +13 -112
  52. data/spec/isodoc/ref_spec.rb +4 -4
  53. data/spec/isodoc/section_spec.rb +8 -12
  54. data/spec/isodoc/table_spec.rb +24 -24
  55. data/spec/isodoc/terms_spec.rb +2 -2
  56. data/spec/isodoc/xref_spec.rb +19 -19
  57. data/spec/metanorma/processor_spec.rb +2 -2
  58. data/spec/spec_helper.rb +13 -1
  59. metadata +9 -3
  60. data/asciidoctor-iso.gemspec.old +0 -50
@@ -5,6 +5,7 @@ require "json"
5
5
  require "pathname"
6
6
  require "open-uri"
7
7
  require "pp"
8
+ require "asciidoctor/iso/term_lookup_cleanup"
8
9
 
9
10
  module Asciidoctor
10
11
  module ISO
@@ -13,12 +14,12 @@ module Asciidoctor
13
14
  "//clause[title = 'Scope']//fn".freeze
14
15
 
15
16
  NORMREF_FOOTNOTES =
16
- "//references[title = 'Normative References']//fn".freeze
17
+ "//references[@normative = 'true']//fn".freeze
17
18
 
18
19
  POST_NORMREF_FOOTNOTES =
19
20
  "//sections//clause[not(title = 'Scope')]//fn | "\
20
21
  "//annex//fn | "\
21
- "//references[title = 'Bibliography']//fn".freeze
22
+ "//references[@normative = 'false']//fn".freeze
22
23
 
23
24
  def other_footnote_renumber(xmldoc)
24
25
  seen = {}
@@ -35,6 +36,7 @@ module Asciidoctor
35
36
  end
36
37
 
37
38
  def id_prefix(prefix, id)
39
+ return id.text if @amd # we're just inheriting the prefixes from parent doc
38
40
  prefix.join("/") + ( id.text.match(%{^/}) ? "" : " " ) + id.text
39
41
  end
40
42
 
@@ -57,6 +59,8 @@ module Asciidoctor
57
59
  id.content = id_prefix(prefix, id)
58
60
  id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-with-lang']") and
59
61
  id.content = id_prefix(prefix, id)
62
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-reference']") and
63
+ id.content = id_prefix(prefix, id)
60
64
  end
61
65
 
62
66
  def format_ref(ref, type, isopub)
@@ -86,6 +90,11 @@ module Asciidoctor
86
90
  end
87
91
  end
88
92
 
93
+ def termdef_cleanup(xmldoc)
94
+ Asciidoctor::ISO::TermLookupCleanup.new(xmldoc, @log).call
95
+ super
96
+ end
97
+
89
98
  # TODO sort by authors
90
99
  # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
91
100
  # then standard class (docid class other than DOI &c)
@@ -108,6 +117,14 @@ module Asciidoctor
108
117
  "#{num.nil? ? abbrid : sprintf("%09d", num.to_i)} :: "\
109
118
  "#{partid} :: #{id&.text} :: #{title}"
110
119
  end
120
+
121
+ def sections_cleanup(x)
122
+ super
123
+ return unless @amd
124
+ x.xpath("//*[@inline-header]").each do |h|
125
+ h.delete('inline-header')
126
+ end
127
+ end
111
128
  end
112
129
  end
113
130
  end
@@ -9,6 +9,49 @@ require "pp"
9
9
  module Asciidoctor
10
10
  module ISO
11
11
  class Converter < Standoc::Converter
12
+ STAGE_ABBRS = {
13
+ "00": "PWI",
14
+ "10": "NWIP",
15
+ "20": "WD",
16
+ "30": "CD",
17
+ "40": "DIS",
18
+ "50": "FDIS",
19
+ "60": "IS",
20
+ "90": "(Review)",
21
+ "95": "(Withdrawal)",
22
+ }.freeze
23
+
24
+ STAGE_NAMES = {
25
+ "00": "Preliminary work item",
26
+ "10": "New work item proposal",
27
+ "20": "Working draft",
28
+ "30": "Committee draft",
29
+ "40": "Draft international standard",
30
+ "50": "Final draft international standard",
31
+ "60": "International standard",
32
+ "90": "Review",
33
+ "95": "Withdrawal",
34
+ }.freeze
35
+
36
+ def stage_abbr(stage, substage, doctype)
37
+ return nil if stage.to_i > 60
38
+ return "PRF" if stage == "60" && substage == "00"
39
+ ret = STAGE_ABBRS[stage.to_sym]
40
+ ret = "DTS" if ret == "DIS" && %w(technical-report technical-specification).include?(doctype)
41
+ ret = "FDTS" if ret == "FDIS" && %w(technical-report technical-specification).include?(doctype)
42
+ ret
43
+ end
44
+
45
+ def stage_name(stage, substage, doctype)
46
+ return "Proof" if stage == "60" && substage == "00"
47
+ ret = STAGE_NAMES[stage.to_sym]
48
+ if %w(technical-report technical-specification).include? doctype
49
+ ret = "Draft technical standard" if ret == "Draft international standard"
50
+ ret = "Final draft technical standard" if ret == "Final draft international standard"
51
+ end
52
+ ret
53
+ end
54
+
12
55
  def metadata_id(node, xml)
13
56
  iso_id(node, xml)
14
57
  node&.attr("tc-docnumber")&.split(/,\s*/)&.each do |n|
@@ -18,12 +61,34 @@ module Asciidoctor
18
61
  end
19
62
 
20
63
  def iso_id(node, xml)
21
- return unless node.attr("docnumber")
22
- part, subpart = node&.attr("partnumber")&.split(/-/)
23
- dn = add_id_parts(node.attr("docnumber"), part, subpart)
24
- dn = id_stage_prefix(dn, node)
25
- xml.docidentifier dn, **attr_code(type: "iso")
26
- xml.docidentifier id_langsuffix(dn, node), **attr_code(type: "iso-with-lang")
64
+ return unless !@amd && node.attr("docnumber") || @amd && node.attr("updates")
65
+ dn = iso_id1(node)
66
+ dn1 = id_stage_prefix(dn, node, false)
67
+ dn2 = id_stage_prefix(dn, node, true)
68
+ xml.docidentifier dn1, **attr_code(type: "iso")
69
+ xml.docidentifier id_langsuffix(dn1, node), **attr_code(type: "iso-with-lang")
70
+ xml.docidentifier id_langsuffix(dn2, node), **attr_code(type: "iso-reference")
71
+ end
72
+
73
+ def iso_id1(node)
74
+ if @amd
75
+ dn = node.attr("updates")
76
+ return add_amd_parts(dn, node)
77
+ else
78
+ part, subpart = node&.attr("partnumber")&.split(/-/)
79
+ dn = add_id_parts(node.attr("docnumber"), part, subpart)
80
+ end
81
+ end
82
+
83
+ def add_amd_parts(dn, node)
84
+ a = node.attr("amendment-number")
85
+ c = node.attr("corrigendum-number")
86
+ case node.attr("doctype")
87
+ when "amendment"
88
+ "#{dn}/Amd.#{node.attr('amendment-number')}"
89
+ when "technical corrigendum"
90
+ "#{dn}/Cor.#{node.attr('corrigendum-number')}"
91
+ end
27
92
  end
28
93
 
29
94
  def id_langsuffix(dn, node)
@@ -34,12 +99,15 @@ module Asciidoctor
34
99
  else
35
100
  "(X)"
36
101
  end
37
- "#{dn} #{suffix}"
102
+ "#{dn}#{suffix}"
38
103
  end
39
104
 
40
105
  def metadata_ext(node, xml)
41
106
  super
42
107
  structured_id(node, xml)
108
+ xml.stagename stage_name(get_stage(node), get_substage(node), node.attr("doctype"))
109
+ @amd && a = node.attr("updates-document-type") and
110
+ xml.updates_document_type a
43
111
  end
44
112
 
45
113
  def structured_id(node, xml)
@@ -47,7 +115,8 @@ module Asciidoctor
47
115
  part, subpart = node&.attr("partnumber")&.split(/-/)
48
116
  xml.structuredidentifier do |i|
49
117
  i.project_number node.attr("docnumber"),
50
- **attr_code(part: part, subpart: subpart)
118
+ **attr_code(part: part, subpart: subpart, amendment: node.attr("amendment-number"),
119
+ corrigendum: node.attr("corrigendum-number"), origyr: node.attr("created-date"))
51
120
  end
52
121
  end
53
122
 
@@ -59,18 +128,27 @@ module Asciidoctor
59
128
 
60
129
  def id_stage_abbr(stage, substage, node)
61
130
  IsoDoc::Iso::Metadata.new("en", "Latn", {}).
62
- status_abbrev(stage, substage, node.attr("iteration"),
63
- node.attr("draft"))
131
+ status_abbrev(stage_abbr(stage, substage, node.attr("doctype")),
132
+ substage, node.attr("iteration"),
133
+ node.attr("draft"), node.attr("doctype"))
64
134
  end
65
135
 
66
- def id_stage_prefix(dn, node)
136
+ def id_stage_prefix(dn, node, force_year)
67
137
  stage = get_stage(node)
68
138
  substage = get_substage(node)
69
- if stage && (stage.to_i < 60 || stage.to_i == 60 && substage.to_i < 60)
139
+ typeabbr = get_typeabbr(node)
140
+ if stage && (stage.to_i < 60)
70
141
  abbr = id_stage_abbr(stage, substage, node)
71
- dn = "/#{abbr} #{dn}" unless abbr.nil? || abbr.empty? # prefixes added in cleanup
72
- else
73
- dn += ":#{node.attr("copyright-year")}" if node.attr("copyright-year")
142
+ unless abbr.nil? || abbr.empty? # prefixes added in cleanup
143
+ dn = @amd ? dn.sub(/ /, "/#{abbr} ") : "/#{abbr} #{typeabbr}#{dn}"
144
+ end
145
+ elsif typeabbr && !@amd
146
+ dn = "/#{typeabbr}#{dn}"
147
+ end
148
+ if force_year || !(stage && (stage.to_i < 60))
149
+ year = @amd ? (node.attr("copyright-year") || node.attr("updated-date").sub(/-.*$/, "")) :
150
+ node.attr("copyright-year")
151
+ dn += ":#{year}" if year
74
152
  end
75
153
  dn
76
154
  end
@@ -130,10 +208,21 @@ module Asciidoctor
130
208
  node.attr("docsubstage") || ( stage == "60" ? "60" : "00" )
131
209
  end
132
210
 
211
+ def get_typeabbr(node)
212
+ case node.attr("doctype")
213
+ when "technical-report" then "TR "
214
+ when "technical-specification" then "TS "
215
+ else
216
+ nil
217
+ end
218
+ end
219
+
133
220
  def metadata_status(node, xml)
221
+ stage = get_stage(node)
222
+ substage = get_substage(node)
134
223
  xml.status do |s|
135
- s.stage get_stage(node)
136
- s.substage get_substage(node)
224
+ s.stage stage, **attr_code(abbreviation: stage_abbr(stage, substage, node.attr("doctype")))
225
+ s.substage substage
137
226
  node.attr("iteration") && (s.iteration node.attr("iteration"))
138
227
  end
139
228
  end
@@ -167,12 +256,21 @@ module Asciidoctor
167
256
  end
168
257
  end
169
258
 
259
+ def title_amd(node, t, lang, at)
260
+ return unless node.attr("title-amendment-#{lang}")
261
+ t.title(**attr_code(at.merge(type: "title-amd"))) do |t1|
262
+ t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(node.attr("title-amendment-#{lang}"))
263
+ end
264
+ end
265
+
170
266
  def title_full(node, t, lang, at)
171
267
  title = node.attr("title-main-#{lang}")
172
268
  intro = node.attr("title-intro-#{lang}")
173
269
  part = node.attr("title-part-#{lang}")
270
+ amd = node.attr("title-amendment-#{lang}")
174
271
  title = "#{intro} -- #{title}" if intro
175
272
  title = "#{title} -- #{part}" if part
273
+ title = "#{title} -- #{amd}" if amd && @amd
176
274
  t.title **attr_code(at.merge(type: "main")) do |t1|
177
275
  t1 << Asciidoctor::Standoc::Utils::asciidoc_sub(title)
178
276
  end
@@ -185,6 +283,7 @@ module Asciidoctor
185
283
  title_intro(node, xml, lang, at)
186
284
  title_main(node, xml, lang, at)
187
285
  title_part(node, xml, lang, at)
286
+ title_amd(node, xml, lang, at) if @amd
188
287
  end
189
288
  end
190
289
  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>
@@ -0,0 +1,98 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar ns="https://www.metanorma.org/ns/iso" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
3
+ <!-- default namespace isostandard = "https://www.metanorma.com/ns/iso" -->
4
+ <include href="isostandard.rng">
5
+ <start>
6
+ <ref name="iso-standard"/>
7
+ </start>
8
+ <define name="sections">
9
+ <element name="sections">
10
+ <oneOrMore>
11
+ <ref name="clause"/>
12
+ </oneOrMore>
13
+ </element>
14
+ </define>
15
+ <define name="clause">
16
+ <element name="clause">
17
+ <optional>
18
+ <attribute name="type"/>
19
+ </optional>
20
+ <optional>
21
+ <attribute name="change">
22
+ <choice>
23
+ <value>add</value>
24
+ <value>delete</value>
25
+ <value>modify</value>
26
+ </choice>
27
+ </attribute>
28
+ </optional>
29
+ <optional>
30
+ <attribute name="locality"/>
31
+ </optional>
32
+ <ref name="Clause-Section"/>
33
+ </element>
34
+ </define>
35
+ <define name="iso-standard">
36
+ <element name="iso-standard">
37
+ <ref name="bibdata"/>
38
+ <optional>
39
+ <ref name="boilerplate"/>
40
+ </optional>
41
+ <ref name="preface"/>
42
+ <oneOrMore>
43
+ <ref name="sections"/>
44
+ </oneOrMore>
45
+ </element>
46
+ </define>
47
+ <define name="documentnumber">
48
+ <element name="project-number">
49
+ <optional>
50
+ <attribute name="part">
51
+ <data type="int"/>
52
+ </attribute>
53
+ </optional>
54
+ <optional>
55
+ <attribute name="subpart">
56
+ <data type="int"/>
57
+ </attribute>
58
+ </optional>
59
+ <optional>
60
+ <attribute name="amendment">
61
+ <data type="int"/>
62
+ </attribute>
63
+ </optional>
64
+ <optional>
65
+ <attribute name="corrigendum">
66
+ <data type="int"/>
67
+ </attribute>
68
+ </optional>
69
+ <optional>
70
+ <attribute name="origyr">
71
+ <data type="int"/>
72
+ </attribute>
73
+ </optional>
74
+ <text/>
75
+ </element>
76
+ </define>
77
+ <define name="BibDataExtensionType">
78
+ <ref name="doctype"/>
79
+ <ref name="editorialgroup"/>
80
+ <zeroOrMore>
81
+ <ref name="ics"/>
82
+ </zeroOrMore>
83
+ <ref name="structuredidentifier"/>
84
+ <optional>
85
+ <ref name="stagename"/>
86
+ </optional>
87
+ <optional>
88
+ <ref name="updates_document_type"/>
89
+ </optional>
90
+ </define>
91
+ </include>
92
+ <!-- end overrides -->
93
+ <define name="updates_document_type">
94
+ <element name="updates-document-type">
95
+ <ref name="DocumentType"/>
96
+ </element>
97
+ </define>
98
+ </grammar>
@@ -43,6 +43,9 @@
43
43
  <ref name="ics"/>
44
44
  </zeroOrMore>
45
45
  <ref name="structuredidentifier"/>
46
+ <optional>
47
+ <ref name="stagename"/>
48
+ </optional>
46
49
  </define>
47
50
  <define name="bdate">
48
51
  <element name="date">
@@ -260,6 +263,8 @@
260
263
  <value>publicly-available-specification</value>
261
264
  <value>international-workshop-agreement</value>
262
265
  <value>guide</value>
266
+ <value>amendment</value>
267
+ <value>technical-corrigendum</value>
263
268
  </choice>
264
269
  </define>
265
270
  <define name="structuredidentifier">
@@ -511,4 +516,9 @@
511
516
  </oneOrMore>
512
517
  </element>
513
518
  </define>
519
+ <define name="stagename">
520
+ <element name="stagename">
521
+ <text/>
522
+ </element>
523
+ </define>
514
524
  </grammar>