metanorma-iso 1.7.3 → 1.8.3

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +7 -1
  4. data/lib/asciidoctor/iso/base.rb +14 -11
  5. data/lib/asciidoctor/iso/biblio.rng +5 -6
  6. data/lib/asciidoctor/iso/cleanup.rb +40 -24
  7. data/lib/asciidoctor/iso/front.rb +29 -17
  8. data/lib/asciidoctor/iso/front_id.rb +81 -60
  9. data/lib/asciidoctor/iso/isodoc.rng +305 -4
  10. data/lib/asciidoctor/iso/isostandard.rng +1 -0
  11. data/lib/asciidoctor/iso/section.rb +2 -1
  12. data/lib/asciidoctor/iso/validate.rb +22 -110
  13. data/lib/asciidoctor/iso/validate_image.rb +97 -0
  14. data/lib/asciidoctor/iso/validate_requirements.rb +26 -20
  15. data/lib/asciidoctor/iso/validate_section.rb +55 -29
  16. data/lib/asciidoctor/iso/validate_style.rb +36 -24
  17. data/lib/asciidoctor/iso/validate_title.rb +23 -17
  18. data/lib/isodoc/iso/base_convert.rb +8 -2
  19. data/lib/isodoc/iso/html/style-human.css +7 -0
  20. data/lib/isodoc/iso/html/style-iso.css +7 -0
  21. data/lib/isodoc/iso/html_convert.rb +0 -1
  22. data/lib/isodoc/iso/index.rb +2 -1
  23. data/lib/isodoc/iso/iso.amendment.xsl +659 -194
  24. data/lib/isodoc/iso/iso.international-standard.xsl +659 -194
  25. data/lib/isodoc/iso/metadata.rb +1 -0
  26. data/lib/isodoc/iso/presentation_xml_convert.rb +44 -33
  27. data/lib/isodoc/iso/sts_convert.rb +10 -13
  28. data/lib/isodoc/iso/word_convert.rb +0 -1
  29. data/lib/isodoc/iso/xref.rb +43 -26
  30. data/lib/metanorma/iso/processor.rb +1 -0
  31. data/lib/metanorma/iso/version.rb +1 -1
  32. data/metanorma-iso.gemspec +8 -8
  33. data/spec/asciidoctor/amd_spec.rb +5 -5
  34. data/spec/asciidoctor/base_spec.rb +428 -307
  35. data/spec/asciidoctor/blocks_spec.rb +96 -34
  36. data/spec/asciidoctor/cleanup_spec.rb +383 -25
  37. data/spec/asciidoctor/section_spec.rb +0 -14
  38. data/spec/asciidoctor/validate_spec.rb +235 -83
  39. data/spec/isodoc/postproc_spec.rb +481 -438
  40. data/spec/spec_helper.rb +16 -13
  41. metadata +50 -50
  42. data/lib/isodoc/iso/html/scripts.html +0 -178
@@ -86,6 +86,35 @@
86
86
  <text/>
87
87
  </element>
88
88
  </define>
89
+ <define name="erefType">
90
+ <optional>
91
+ <attribute name="normative">
92
+ <data type="boolean"/>
93
+ </attribute>
94
+ </optional>
95
+ <attribute name="citeas"/>
96
+ <attribute name="type">
97
+ <ref name="ReferenceFormat"/>
98
+ </attribute>
99
+ <optional>
100
+ <attribute name="alt"/>
101
+ </optional>
102
+ <optional>
103
+ <attribute name="case">
104
+ <choice>
105
+ <value>capital</value>
106
+ <value>lowercase</value>
107
+ </choice>
108
+ </attribute>
109
+ </optional>
110
+ <optional>
111
+ <attribute name="droploc">
112
+ <data type="boolean"/>
113
+ </attribute>
114
+ </optional>
115
+ <ref name="CitationType"/>
116
+ <text/>
117
+ </define>
89
118
  <define name="ul">
90
119
  <element name="ul">
91
120
  <attribute name="id">
@@ -775,6 +804,90 @@
775
804
  <ref name="paragraph"/>
776
805
  </element>
777
806
  </define>
