metanorma-iso 1.8.0 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -13
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +4 -8
  5. data/lib/asciidoctor/iso/base.rb +14 -11
  6. data/lib/asciidoctor/iso/biblio.rng +1 -0
  7. data/lib/asciidoctor/iso/cleanup.rb +40 -24
  8. data/lib/asciidoctor/iso/front.rb +28 -16
  9. data/lib/asciidoctor/iso/front_id.rb +66 -50
  10. data/lib/asciidoctor/iso/isodoc.rng +191 -3
  11. data/lib/asciidoctor/iso/isostandard-amd.rng +3 -0
  12. data/lib/asciidoctor/iso/isostandard.rng +12 -0
  13. data/lib/asciidoctor/iso/section.rb +2 -1
  14. data/lib/asciidoctor/iso/validate.rb +22 -110
  15. data/lib/asciidoctor/iso/validate_image.rb +97 -0
  16. data/lib/asciidoctor/iso/validate_requirements.rb +26 -20
  17. data/lib/asciidoctor/iso/validate_section.rb +55 -29
  18. data/lib/asciidoctor/iso/validate_style.rb +36 -24
  19. data/lib/asciidoctor/iso/validate_title.rb +2 -4
  20. data/lib/isodoc/iso/base_convert.rb +20 -14
  21. data/lib/isodoc/iso/html/isodoc.css +475 -20
  22. data/lib/isodoc/iso/html/isodoc.scss +456 -23
  23. data/lib/isodoc/iso/html/wordstyle.css +202 -31
  24. data/lib/isodoc/iso/html/wordstyle.scss +194 -32
  25. data/lib/isodoc/iso/iso.amendment.xsl +666 -193
  26. data/lib/isodoc/iso/iso.international-standard.xsl +666 -193
  27. data/lib/isodoc/iso/metadata.rb +3 -2
  28. data/lib/isodoc/iso/presentation_xml_convert.rb +15 -14
  29. data/lib/isodoc/iso/sts_convert.rb +10 -13
  30. data/lib/isodoc/iso/word_convert.rb +153 -39
  31. data/lib/isodoc/iso/xref.rb +44 -29
  32. data/lib/metanorma/iso/processor.rb +1 -0
  33. data/lib/metanorma/iso/version.rb +1 -1
  34. data/metanorma-iso.gemspec +3 -3
  35. data/spec/asciidoctor/base_spec.rb +426 -305
  36. data/spec/asciidoctor/blocks_spec.rb +96 -34
  37. data/spec/asciidoctor/cleanup_spec.rb +383 -25
  38. data/spec/asciidoctor/section_spec.rb +0 -14
  39. data/spec/asciidoctor/validate_spec.rb +218 -83
  40. data/spec/isodoc/amd_spec.rb +193 -201
  41. data/spec/isodoc/blocks_spec.rb +100 -88
  42. data/spec/isodoc/i18n_spec.rb +36 -36
  43. data/spec/isodoc/inline_spec.rb +2 -2
  44. data/spec/isodoc/iso_spec.rb +86 -138
  45. data/spec/isodoc/postproc_spec.rb +492 -442
  46. data/spec/isodoc/ref_spec.rb +6 -6
  47. data/spec/isodoc/section_spec.rb +301 -306
  48. data/spec/isodoc/table_spec.rb +166 -231
  49. data/spec/isodoc/terms_spec.rb +11 -8
  50. data/spec/isodoc/xref_spec.rb +147 -118
  51. data/spec/spec_helper.rb +16 -15
  52. metadata +8 -7
@@ -45,6 +45,11 @@
45
45
  <optional>
46
46
  <attribute name="alt"/>
47
47
  </optional>
48
+ <optional>
49
+ <attribute name="updatetype">
50
+ <data type="boolean"/>
51
+ </attribute>
52
+ </optional>
48
53
  <text/>
49
54
  </element>
50
55
  </define>
@@ -543,6 +548,9 @@
543
548
  </define>
544
549
  <define name="BibDataExtensionType">
545
550
  <ref name="doctype"/>
551
+ <optional>
552
+ <ref name="docsubtype"/>
553
+ </optional>
546
554
  <optional>
547
555
  <ref name="editorialgroup"/>
548
556
  </optional>
@@ -876,8 +884,28 @@
876
884
  </zeroOrMore>
877
885
  </element>
878
886
  </define>
887
+ <define name="pagebreak">
888
+ <element name="pagebreak">
889
+ <optional>
890
+ <attribute name="orientation">
891
+ <choice>
892
+ <value>landscape</value>
893
+ <value>portrait</value>
894
+ </choice>
895
+ </attribute>
896
+ </optional>
897
+ </element>
898
+ </define>
879
899
  </include>
