metanorma-iso 1.7.4 → 1.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/lib/asciidoctor/iso/base.rb +14 -11
- data/lib/asciidoctor/iso/biblio.rng +1 -0
- data/lib/asciidoctor/iso/cleanup.rb +40 -24
- data/lib/asciidoctor/iso/front.rb +28 -16
- data/lib/asciidoctor/iso/front_id.rb +66 -50
- data/lib/asciidoctor/iso/isodoc.rng +321 -4
- data/lib/asciidoctor/iso/isostandard-amd.rng +3 -0
- data/lib/asciidoctor/iso/isostandard.rng +12 -0
- data/lib/asciidoctor/iso/section.rb +2 -1
- data/lib/asciidoctor/iso/validate.rb +22 -110
- data/lib/asciidoctor/iso/validate_image.rb +97 -0
- data/lib/asciidoctor/iso/validate_requirements.rb +26 -20
- data/lib/asciidoctor/iso/validate_section.rb +55 -29
- data/lib/asciidoctor/iso/validate_style.rb +36 -24
- data/lib/asciidoctor/iso/validate_title.rb +2 -4
- data/lib/isodoc/iso/base_convert.rb +8 -2
- data/lib/isodoc/iso/html/style-human.css +7 -0
- data/lib/isodoc/iso/html/style-iso.css +7 -0
- data/lib/isodoc/iso/html_convert.rb +0 -1
- data/lib/isodoc/iso/iso.amendment.xsl +680 -198
- data/lib/isodoc/iso/iso.international-standard.xsl +680 -198
- data/lib/isodoc/iso/metadata.rb +1 -0
- data/lib/isodoc/iso/presentation_xml_convert.rb +44 -33
- data/lib/isodoc/iso/sts_convert.rb +10 -13
- data/lib/isodoc/iso/word_convert.rb +0 -1
- data/lib/isodoc/iso/xref.rb +52 -34
- data/lib/metanorma/iso/processor.rb +1 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/metanorma-iso.gemspec +7 -7
- data/spec/asciidoctor/base_spec.rb +426 -305
- data/spec/asciidoctor/blocks_spec.rb +96 -34
- data/spec/asciidoctor/cleanup_spec.rb +383 -25
- data/spec/asciidoctor/section_spec.rb +0 -14
- data/spec/asciidoctor/validate_spec.rb +218 -83
- data/spec/isodoc/postproc_spec.rb +481 -438
- data/spec/spec_helper.rb +16 -15
- metadata +46 -46
- data/lib/isodoc/iso/html/scripts.html +0 -178
@@ -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>
|
@@ -86,6 +91,35 @@
|
|
86
91
|
<text/>
|
87
92
|
</element>
|
88
93
|
</define>
|
94
|
+
<define name="erefType">
|
95
|
+
<optional>
|
96
|
+
<attribute name="normative">
|
97
|
+
<data type="boolean"/>
|
98
|
+
</attribute>
|
99
|
+
</optional>
|
100
|
+
<attribute name="citeas"/>
|
101
|
+
<attribute name="type">
|
102
|
+
<ref name="ReferenceFormat"/>
|
103
|
+
</attribute>
|
104
|
+
<optional>
|
105
|
+
<attribute name="alt"/>
|
106
|
+
</optional>
|
107
|
+
<optional>
|
108
|
+
<attribute name="case">
|
109
|
+
<choice>
|
110
|
+
<value>capital</value>
|
111
|
+
<value>lowercase</value>
|
112
|
+
</choice>
|
113
|
+
</attribute>
|
114
|
+
</optional>
|
115
|
+
<optional>
|
116
|
+
<attribute name="droploc">
|
117
|
+
<data type="boolean"/>
|
118
|
+
</attribute>
|
119
|
+
</optional>
|
120
|
+
<ref name="CitationType"/>
|
121
|
+
<text/>
|
122
|
+
</define>
|
89
123
|
<define name="ul">
|
90
124
|
<element name="ul">
|
91
125
|
<attribute name="id">
|
@@ -514,6 +548,9 @@
|
|
514
548
|
</define>
|
515
549
|
<define name="BibDataExtensionType">
|
516
550
|
<ref name="doctype"/>
|
551
|
+
<optional>
|
552
|
+
<ref name="docsubtype"/>
|
553
|
+
</optional>
|
517
554
|
<optional>
|
518
555
|
<ref name="editorialgroup"/>
|
519
556
|
</optional>
|
@@ -775,8 +812,100 @@
|
|
775
812
|
<ref name="paragraph"/>
|
776
813
|
</element>
|
777
814
|
</define>
|
815
|
+
<define name="em">
|
816
|
+
<element name="em">
|
817
|
+
<zeroOrMore>
|
818
|
+
<choice>
|
819
|
+
<ref name="PureTextElement"/>
|
820
|
+
<ref name="stem"/>
|
821
|
+
<ref name="index"/>
|
822
|
+
</choice>
|
823
|
+
</zeroOrMore>
|
824
|
+
</element>
|
825
|
+
</define>
|
826
|
+
<define name="strong">
|
827
|
+
<element name="strong">
|
828
|
+
<zeroOrMore>
|
829
|
+
<choice>
|
830
|
+
<ref name="PureTextElement"/>
|
831
|
+
<ref name="stem"/>
|
832
|
+
<ref name="index"/>
|
833
|
+
</choice>
|
834
|
+
</zeroOrMore>
|
835
|
+
</element>
|
836
|
+
</define>
|
837
|
+
<define name="tt">
|
838
|
+
<element name="tt">
|
839
|
+
<zeroOrMore>
|
840
|
+
<choice>
|
841
|
+
<ref name="PureTextElement"/>
|
842
|
+
<ref name="index"/>
|
843
|
+
</choice>
|
844
|
+
</zeroOrMore>
|
845
|
+
</element>
|
846
|
+
</define>
|
847
|
+
<define name="keyword">
|
848
|
+
<element name="keyword">
|
849
|
+
<zeroOrMore>
|
850
|
+
<choice>
|
851
|
+
<ref name="PureTextElement"/>
|
852
|
+
<ref name="index"/>
|
853
|
+
</choice>
|
854
|
+
</zeroOrMore>
|
855
|
+
</element>
|
856
|
+
</define>
|
857
|
+
<define name="strike">
|
858
|
+
<element name="strike">
|
859
|
+
<zeroOrMore>
|
860
|
+
<choice>
|
861
|
+
<ref name="PureTextElement"/>
|
862
|
+
<ref name="index"/>
|
863
|
+
</choice>
|
864
|
+
</zeroOrMore>
|
865
|
+
</element>
|
866
|
+
</define>
|
867
|
+
<define name="underline">
|
868
|
+
<element name="underline">
|
869
|
+
<zeroOrMore>
|
870
|
+
<choice>
|
871
|
+
<ref name="PureTextElement"/>
|
872
|
+
<ref name="index"/>
|
873
|
+
</choice>
|
874
|
+
</zeroOrMore>
|
875
|
+
</element>
|
876
|
+
</define>
|
877
|
+
<define name="smallcap">
|
878
|
+
<element name="smallcap">
|
879
|
+
<zeroOrMore>
|
880
|
+
<choice>
|
881
|
+
<ref name="PureTextElement"/>
|
882
|
+
<ref name="index"/>
|
883
|
+
</choice>
|
884
|
+
</zeroOrMore>
|
885
|
+
</element>
|
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>
|
778
899
|
</include>
|
779
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>
|
780
909
|
<define name="colgroup">
|
781
910
|
<element name="colgroup">
|
782
911
|
<oneOrMore>
|
@@ -793,7 +922,35 @@
|
|
793
922
|
<value>internal</value>
|
794
923
|
</define>
|
795
924
|
<define name="TextElement" combine="choice">
|
796
|
-
<
|
925
|
+
<choice>
|
926
|
+
<ref name="concept"/>
|
927
|
+
<ref name="add"/>
|
928
|
+
<ref name="del"/>
|
929
|
+
</choice>
|
930
|
+
</define>
|
931
|
+
<define name="add">
|
932
|
+
<element name="add">
|
933
|
+
<choice>
|
934
|
+
<ref name="PureTextElement"/>
|
935
|
+
<ref name="eref"/>
|
936
|
+
<ref name="stem"/>
|
937
|
+
<ref name="keyword"/>
|
938
|
+
<ref name="xref"/>
|
939
|
+
<ref name="hyperlink"/>
|
940
|
+
</choice>
|
941
|
+
</element>
|
942
|
+
</define>
|
943
|
+
<define name="del">
|
944
|
+
<element name="del">
|
945
|
+
<choice>
|
946
|
+
<ref name="PureTextElement"/>
|
947
|
+
<ref name="eref"/>
|
948
|
+
<ref name="stem"/>
|
949
|
+
<ref name="keyword"/>
|
950
|
+
<ref name="xref"/>
|
951
|
+
<ref name="hyperlink"/>
|
952
|
+
</choice>
|
953
|
+
</element>
|
797
954
|
</define>
|
798
955
|
<define name="concept">
|
799
956
|
<element name="concept">
|
@@ -814,8 +971,170 @@
|
|
814
971
|
<ref name="permission"/>
|
815
972
|
<ref name="imagemap"/>
|
816
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>
|
817
1010
|
</choice>
|
818
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>
|
819
1138
|
<define name="bibliography">
|
820
1139
|
<element name="bibliography">
|
821
1140
|
<oneOrMore>
|
@@ -888,9 +1207,7 @@
|
|
888
1207
|
</define>
|
889
1208
|
<define name="IsoWorkgroup">
|
890
1209
|
<optional>
|
891
|
-
<attribute name="number"
|
892
|
-
<data type="int"/>
|
893
|
-
</attribute>
|
1210
|
+
<attribute name="number"/>
|
894
1211
|
</optional>
|
895
1212
|
<optional>
|
896
1213
|
<attribute name="type"/>
|
@@ -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
|
3
|
-
require_relative "./validate_requirements
|
4
|
-
require_relative "./validate_section
|
5
|
-
require_relative "./validate_title
|
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
|
-
|
58
|
-
next unless !
|
59
|
-
|
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
|
-
|
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
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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,
|
86
|
-
|
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(
|
166
|
+
"Reference #{b&.at('./@id')&.text} does not have an "\
|
255
167
|
"associated footnote indicating unpublished status")
|
256
168
|
end
|
257
169
|
end
|