807
+ <define name="em">
808
+ <element name="em">
809
+ <zeroOrMore>
810
+ <choice>
811
+ <ref name="PureTextElement"/>
812
+ <ref name="stem"/>
813
+ <ref name="index"/>
814
+ </choice>
815
+ </zeroOrMore>
816
+ </element>
817
+ </define>
818
+ <define name="strong">
819
+ <element name="strong">
820
+ <zeroOrMore>
821
+ <choice>
822
+ <ref name="PureTextElement"/>
823
+ <ref name="stem"/>
824
+ <ref name="index"/>
825
+ </choice>
826
+ </zeroOrMore>
827
+ </element>
828
+ </define>
829
+ <define name="tt">
830
+ <element name="tt">
831
+ <zeroOrMore>
832
+ <choice>
833
+ <ref name="PureTextElement"/>
834
+ <ref name="index"/>
835
+ </choice>
836
+ </zeroOrMore>
837
+ </element>
838
+ </define>
839
+ <define name="keyword">
840
+ <element name="keyword">
841
+ <zeroOrMore>
842
+ <choice>
843
+ <ref name="PureTextElement"/>
844
+ <ref name="index"/>
845
+ </choice>
846
+ </zeroOrMore>
847
+ </element>
848
+ </define>
849
+ <define name="strike">
850
+ <element name="strike">
851
+ <zeroOrMore>
852
+ <choice>
853
+ <ref name="PureTextElement"/>
854
+ <ref name="index"/>
855
+ </choice>
856
+ </zeroOrMore>
857
+ </element>
858
+ </define>
859
+ <define name="underline">
860
+ <element name="underline">
861
+ <zeroOrMore>
862
+ <choice>
863
+ <ref name="PureTextElement"/>
864
+ <ref name="index"/>
865
+ </choice>
866
+ </zeroOrMore>
867
+ </element>
868
+ </define>
869
+ <define name="smallcap">
870
+ <element name="smallcap">
871
+ <zeroOrMore>
872
+ <choice>
873
+ <ref name="PureTextElement"/>
874
+ <ref name="index"/>
875
+ </choice>
876
+ </zeroOrMore>
877
+ </element>
878
+ </define>
879
+ <define name="pagebreak">
880
+ <element name="pagebreak">
881
+ <optional>
882
+ <attribute name="orientation">
883
+ <choice>
884
+ <value>landscape</value>
885
+ <value>portrait</value>
886
+ </choice>
887
+ </attribute>
888
+ </optional>
889
+ </element>
890
+ </define>
778
891
  </include>
779
892
  <!-- end overrides -->
780
893
  <define name="colgroup">
@@ -793,7 +906,35 @@
793
906
  <value>internal</value>
794
907
  </define>
795
908
  <define name="TextElement" combine="choice">
796
- <ref name="concept"/>
909
+ <choice>
910
+ <ref name="concept"/>
911
+ <ref name="add"/>
912
+ <ref name="del"/>
913
+ </choice>
914
+ </define>
915
+ <define name="add">
916
+ <element name="add">
917
+ <choice>
918
+ <ref name="PureTextElement"/>
919
+ <ref name="eref"/>
920
+ <ref name="stem"/>
921
+ <ref name="keyword"/>
922
+ <ref name="xref"/>
923
+ <ref name="hyperlink"/>
924
+ </choice>
925
+ </element>
926
+ </define>
927
+ <define name="del">
928
+ <element name="del">
929
+ <choice>
930
+ <ref name="PureTextElement"/>
931
+ <ref name="eref"/>
932
+ <ref name="stem"/>
933
+ <ref name="keyword"/>
934
+ <ref name="xref"/>
935
+ <ref name="hyperlink"/>
936
+ </choice>
937
+ </element>
797
938
  </define>
798
939
  <define name="concept">
799
940
  <element name="concept">
@@ -814,8 +955,170 @@
814
955
  <ref name="permission"/>
815
956
  <ref name="imagemap"/>
816
957
  <ref name="svgmap"/>
958
+ <ref name="inputform"/>
959
+ </choice>
960
+ </define>
961
+ <define name="inputform">
962
+ <element name="form">
963
+ <attribute name="id">
964
+ <data type="ID"/>
965
+ </attribute>
966
+ <attribute name="name"/>
967
+ <attribute name="action"/>
968
+ <zeroOrMore>
969
+ <choice>
970
+ <ref name="TextElement"/>
971
+ <ref name="FormInput"/>
972
+ </choice>
973
+ </zeroOrMore>
974
+ </element>
975
+ </define>
976
+ <define name="FormInput">
977
+ <choice>
978
+ <ref name="input"/>
979
+ <ref name="formlabel"/>
980
+ <ref name="select"/>
981
+ <ref name="textarea"/>
982
+ </choice>
983
+ </define>
984
+ <define name="InputType">
985
+ <choice>
986
+ <value>button</value>
987
+ <value>checkbox</value>
988
+ <value>date</value>
989
+ <value>file</value>
990
+ <value>password</value>
991
+ <value>radio</value>
992
+ <value>submit</value>
993
+ <value>text</value>
817
994
  </choice>
818
995
  </define>