880
900
  <!-- end overrides -->
901
+ <define name="docsubtype">
902
+ <element name="docsubtype">
903
+ <ref name="DocumentSubtype"/>
904
+ </element>
905
+ </define>
906
+ <define name="DocumentSubtype">
907
+ <text/>
908
+ </define>
881
909
  <define name="colgroup">
882
910
  <element name="colgroup">
883
911
  <oneOrMore>
@@ -943,8 +971,170 @@
943
971
  <ref name="permission"/>
944
972
  <ref name="imagemap"/>
945
973
  <ref name="svgmap"/>
974
+ <ref name="inputform"/>
975
+ </choice>
976
+ </define>
977
+ <define name="inputform">
978
+ <element name="form">
979
+ <attribute name="id">
980
+ <data type="ID"/>
981
+ </attribute>
982
+ <attribute name="name"/>
983
+ <attribute name="action"/>
984
+ <zeroOrMore>
985
+ <choice>
986
+ <ref name="TextElement"/>
987
+ <ref name="FormInput"/>
988
+ </choice>
989
+ </zeroOrMore>
990
+ </element>
991
+ </define>
992
+ <define name="FormInput">
993
+ <choice>
994
+ <ref name="input"/>
995
+ <ref name="formlabel"/>
996
+ <ref name="select"/>
997
+ <ref name="textarea"/>
998
+ </choice>
999
+ </define>
1000
+ <define name="InputType">
1001
+ <choice>
1002
+ <value>button</value>
1003
+ <value>checkbox</value>
1004
+ <value>date</value>
1005
+ <value>file</value>
1006
+ <value>password</value>
1007
+ <value>radio</value>
1008
+ <value>submit</value>
1009
+ <value>text</value>
946
1010
  </choice>
947
1011
  </define>
1012
+ <define name="input">
1013
+ <element name="input">
1014
+ <attribute name="type">
1015
+ <ref name="InputType"/>
1016
+ </attribute>
1017
+ <optional>
1018
+ <attribute name="checked">
1019
+ <data type="boolean"/>
1020
+ </attribute>
1021
+ </optional>
1022
+ <optional>
1023
+ <attribute name="disabled">
1024
+ <data type="boolean"/>
1025
+ </attribute>
1026
+ </optional>
1027
+ <optional>
1028
+ <attribute name="readonly">
1029
+ <data type="boolean"/>
1030
+ </attribute>
1031
+ </optional>
1032
+ <optional>
1033
+ <attribute name="maxlength">
1034
+ <data type="int"/>
1035
+ </attribute>
1036
+ </optional>
1037
+ <optional>
1038
+ <attribute name="minlength">
1039
+ <data type="int"/>
1040
+ </attribute>
1041
+ </optional>
1042
+ <optional>
1043
+ <attribute name="name"/>
1044
+ </optional>
1045
+ <optional>
1046
+ <attribute name="value"/>
1047
+ </optional>
1048
+ <optional>
1049
+ <attribute name="id">
1050
+ <data type="ID"/>
1051
+ </attribute>
1052
+ </optional>
1053
+ </element>
1054
+ </define>
1055
+ <define name="formlabel">
1056
+ <element name="label">
1057
+ <attribute name="for">
1058
+ <data type="IDREF"/>
1059
+ </attribute>
1060
+ <zeroOrMore>
1061
+ <ref name="PureTextElement"/>
1062
+ </zeroOrMore>
1063
+ </element>
1064
+ </define>
1065
+ <define name="select">
1066
+ <element name="select">
1067
+ <optional>
1068
+ <attribute name="name"/>
1069
+ </optional>
1070
+ <optional>
1071
+ <attribute name="value"/>
1072
+ </optional>
1073
+ <optional>
1074
+ <attribute name="id">
1075
+ <data type="ID"/>
1076
+ </attribute>
1077
+ </optional>
1078
+ <optional>
1079
+ <attribute name="disabled">
1080
+ <data type="boolean"/>
1081
+ </attribute>
1082
+ </optional>
1083
+ <optional>
1084
+ <attribute name="multiple">
1085
+ <data type="boolean"/>
1086
+ </attribute>
1087
+ </optional>
1088
+ <optional>
1089
+ <attribute name="size">
1090
+ <data type="int"/>
1091
+ </attribute>
1092
+ </optional>
1093
+ <oneOrMore>
1094
+ <ref name="option"/>
1095
+ </oneOrMore>
1096
+ </element>
1097
+ </define>
1098
+ <define name="option">
1099
+ <element name="option">
1100
+ <optional>
1101
+ <attribute name="disabled">
1102
+ <data type="boolean"/>
1103
+ </attribute>
1104
+ </optional>
1105
+ <optional>
1106
+ <attribute name="value"/>
1107
+ </optional>
1108
+ <zeroOrMore>
1109
+ <ref name="PureTextElement"/>
1110
+ </zeroOrMore>
1111
+ </element>
1112
+ </define>
1113
+ <define name="textarea">
1114
+ <element name="textarea">
1115
+ <optional>
1116
+ <attribute name="name"/>
1117
+ </optional>
1118
+ <optional>
1119
+ <attribute name="value"/>
1120
+ </optional>
1121
+ <optional>
1122
+ <attribute name="id">
1123
+ <data type="ID"/>
1124
+ </attribute>
1125
+ </optional>
1126
+ <optional>
1127
+ <attribute name="rows">
1128
+ <data type="int"/>
1129
+ </attribute>
1130
+ </optional>
1131
+ <optional>
1132
+ <attribute name="cols">
1133
+ <data type="int"/>
1134
+ </attribute>
1135
+ </optional>
1136
+ </element>
1137
+ </define>
948
1138
  <define name="bibliography">
