metanorma-iso 1.10.3 → 2.0.0
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 -33
- data/.github/workflows/ubuntu.yml +1 -1
- data/.gitignore +26 -0
- data/Gemfile +1 -1
- data/Makefile +1 -1
- data/lib/asciidoctor/iso/base.rb +2 -69
- data/lib/asciidoctor/iso/cleanup.rb +2 -175
- data/lib/asciidoctor/iso/converter.rb +2 -17
- data/lib/asciidoctor/iso/deprecated.rb +5 -0
- data/lib/asciidoctor/iso/front.rb +2 -156
- data/lib/asciidoctor/iso/front_id.rb +2 -221
- data/lib/asciidoctor/iso/section.rb +2 -48
- data/lib/asciidoctor/iso/validate.rb +2 -171
- data/lib/asciidoctor/iso/validate_image.rb +2 -96
- data/lib/asciidoctor/iso/validate_requirements.rb +2 -110
- data/lib/asciidoctor/iso/validate_section.rb +2 -246
- data/lib/asciidoctor/iso/validate_style.rb +2 -169
- data/lib/asciidoctor/iso/validate_title.rb +2 -104
- data/lib/isodoc/iso/base_convert.rb +14 -31
- data/lib/isodoc/iso/html/style-human.css +40 -8
- data/lib/isodoc/iso/html/style-human.scss +36 -8
- data/lib/isodoc/iso/html/style-iso.css +35 -5
- data/lib/isodoc/iso/html/style-iso.scss +31 -5
- data/lib/isodoc/iso/html/wordstyle.css +10 -8
- data/lib/isodoc/iso/html/wordstyle.scss +10 -8
- data/lib/isodoc/iso/html_convert.rb +83 -22
- data/lib/isodoc/iso/index.rb +53 -45
- data/lib/isodoc/iso/iso.amendment.xsl +477 -264
- data/lib/isodoc/iso/iso.international-standard.xsl +477 -264
- data/lib/isodoc/iso/metadata.rb +27 -22
- data/lib/isodoc/iso/presentation_xml_convert.rb +42 -17
- data/lib/isodoc/iso/sts_convert.rb +2 -4
- data/lib/isodoc/iso/word_convert.rb +0 -2
- data/lib/metanorma/iso/base.rb +70 -0
- data/lib/{asciidoctor → metanorma}/iso/basicdoc.rng +0 -0
- data/lib/{asciidoctor → metanorma}/iso/biblio.rng +0 -0
- data/lib/{asciidoctor → metanorma}/iso/boilerplate-fr.xml +0 -0
- data/lib/{asciidoctor → metanorma}/iso/boilerplate.xml +0 -0
- data/lib/metanorma/iso/cleanup.rb +176 -0
- data/lib/metanorma/iso/converter.rb +18 -0
- data/lib/metanorma/iso/front.rb +170 -0
- data/lib/metanorma/iso/front_id.rb +225 -0
- data/lib/{asciidoctor → metanorma}/iso/isodoc.rng +49 -2
- data/lib/{asciidoctor → metanorma}/iso/isostandard-amd.rng +0 -0
- data/lib/{asciidoctor → metanorma}/iso/isostandard.rnc +0 -0
- data/lib/{asciidoctor → metanorma}/iso/isostandard.rng +14 -0
- data/lib/{asciidoctor → metanorma}/iso/reqt.rng +0 -0
- data/lib/metanorma/iso/section.rb +49 -0
- data/lib/metanorma/iso/validate.rb +172 -0
- data/lib/metanorma/iso/validate_image.rb +97 -0
- data/lib/metanorma/iso/validate_requirements.rb +111 -0
- data/lib/metanorma/iso/validate_section.rb +247 -0
- data/lib/metanorma/iso/validate_style.rb +170 -0
- data/lib/metanorma/iso/validate_title.rb +105 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/lib/metanorma-iso.rb +1 -1
- data/metanorma-iso.gemspec +2 -2
- data/spec/isodoc/amd_spec.rb +261 -250
- data/spec/isodoc/inline_spec.rb +238 -212
- data/spec/isodoc/iso_spec.rb +3 -1
- data/spec/isodoc/postproc_spec.rb +111 -28
- data/spec/isodoc/ref_spec.rb +4 -2
- data/spec/isodoc/section_spec.rb +1 -1
- data/spec/isodoc/terms_spec.rb +17 -24
- data/spec/{asciidoctor → metanorma}/amd_spec.rb +1 -1
- data/spec/metanorma/base_spec.rb +1185 -0
- data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/inline_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
- data/spec/metanorma/processor_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/refs_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/section_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/validate_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/vcr_cassettes/docrels.yml +35 -425
- metadata +40 -27
- data/spec/asciidoctor/base_spec.rb +0 -1333
@@ -0,0 +1,225 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "json"
|
5
|
+
require "pathname"
|
6
|
+
require "open-uri"
|
7
|
+
require "twitter_cldr"
|
8
|
+
|
9
|
+
module Metanorma
|
10
|
+
module ISO
|
11
|
+
class Converter < Standoc::Converter
|
12
|
+
STAGE_ABBRS = {
|
13
|
+
"00": "PWI",
|
14
|
+
"10": "NP",
|
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",
|
30
|
+
"50": "Final draft",
|
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
|
+
|
39
|
+
ret = STAGE_ABBRS[stage.to_sym]
|
40
|
+
ret = "PRF" if stage == "60" && substage == "00"
|
41
|
+
ret = "AWI" if stage == "10" && substage == "99"
|
42
|
+
if %w(amendment technical-corrigendum technical-report
|
43
|
+
technical-specification).include?(doctype)
|
44
|
+
ret = "D" if stage == "40" && doctype == "amendment"
|
45
|
+
ret = "FD" if stage == "50" && %w(amendment technical-corrigendum)
|
46
|
+
.include?(doctype)
|
47
|
+
end
|
48
|
+
ret
|
49
|
+
end
|
50
|
+
|
51
|
+
def stage_name(stage, substage, _doctype, iteration = nil)
|
52
|
+
return "Proof" if stage == "60" && substage == "00"
|
53
|
+
|
54
|
+
ret = STAGE_NAMES[stage.to_sym]
|
55
|
+
if iteration && %w(20 30).include?(stage)
|
56
|
+
prefix = iteration.to_i.localize(@lang.to_sym)
|
57
|
+
.to_rbnf_s("SpelloutRules", "spellout-ordinal")
|
58
|
+
ret = "#{prefix.capitalize} #{ret.downcase}"
|
59
|
+
end
|
60
|
+
ret
|
61
|
+
end
|
62
|
+
|
63
|
+
def metadata_id(node, xml)
|
64
|
+
iso_id(node, xml)
|
65
|
+
node&.attr("tc-docnumber")&.split(/,\s*/)&.each do |n|
|
66
|
+
xml.docidentifier(n, **attr_code(type: "iso-tc"))
|
67
|
+
end
|
68
|
+
xml.docnumber node&.attr("docnumber")
|
69
|
+
end
|
70
|
+
|
71
|
+
def iso_id(node, xml)
|
72
|
+
(!@amd && node.attr("docnumber")) || (@amd && node.attr("updates")) or
|
73
|
+
return
|
74
|
+
|
75
|
+
dn = iso_id1(node)
|
76
|
+
dn1 = id_stage_prefix(dn, node, false)
|
77
|
+
dn2 = id_stage_prefix(dn, node, true)
|
78
|
+
xml.docidentifier dn1, **attr_code(type: "ISO")
|
79
|
+
xml.docidentifier(id_langsuffix(dn1, node),
|
80
|
+
**attr_code(type: "iso-with-lang"))
|
81
|
+
xml.docidentifier(id_langsuffix(dn2, node),
|
82
|
+
**attr_code(type: "iso-reference"))
|
83
|
+
end
|
84
|
+
|
85
|
+
def iso_id1(node)
|
86
|
+
if @amd
|
87
|
+
dn = node.attr("updates")
|
88
|
+
add_amd_parts(dn, node)
|
89
|
+
else
|
90
|
+
part, subpart = node&.attr("partnumber")&.split(/-/)
|
91
|
+
add_id_parts(node.attr("docnumber"), part, subpart)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_amd_parts(docnum, node)
|
96
|
+
case doctype(node)
|
97
|
+
when "amendment"
|
98
|
+
"#{docnum}/Amd #{node.attr('amendment-number')}"
|
99
|
+
when "technical-corrigendum"
|
100
|
+
"#{docnum}/Cor.#{node.attr('corrigendum-number')}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def id_langsuffix(docnum, node)
|
105
|
+
lang = node.attr("language") || "en"
|
106
|
+
suffix = case lang
|
107
|
+
when "en" then "(E)"
|
108
|
+
when "fr" then "(F)"
|
109
|
+
else
|
110
|
+
"(X)"
|
111
|
+
end
|
112
|
+
"#{docnum}#{suffix}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def structured_id(node, xml)
|
116
|
+
return unless node.attr("docnumber")
|
117
|
+
|
118
|
+
part, subpart = node&.attr("partnumber")&.split(/-/)
|
119
|
+
xml.structuredidentifier do |i|
|
120
|
+
i.project_number(node.attr("docnumber"), **attr_code(
|
121
|
+
part: part, subpart: subpart,
|
122
|
+
amendment: node.attr("amendment-number"),
|
123
|
+
corrigendum: node.attr("corrigendum-number"),
|
124
|
+
origyr: node.attr("created-date")
|
125
|
+
))
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def add_id_parts(docnum, part, subpart)
|
130
|
+
docnum += "-#{part}" if part
|
131
|
+
docnum += "-#{subpart}" if subpart
|
132
|
+
docnum
|
133
|
+
end
|
134
|
+
|
135
|
+
def id_stage_abbr(stage, substage, node, bare = false)
|
136
|
+
ret = id_stage_abbr1(stage, substage, node, bare)
|
137
|
+
if %w(amendment technical-corrigendum technical-report
|
138
|
+
technical-specification).include?(doctype(node)) &&
|
139
|
+
!%w(D FD).include?(ret)
|
140
|
+
ret = "#{ret} "
|
141
|
+
end
|
142
|
+
ret
|
143
|
+
end
|
144
|
+
|
145
|
+
def id_stage_abbr1(stage, substage, node, bare)
|
146
|
+
if bare
|
147
|
+
IsoDoc::Iso::Metadata.new("en", "Latn", @i18n)
|
148
|
+
.status_abbrev(stage_abbr(stage, substage, doctype(node)),
|
149
|
+
substage, nil, nil, doctype(node))
|
150
|
+
else
|
151
|
+
IsoDoc::Iso::Metadata.new("en", "Latn", @i18n)
|
152
|
+
.status_abbrev(stage_abbr(stage, substage, doctype(node)),
|
153
|
+
substage, node.attr("iteration"),
|
154
|
+
node.attr("draft"), doctype(node))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def cover_stage_abbr(node)
|
159
|
+
stage = get_stage(node)
|
160
|
+
abbr = id_stage_abbr(get_stage(node), get_substage(node), node, true)
|
161
|
+
typeabbr = get_typeabbr(node, true)
|
162
|
+
if stage.to_i > 50 || (stage.to_i == 60 && get_substage(node).to_i < 60)
|
163
|
+
typeabbr = ""
|
164
|
+
end
|
165
|
+
"#{abbr}#{typeabbr}".strip
|
166
|
+
end
|
167
|
+
|
168
|
+
def id_stage_prefix(docnum, node, force_year)
|
169
|
+
stage = get_stage(node)
|
170
|
+
typeabbr = get_typeabbr(node)
|
171
|
+
if stage && (stage.to_i < 60)
|
172
|
+
docnum = unpub_stage_prefix(docnum, stage, typeabbr, node)
|
173
|
+
elsif typeabbr == "DIR " then docnum = "#{typeabbr}#{docnum}"
|
174
|
+
elsif typeabbr && !@amd then docnum = "/#{typeabbr}#{docnum}"
|
175
|
+
end
|
176
|
+
(force_year || !(stage && (stage.to_i < 60))) and
|
177
|
+
docnum = id_add_year(docnum, node)
|
178
|
+
docnum
|
179
|
+
end
|
180
|
+
|
181
|
+
def unpub_stage_prefix(docnum, stage, typeabbr, node)
|
182
|
+
abbr = id_stage_abbr(stage, get_substage(node), node)
|
183
|
+
%w(40 50).include?(stage) && i = node.attr("iteration") and
|
184
|
+
itersuffix = ".#{i}"
|
185
|
+
return docnum if abbr.nil? || abbr.empty? # prefixes added in cleanup
|
186
|
+
return "/#{abbr}#{typeabbr} #{docnum}#{itersuffix}" unless @amd
|
187
|
+
|
188
|
+
a = docnum.split(%r{/})
|
189
|
+
a[-1] = "#{abbr}#{a[-1]}#{itersuffix}"
|
190
|
+
a.join("/")
|
191
|
+
end
|
192
|
+
|
193
|
+
def id_add_year(docnum, node)
|
194
|
+
year = node.attr("copyright-year")
|
195
|
+
@amd and year ||= node.attr("updated-date")&.sub(/-.*$/, "")
|
196
|
+
docnum += ":#{year}" if year
|
197
|
+
docnum
|
198
|
+
end
|
199
|
+
|
200
|
+
def get_stage(node)
|
201
|
+
a = node.attr("status")
|
202
|
+
a = node.attr("docstage") if a.nil? || a.empty?
|
203
|
+
a = "60" if a.nil? || a.empty?
|
204
|
+
a
|
205
|
+
end
|
206
|
+
|
207
|
+
def get_substage(node)
|
208
|
+
stage = get_stage(node)
|
209
|
+
ret = node.attr("docsubstage")
|
210
|
+
ret = (stage == "60" ? "60" : "00") if ret.nil? || ret.empty?
|
211
|
+
ret
|
212
|
+
end
|
213
|
+
|
214
|
+
def get_typeabbr(node, amd = false)
|
215
|
+
case doctype(node)
|
216
|
+
when "directive" then "DIR "
|
217
|
+
when "technical-report" then "TR "
|
218
|
+
when "technical-specification" then "TS "
|
219
|
+
when "amendment" then (amd ? "Amd " : "")
|
220
|
+
when "technical-corrigendum" then (amd ? "Cor " : "")
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
@@ -32,6 +32,19 @@
|
|
32
32
|
<ref name="DocumentType"/>
|
33
33
|
</element>
|
34
34
|
</define>
|
35
|
+
<define name="bibitem">
|
36
|
+
<element name="bibitem">
|
37
|
+
<attribute name="id">
|
38
|
+
<data type="ID"/>
|
39
|
+
</attribute>
|
40
|
+
<optional>
|
41
|
+
<attribute name="hidden">
|
42
|
+
<data type="boolean"/>
|
43
|
+
</attribute>
|
44
|
+
</optional>
|
45
|
+
<ref name="BibliographicItem"/>
|
46
|
+
</element>
|
47
|
+
</define>
|
35
48
|
<define name="section-title">
|
36
49
|
<element name="title">
|
37
50
|
<zeroOrMore>
|
@@ -690,6 +703,7 @@
|
|
690
703
|
<ref name="terms"/>
|
691
704
|
<ref name="term-clause"/>
|
692
705
|
<ref name="definitions"/>
|
706
|
+
<ref name="floating-title"/>
|
693
707
|
</choice>
|
694
708
|
</oneOrMore>
|
695
709
|
</element>
|
@@ -1680,6 +1694,7 @@
|
|
1680
1694
|
<ref name="clause-subsection"/>
|
1681
1695
|
<ref name="terms"/>
|
1682
1696
|
<ref name="definitions"/>
|
1697
|
+
<ref name="floating-title"/>
|
1683
1698
|
</choice>
|
1684
1699
|
</oneOrMore>
|
1685
1700
|
</choice>
|
@@ -1722,6 +1737,7 @@
|
|
1722
1737
|
<ref name="terms"/>
|
1723
1738
|
<ref name="definitions"/>
|
1724
1739
|
<ref name="references"/>
|
1740
|
+
<ref name="floating-title"/>
|
1725
1741
|
</choice>
|
1726
1742
|
</zeroOrMore>
|
1727
1743
|
</group>
|
@@ -1796,6 +1812,20 @@
|
|
1796
1812
|
<data type="ID"/>
|
1797
1813
|
</attribute>
|
1798
1814
|
</optional>
|
1815
|
+
<optional>
|
1816
|
+
<attribute name="language"/>
|
1817
|
+
</optional>
|
1818
|
+
<optional>
|
1819
|
+
<attribute name="script"/>
|
1820
|
+
</optional>
|
1821
|
+
<optional>
|
1822
|
+
<attribute name="tag"/>
|
1823
|
+
</optional>
|
1824
|
+
<optional>
|
1825
|
+
<attribute name="multilingual-rendering">
|
1826
|
+
<ref name="MultilingualRenderingType"/>
|
1827
|
+
</attribute>
|
1828
|
+
</optional>
|
1799
1829
|
<oneOrMore>
|
1800
1830
|
<ref name="preferred"/>
|
1801
1831
|
</oneOrMore>
|
@@ -1959,7 +1989,11 @@
|
|
1959
1989
|
</optional>
|
1960
1990
|
<element name="name">
|
1961
1991
|
<zeroOrMore>
|
1962
|
-
<
|
1992
|
+
<choice>
|
1993
|
+
<ref name="PureTextElement"/>
|
1994
|
+
<ref name="stem"/>
|
1995
|
+
<ref name="index"/>
|
1996
|
+
</choice>
|
1963
1997
|
</zeroOrMore>
|
1964
1998
|
</element>
|
1965
1999
|
<optional>
|
@@ -1973,7 +2007,7 @@
|
|
1973
2007
|
</element>
|
1974
2008
|
</optional>
|
1975
2009
|
<optional>
|
1976
|
-
<element name="grammar
|
2010
|
+
<element name="grammar">
|
1977
2011
|
<ref name="Grammar"/>
|
1978
2012
|
</element>
|
1979
2013
|
</optional>
|
@@ -2516,4 +2550,17 @@
|
|
2516
2550
|
</oneOrMore>
|
2517
2551
|
</element>
|
2518
2552
|
</define>
|
2553
|
+
<define name="floating-title">
|
2554
|
+
<element name="floating-title">
|
2555
|
+
<attribute name="id">
|
2556
|
+
<data type="ID"/>
|
2557
|
+
</attribute>
|
2558
|
+
<attribute name="depth">
|
2559
|
+
<data type="int"/>
|
2560
|
+
</attribute>
|
2561
|
+
<zeroOrMore>
|
2562
|
+
<ref name="TextElement"/>
|
2563
|
+
</zeroOrMore>
|
2564
|
+
</element>
|
2565
|
+
</define>
|
2519
2566
|
</grammar>
|
File without changes
|
File without changes
|
@@ -159,6 +159,20 @@
|
|
159
159
|
<data type="ID"/>
|
160
160
|
</attribute>
|
161
161
|
</optional>
|
162
|
+
<optional>
|
163
|
+
<attribute name="language"/>
|
164
|
+
</optional>
|
165
|
+
<optional>
|
166
|
+
<attribute name="script"/>
|
167
|
+
</optional>
|
168
|
+
<optional>
|
169
|
+
<attribute name="tag"/>
|
170
|
+
</optional>
|
171
|
+
<optional>
|
172
|
+
<attribute name="multilingual-rendering">
|
173
|
+
<ref name="MultilingualRenderingType"/>
|
174
|
+
</attribute>
|
175
|
+
</optional>
|
162
176
|
<ref name="preferred"/>
|
163
177
|
<zeroOrMore>
|
164
178
|
<ref name="admitted"/>
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "htmlentities"
|
2
|
+
require "uri" if /^2\./.match?(RUBY_VERSION)
|
3
|
+
|
4
|
+
module Metanorma
|
5
|
+
module ISO
|
6
|
+
class Converter < Standoc::Converter
|
7
|
+
def clause_parse(attrs, xml, node)
|
8
|
+
node.option? "appendix" and return appendix_parse(attrs, xml, node)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def scope_parse(attrs, xml, node)
|
13
|
+
attrs = attrs.merge(type: "scope") unless @amd
|
14
|
+
clause_parse(attrs, xml, node)
|
15
|
+
end
|
16
|
+
|
17
|
+
def appendix_parse(attrs, xml, node)
|
18
|
+
attrs[:"inline-header"] = node.option? "inline-header"
|
19
|
+
set_obligation(attrs, node)
|
20
|
+
xml.appendix **attr_code(attrs) do |xml_section|
|
21
|
+
xml_section.title { |name| name << node.title }
|
22
|
+
xml_section << node.content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def patent_notice_parse(xml, node)
|
27
|
+
# xml.patent_notice do |xml_section|
|
28
|
+
# xml_section << node.content
|
29
|
+
# end
|
30
|
+
xml << node.content
|
31
|
+
end
|
32
|
+
|
33
|
+
def sectiontype(node, level = true)
|
34
|
+
return nil if @amd
|
35
|
+
|
36
|
+
ret = sectiontype_streamline(sectiontype1(node))
|
37
|
+
return ret if ret == "terms and definitions" && @vocab
|
38
|
+
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def term_def_subclause_parse(attrs, xml, node)
|
43
|
+
node.role == "term" and
|
44
|
+
return term_def_subclause_parse1(attrs, xml, node)
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require "metanorma-standoc"
|
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"
|
7
|
+
require "nokogiri"
|
8
|
+
require "jing"
|
9
|
+
require "iev"
|
10
|
+
|
11
|
+
module Metanorma
|
12
|
+
module ISO
|
13
|
+
class Converter < Standoc::Converter
|
14
|
+
def isosubgroup_validate(root)
|
15
|
+
root.xpath("//technical-committee/@type").each do |t|
|
16
|
+
unless %w{TC PC JTC JPC}.include? t.text
|
17
|
+
@log.add("Document Attributes", nil,
|
18
|
+
"invalid technical committee type #{t}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
root.xpath("//subcommittee/@type").each do |t|
|
22
|
+
unless %w{SC JSC}.include? t.text
|
23
|
+
@log.add("Document Attributes", nil,
|
24
|
+
"invalid subcommittee type #{t}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# ISO/IEC DIR 2, 15.5.3
|
30
|
+
# does not deal with preceding text marked up
|
31
|
+
def see_xrefs_validate(root)
|
32
|
+
root.xpath("//xref").each do |t|
|
33
|
+
preceding = t.at("./preceding-sibling::text()[last()]")
|
34
|
+
next unless !preceding.nil? &&
|
35
|
+
/\b(see| refer to)\s*\Z/mi.match(preceding)
|
36
|
+
|
37
|
+
(target = root.at("//*[@id = '#{t['target']}']")) || next
|
38
|
+
if target&.at("./ancestor-or-self::*[@obligation = 'normative']")
|
39
|
+
@log.add("Style", t,
|
40
|
+
"'see #{t['target']}' is pointing to a normative section")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# ISO/IEC DIR 2, 15.5.3
|
46
|
+
def see_erefs_validate(root)
|
47
|
+
root.xpath("//eref").each do |t|
|
48
|
+
prec = t.at("./preceding-sibling::text()[last()]")
|
49
|
+
next unless !prec.nil? && /\b(see|refer to)\s*\Z/mi.match(prec)
|
50
|
+
|
51
|
+
unless target = root.at("//*[@id = '#{t['bibitemid']}']")
|
52
|
+
@log.add("Bibliography", t,
|
53
|
+
"'#{t} is not pointing to a real reference")
|
54
|
+
next
|
55
|
+
end
|
56
|
+
target.at("./ancestor::references[@normative = 'true']") and
|
57
|
+
@log.add("Style", t,
|
58
|
+
"'see #{t}' is pointing to a normative reference")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# ISO/IEC DIR 2, 10.4
|
63
|
+
def locality_erefs_validate(root)
|
64
|
+
root.xpath("//eref[descendant::locality]").each do |t|
|
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")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def termdef_warn(text, regex, elem, term, msg)
|
75
|
+
regex.match(text) && @log.add("Style", elem, "#{term}: #{msg}")
|
76
|
+
end
|
77
|
+
|
78
|
+
# ISO/IEC DIR 2, 16.5.6
|
79
|
+
def termdef_style(xmldoc)
|
80
|
+
xmldoc.xpath("//term").each do |t|
|
81
|
+
para = t.at("./definition/verbal-definition") || return
|
82
|
+
term = t.at("./preferred//name").text
|
83
|
+
termdef_warn(para.text, /\A(the|a)\b/i, t, term,
|
84
|
+
"term definition starts with article")
|
85
|
+
termdef_warn(para.text, /\.\Z/i, t, term,
|
86
|
+
"term definition ends with period")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def doctype_validate(xmldoc)
|
91
|
+
doctype = xmldoc&.at("//bibdata/ext/doctype")&.text
|
92
|
+
%w(international-standard technical-specification technical-report
|
93
|
+
publicly-available-specification international-workshop-agreement
|
94
|
+
guide amendment technical-corrigendum).include? doctype or
|
95
|
+
@log.add("Document Attributes", nil,
|
96
|
+
"#{doctype} is not a recognised document type")
|
97
|
+
end
|
98
|
+
|
99
|
+
def script_validate(xmldoc)
|
100
|
+
script = xmldoc&.at("//bibdata/script")&.text
|
101
|
+
script == "Latn" or
|
102
|
+
@log.add("Document Attributes", nil,
|
103
|
+
"#{script} is not a recognised script")
|
104
|
+
end
|
105
|
+
|
106
|
+
def stage_validate(xmldoc)
|
107
|
+
stage = xmldoc&.at("//bibdata/status/stage")&.text
|
108
|
+
%w(00 10 20 30 40 50 60 90 95).include? stage or
|
109
|
+
@log.add("Document Attributes", nil,
|
110
|
+
"#{stage} is not a recognised stage")
|
111
|
+
end
|
112
|
+
|
113
|
+
def substage_validate(xmldoc)
|
114
|
+
substage = xmldoc&.at("//bibdata/status/substage")&.text or return
|
115
|
+
%w(00 20 60 90 92 93 98 99).include? substage or
|
116
|
+
@log.add("Document Attributes", nil,
|
117
|
+
"#{substage} is not a recognised substage")
|
118
|
+
end
|
119
|
+
|
120
|
+
def iteration_validate(xmldoc)
|
121
|
+
iteration = xmldoc&.at("//bibdata/status/iteration")&.text or return
|
122
|
+
/^\d+/.match(iteration) or
|
123
|
+
@log.add("Document Attributes", nil,
|
124
|
+
"#{iteration} is not a recognised iteration")
|
125
|
+
end
|
126
|
+
|
127
|
+
def bibdata_validate(doc)
|
128
|
+
doctype_validate(doc)
|
129
|
+
script_validate(doc)
|
130
|
+
stage_validate(doc)
|
131
|
+
substage_validate(doc)
|
132
|
+
iteration_validate(doc)
|
133
|
+
end
|
134
|
+
|
135
|
+
def content_validate(doc)
|
136
|
+
super
|
137
|
+
title_validate(doc.root)
|
138
|
+
isosubgroup_validate(doc.root)
|
139
|
+
onlychild_clause_validate(doc.root)
|
140
|
+
termdef_style(doc.root)
|
141
|
+
see_xrefs_validate(doc.root)
|
142
|
+
see_erefs_validate(doc.root)
|
143
|
+
locality_erefs_validate(doc.root)
|
144
|
+
bibdata_validate(doc.root)
|
145
|
+
bibitem_validate(doc.root)
|
146
|
+
figure_validate(doc.root)
|
147
|
+
end
|
148
|
+
|
149
|
+
def bibitem_validate(xmldoc)
|
150
|
+
xmldoc.xpath("//bibitem[date/on = '–']").each do |b|
|
151
|
+
b.at("./note[@type = 'Unpublished-Status']") or
|
152
|
+
@log.add("Style", b,
|
153
|
+
"Reference #{b&.at('./@id')&.text} does not have an "\
|
154
|
+
"associated footnote indicating unpublished status")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def validate(doc)
|
159
|
+
content_validate(doc)
|
160
|
+
doctype = doc&.at("//bibdata/ext/doctype")&.text
|
161
|
+
schema = case doctype
|
162
|
+
when "amendment", "technical-corrigendum" # @amd
|
163
|
+
"isostandard-amd.rng"
|
164
|
+
else
|
165
|
+
"isostandard.rng"
|
166
|
+
end
|
167
|
+
schema_validate(formattedstr_strip(doc.dup),
|
168
|
+
File.join(File.dirname(__FILE__), schema))
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module ISO
|
3
|
+
class Converter < Standoc::Converter
|
4
|
+
# DRG directives 3.7; but anticipated by standoc
|
5
|
+
def subfigure_validate(xmldoc)
|
6
|
+
xmldoc.xpath("//figure//figure").each do |f|
|
7
|
+
{ footnote: "fn", note: "note", key: "dl" }.each do |k, v|
|
8
|
+
f.xpath(".//#{v}").each do |n|
|
9
|
+
@log.add("Style", n, "#{k} is not permitted in a subfigure")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_name_prefix(xmldoc)
|
16
|
+
std = xmldoc&.at("//bibdata/ext/structuredidentifier/project-number") or
|
17
|
+
return
|
18
|
+
num = xmldoc&.at("//bibdata/docnumber")&.text or return
|
19
|
+
ed = xmldoc&.at("//bibdata/edition")&.text || "1"
|
20
|
+
prefix = num
|
21
|
+
std["part"] and prefix += "-#{std['part']}"
|
22
|
+
prefix += "_ed#{ed}"
|
23
|
+
amd = std["amendment"] and prefix += "amd#{amd}"
|
24
|
+
prefix
|
25
|
+
end
|
26
|
+
|
27
|
+
def image_name_suffix(xmldoc)
|
28
|
+
case xmldoc&.at("//bibdata/language")&.text
|
29
|
+
when "fr" then "_f"
|
30
|
+
when "de" then "_d"
|
31
|
+
when "ru" then "_r"
|
32
|
+
when "es" then "_s"
|
33
|
+
when "ar" then "_a"
|
34
|
+
# when "en" then "_e"
|
35
|
+
else
|
36
|
+
"_e"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def disjunct_error(img, cond1, cond2, msg1, msg2)
|
41
|
+
cond1 && !cond2 and
|
42
|
+
@log.add("Style", img, "image name #{img['src']} #{msg1}")
|
43
|
+
!cond1 && cond2 and
|
44
|
+
@log.add("Style", img, "image name #{img['src']} #{msg2}")
|
45
|
+
end
|
46
|
+
|
47
|
+
def image_name_parse(img, prefix)
|
48
|
+
m = %r[(SL)?#{prefix}fig(?<tab>Tab)?(?<annex>[A-Z])?(Text)?(?<num>\d+)
|
49
|
+
(?<subfig>[a-z])?(?<key>_key\d+)?(?<lang>_[a-z])?$]x
|
50
|
+
.match(File.basename(img["src"], ".*"))
|
51
|
+
m.nil? and
|
52
|
+
@log.add("Style", img,
|
53
|
+
"image name #{img['src']} does not match DRG requirements")
|
54
|
+
m
|
55
|
+
end
|
56
|
+
|
57
|
+
def image_name_validate1(i, prefix)
|
58
|
+
m = image_name_parse(i, prefix) or return
|
59
|
+
warn i["src"]
|
60
|
+
disjunct_error(i, i.at("./ancestor::table"), !m[:tab].nil?,
|
61
|
+
"is under a table but is not so labelled",
|
62
|
+
"is labelled as under a table but is not")
|
63
|
+
disjunct_error(i, i.at("./ancestor::annex"), !m[:annex].nil?,
|
64
|
+
"is under an annex but is not so labelled",
|
65
|
+
"is labelled as under an annex but is not")
|
66
|
+
disjunct_error(i, i.xpath("./ancestor::figure").size > 1, !m[:subfig].nil?,
|
67
|
+
"does not have a subfigure letter but is a subfigure",
|
68
|
+
"has a subfigure letter but is not a subfigure")
|
69
|
+
lang = image_name_suffix(i.document.root)
|
70
|
+
(m[:lang] || "_e") == lang or
|
71
|
+
@log.add("Style", i,
|
72
|
+
"image name #{i['src']} expected to have suffix #{lang}")
|
73
|
+
end
|
74
|
+
|
75
|
+
# DRG directives 3.2
|
76
|
+
def image_name_validate(xmldoc)
|
77
|
+
prefix = image_name_prefix(xmldoc) or return
|
78
|
+
xmldoc.xpath("//image").each do |i|
|
79
|
+
next if i["src"].start_with?("data:")
|
80
|
+
|
81
|
+
if /^ISO_\d+_/.match?(File.basename(i["src"]))
|
82
|
+
elsif /^(SL)?#{prefix}fig/.match?(File.basename(i["src"]))
|
83
|
+
image_name_validate1(i, prefix)
|
84
|
+
else
|
85
|
+
@log.add("Style", i,
|
86
|
+
"image name #{i['src']} does not match DRG requirements: expect #{prefix}fig")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def figure_validate(xmldoc)
|
92
|
+
image_name_validate(xmldoc)
|
93
|
+
subfigure_validate(xmldoc)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|