996
+ <define name="input">
997
+ <element name="input">
998
+ <attribute name="type">
999
+ <ref name="InputType"/>
1000
+ </attribute>
1001
+ <optional>
1002
+ <attribute name="checked">
1003
+ <data type="boolean"/>
1004
+ </attribute>
1005
+ </optional>
1006
+ <optional>
1007
+ <attribute name="disabled">
1008
+ <data type="boolean"/>
1009
+ </attribute>
1010
+ </optional>
1011
+ <optional>
1012
+ <attribute name="readonly">
1013
+ <data type="boolean"/>
1014
+ </attribute>
1015
+ </optional>
1016
+ <optional>
1017
+ <attribute name="maxlength">
1018
+ <data type="int"/>
1019
+ </attribute>
1020
+ </optional>
1021
+ <optional>
1022
+ <attribute name="minlength">
1023
+ <data type="int"/>
1024
+ </attribute>
1025
+ </optional>
1026
+ <optional>
1027
+ <attribute name="name"/>
1028
+ </optional>
1029
+ <optional>
1030
+ <attribute name="value"/>
1031
+ </optional>
1032
+ <optional>
1033
+ <attribute name="id">
1034
+ <data type="ID"/>
1035
+ </attribute>
1036
+ </optional>
1037
+ </element>
1038
+ </define>
1039
+ <define name="formlabel">
1040
+ <element name="label">
1041
+ <attribute name="for">
1042
+ <data type="IDREF"/>
1043
+ </attribute>
1044
+ <zeroOrMore>
1045
+ <ref name="PureTextElement"/>
1046
+ </zeroOrMore>
1047
+ </element>
1048
+ </define>
1049
+ <define name="select">
1050
+ <element name="select">
1051
+ <optional>
1052
+ <attribute name="name"/>
1053
+ </optional>
1054
+ <optional>
1055
+ <attribute name="value"/>
1056
+ </optional>
1057
+ <optional>
1058
+ <attribute name="id">
1059
+ <data type="ID"/>
1060
+ </attribute>
1061
+ </optional>
1062
+ <optional>
1063
+ <attribute name="disabled">
1064
+ <data type="boolean"/>
1065
+ </attribute>
1066
+ </optional>
1067
+ <optional>
1068
+ <attribute name="multiple">
1069
+ <data type="boolean"/>
1070
+ </attribute>
1071
+ </optional>
1072
+ <optional>
1073
+ <attribute name="size">
1074
+ <data type="int"/>
1075
+ </attribute>
1076
+ </optional>
1077
+ <oneOrMore>
1078
+ <ref name="option"/>
1079
+ </oneOrMore>
1080
+ </element>
1081
+ </define>
1082
+ <define name="option">
1083
+ <element name="option">
1084
+ <optional>
1085
+ <attribute name="disabled">
1086
+ <data type="boolean"/>
1087
+ </attribute>
1088
+ </optional>
1089
+ <optional>
1090
+ <attribute name="value"/>
1091
+ </optional>
1092
+ <zeroOrMore>
1093
+ <ref name="PureTextElement"/>
1094
+ </zeroOrMore>
1095
+ </element>
1096
+ </define>
1097
+ <define name="textarea">
1098
+ <element name="textarea">
1099
+ <optional>
1100
+ <attribute name="name"/>
1101
+ </optional>
1102
+ <optional>
1103
+ <attribute name="value"/>
1104
+ </optional>
1105
+ <optional>
1106
+ <attribute name="id">
1107
+ <data type="ID"/>
1108
+ </attribute>
1109
+ </optional>
1110
+ <optional>
1111
+ <attribute name="rows">
1112
+ <data type="int"/>
1113
+ </attribute>
1114
+ </optional>
1115
+ <optional>
1116
+ <attribute name="cols">
1117
+ <data type="int"/>
1118
+ </attribute>
1119
+ </optional>
1120
+ </element>
1121
+ </define>
819
1122
  <define name="bibliography">
820
1123
  <element name="bibliography">
821
1124
  <oneOrMore>
@@ -888,9 +1191,7 @@
888
1191
  </define>
889
1192
  <define name="IsoWorkgroup">
890
1193
  <optional>
891
- <attribute name="number">
892
- <data type="int"/>
893
- </attribute>
1194
+ <attribute name="number"/>
894
1195
  </optional>
895
1196
  <optional>
896
1197
  <attribute name="type"/>
@@ -256,6 +256,7 @@
256
256
  <value>guide</value>
257
257
  <value>amendment</value>
258
258
  <value>technical-corrigendum</value>
259
+ <value>directive</value>
259
260
  </choice>
260
261
  </define>
261
262
  <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