949
1139
  <element name="bibliography">
950
1140
  <oneOrMore>
@@ -1017,9 +1207,7 @@
1017
1207
  </define>
1018
1208
  <define name="IsoWorkgroup">
1019
1209
  <optional>
1020
- <attribute name="number">
1021
- <data type="int"/>
1022
- </attribute>
1210
+ <attribute name="number"/>
1023
1211
  </optional>
1024
1212
  <optional>
1025
1213
  <attribute name="type"/>
@@ -83,6 +83,9 @@
83
83
  </define>
84
84
  <define name="BibDataExtensionType">
85
85
  <ref name="doctype"/>
86
+ <optional>
87
+ <ref name="docsubtype"/>
88
+ </optional>
86
89
  <ref name="editorialgroup"/>
87
90
  <zeroOrMore>
88
91
  <ref name="ics"/>
@@ -38,6 +38,9 @@
38
38
  </define>
39
39
  <define name="BibDataExtensionType">
40
40
  <ref name="doctype"/>
41
+ <optional>
42
+ <ref name="docsubtype"/>
43
+ </optional>
41
44
  <optional>
42
45
  <ref name="horizontal"/>
43
46
  </optional>
@@ -256,6 +259,15 @@
256
259
  <value>guide</value>
257
260
  <value>amendment</value>
258
261
  <value>technical-corrigendum</value>
262
+ <value>directive</value>
263
+ </choice>
264
+ </define>
265
+ <define name="DocumentSubtype">
266
+ <choice>
267
+ <value>specification</value>
268
+ <value>method-of-test</value>
269
+ <value>vocabulary</value>
270
+ <value>code-of-practice</value>
259
271
  </choice>
260
272
  </define>
261
273
  <define name="structuredidentifier">
@@ -10,7 +10,7 @@ module Asciidoctor
10
10
  end
11
11
 
12
12
  def scope_parse(attrs, xml, node)
13
- attrs = attrs.merge(type: "scope") unless @amd
13
+ attrs = attrs.merge(type: "scope") unless @amd
14
14
  clause_parse(attrs, xml, node)
15
15
  end
16
16
 
@@ -32,6 +32,7 @@ module Asciidoctor
32
32
 
33
33
  def sectiontype(node, level = true)
34
34
  return nil if @amd
35
+
35
36
  super
36
37
  end
37
38
  end
@@ -1,8 +1,9 @@
1
1
  require "metanorma-standoc"
2
- require_relative "./validate_style.rb"
3
- require_relative "./validate_requirements.rb"
4
- require_relative "./validate_section.rb"
5
- require_relative "./validate_title.rb"
2
+ require_relative "./validate_style"
3
+ require_relative "./validate_requirements"
4
+ require_relative "./validate_section"
5
+ require_relative "./validate_title"
6
+ require_relative "./validate_image"
6
7
  require "nokogiri"
7
8
  require "jing"
8
9
  require "iev"
@@ -10,17 +11,6 @@ require "iev"
10
11
  module Asciidoctor
11
12
  module ISO
12
13
  class Converter < Standoc::Converter
13
- # ISO/IEC DIR 2, 22.3.2
14
- def onlychild_clause_validate(root)
15
- root.xpath(Standoc::Utils::SUBCLAUSE_XPATH).each do |c|
16
- next unless c.xpath("../clause").size == 1
17
- title = c.at("./title")
18
- location = c["id"] || c.text[0..60] + "..."
19
- location += ":#{title.text}" if c["id"] && !title.nil?
20
- @log.add("Style", nil, "#{location}: subclause is only child")
21
- end
22
- end
23
-
24
14
  def isosubgroup_validate(root)
25
15
  root.xpath("//technical-committee/@type").each do |t|
26
16
  unless %w{TC PC JTC JPC}.include? t.text
@@ -37,12 +27,13 @@ module Asciidoctor
37
27
  end
38
28
 
39
29
  # ISO/IEC DIR 2, 15.5.3
30
+ # does not deal with preceding text marked up
40
31
  def see_xrefs_validate(root)
41
32
  root.xpath("//xref").each do |t|
42
- # does not deal with preceding text marked up
43
33
  preceding = t.at("./preceding-sibling::text()[last()]")
44
34
  next unless !preceding.nil? &&
45
35
  /\b(see| refer to)\s*$/mi.match(preceding)
36
+
46
37
  (target = root.at("//*[@id = '#{t['target']}']")) || next
47
38
  if target&.at("./ancestor-or-self::*[@obligation = 'normative']")
48
39
  @log.add("Style", t,
@@ -54,36 +45,34 @@ module Asciidoctor
54
45
  # ISO/IEC DIR 2, 15.5.3
55
46
  def see_erefs_validate(root)
56
47
  root.xpath("//eref").each do |t|
57
- preceding = t.at("./preceding-sibling::text()[last()]")
58
- next unless !preceding.nil? &&
59
- /\b(see|refer to)\s*$/mi.match(preceding)
48
+ prec = t.at("./preceding-sibling::text()[last()]")
49
+ next unless !prec.nil? && /\b(see|refer to)\s*$/mi.match(prec)
50
+
60
51
  unless target = root.at("//*[@id = '#{t['bibitemid']}']")
61
52
  @log.add("Bibliography", t,
62
53
  "'#{t} is not pointing to a real reference")
63
54
  next
64
55
  end
65
- if target.at("./ancestor::references[@normative = 'true']")
56
+ target.at("./ancestor::references[@normative = 'true']") and
66
57
  @log.add("Style", t,
67
58
  "'see #{t}' is pointing to a normative reference")
68
- end
69
59
  end
70
60
  end
71
61
 
72
62
  # ISO/IEC DIR 2, 10.4
73
63
  def locality_erefs_validate(root)
74
64
  root.xpath("//eref[descendant::locality]").each do |t|
75
- if /^(ISO|IEC)/.match t["citeas"]
76
- unless /:[ ]?(\d+{4}|–)$/.match t["citeas"]
77
- @log.add("Style", t,
78
- "undated reference #{t['citeas']} should not contain "\
79
- "specific elements")
80
- end
65
+ if /^(ISO|IEC)/.match?(t["citeas"]) &&
66
+ !(/: ?(\d+{4}|–)$/.match?(t["citeas"]))
67
+ @log.add("Style", t,
68
+ "undated reference #{t['citeas']} should not contain "\
69
+ "specific elements")
81
70
  end
82
71
  end
83
72
  end
84
73
 
85
- def termdef_warn(text, re, t, term, msg)
86
- re.match(text) && @log.add("Style", t, "#{term}: #{msg}")
74
+ def termdef_warn(text, regex, elem, term, msg)
75
+ regex.match(text) && @log.add("Style", elem, "#{term}: #{msg}")
87
76
  end
88
77
 
89
78
  # ISO/IEC DIR 2, 16.5.6
@@ -103,6 +92,7 @@ module Asciidoctor
103
92
  def cited_term_style(xmldoc)
104
93
  xmldoc.xpath("//term//xref").each do |x|
105
94
  next unless xmldoc.at("//term[@id = '#{x['target']}']")
95
+
106
96
  x&.previous&.text == " (" and x&.previous&.previous&.name == "em" or
107
97
  style_warning(x, "term citation not preceded with italicised term",
108
98
  x.parent.text)
@@ -111,8 +101,8 @@ module Asciidoctor
111
101
 
112
102
  def doctype_validate(xmldoc)
113
103
  doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
114
- %w(international-standard technical-specification technical-report
115
- publicly-available-specification international-workshop-agreement
104
+ %w(international-standard technical-specification technical-report
105
+ publicly-available-specification international-workshop-agreement
116
106
  guide amendment technical-corrigendum).include? doctype or
117
107
  @log.add("Document Attributes", nil,
118
108
  "#{doctype} is not a recognised document type")
@@ -146,84 +136,6 @@ module Asciidoctor
146
136
  "#{iteration} is not a recognised iteration")
147
137
  end
148
138
 
149
- # DRG directives 3.7; but anticipated by standoc
150
- def subfigure_validate(xmldoc)
151
- xmldoc.xpath("//figure//figure").each do |f|
152
- { footnote: "fn", note: "note", key: "dl" }.each do |k, v|
153
- f.xpath(".//#{v}").each do |n|
154
- @log.add("Style", n, "#{k} is not permitted in a subfigure")
155
- end
156
- end
157
- end
158
- end
159
-
160
- def image_name_prefix(xmldoc)
161
- std = xmldoc&.at("//bibdata/ext/structuredidentifier/project-number") or return
162
- num = xmldoc&.at("//bibdata/docnumber")&.text or return
163
- ed = xmldoc&.at("//bibdata/edition")&.text || "1"
164
- prefix = num
165
- part = std["part"] and prefix += "-#{std['part']}"
166
- prefix += "_ed#{ed}"
167
- amd = std["amendment"] and prefix += "amd#{amd}"
168
- prefix
169
- end
170
-
171
- def image_name_suffix(xmldoc)
172
- case xmldoc&.at("//bibdata/language")&.text
173
- when "fr" then "_f"
174
- when "de" then "_d"
175
- when "ru" then "_r"
176
- when "es" then "_s"
177
- when "ar" then "_a"
178
- when "en" then "_e"
179
- else
180
- "_e"
181
- end
182
- end
183
-
184
- def disjunct_error(i, cond1, cond2, msg1, msg2)
185
- cond1 && !cond2 and @log.add("Style", i, "image name #{i['src']} #{msg1}")
186
- !cond1 && cond2 and @log.add("Style", i, "image name #{i['src']} #{msg2}")
187
- end
188
-
189
- def image_name_validate1(i, prefix)
190
- m = %r[(SL)?#{prefix}fig(?<tab>Tab)?(?<annex>[A-Z])?(Text)?(?<num>\d+)
191
- (?<subfig>[a-z])?(?<key>_key\d+)?(?<lang>_[a-z])?$]x.match(File.basename(i["src"], ".*"))
192
- if m.nil?
193
- @log.add("Style", i, "image name #{i['src']} does not match DRG requirements")
194
- return
195
- end
196
- warn i['src']
197
- disjunct_error(i, i.at("./ancestor::table"), !m[:tab].nil?,
198
- "is under a table but is not so labelled", "is labelled as under a table but is not")
199
- disjunct_error(i, i.at("./ancestor::annex"), !m[:annex].nil?,
200
- "is under an annex but is not so labelled", "is labelled as under an annex but is not")
201
- disjunct_error(i, i.xpath("./ancestor::figure").size > 1, !m[:subfig].nil?,
202
- "does not have a subfigure letter but is a subfigure",
203
- "has a subfigure letter but is not a subfigure")
204
- lang = image_name_suffix(i.document.root)
205
- (m[:lang] || "_e") == lang or @log.add("Style", i, "image name #{i['src']} expected to have suffix #{lang}")
206
- end
207
-
208
- # DRG directives 3.2
209
- def image_name_validate(xmldoc)
210
- prefix = image_name_prefix(xmldoc) or return
211
- xmldoc.xpath("//image").each do |i|
212
- next if i["src"].start_with?("data:")
213
- if /^ISO_\d+_/.match(File.basename(i["src"]))
214
- elsif /^(SL)?#{prefix}fig/.match(File.basename(i["src"]))
215
- image_name_validate1(i, prefix)
216
- else
217
- @log.add("Style", i, "image name #{i['src']} does not match DRG requirements: expect #{prefix}fig")
218
- end
219
- end
220
- end
221
-
222
- def figure_validate(xmldoc)
223
- image_name_validate(xmldoc)
224
- subfigure_validate(xmldoc)
225
- end
226
-
227
139
  def bibdata_validate(doc)
228
140
  doctype_validate(doc)
229
141
  script_validate(doc)
@@ -251,7 +163,7 @@ module Asciidoctor
251
163
  xmldoc.xpath("//bibitem[date/on = '–']").each do |b|
252
164
  b.at("./note[@type = 'Unpublished-Status']") or
253
165
  @log.add("Style", b,
254
- "Reference #{b&.at("./@id")&.text} does not have an "\
166
+ "Reference #{b&.at('./@id')&.text} does not have an "\
255
167
  "associated footnote indicating unpublished status")
256
168
  end
257
169
  end