metanorma-standoc 3.0.4 → 3.0.6
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.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/base.rb +5 -7
- data/lib/metanorma/standoc/basicdoc.rng +14 -8
- data/lib/metanorma/standoc/biblio-standoc.rng +37 -7
- data/lib/metanorma/standoc/biblio.rng +30 -18
- data/lib/metanorma/standoc/blocks.rb +24 -3
- data/lib/metanorma/standoc/cleanup.rb +1 -0
- data/lib/metanorma/standoc/cleanup_bibdata.rb +17 -5
- data/lib/metanorma/standoc/cleanup_inline.rb +3 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +3 -5
- data/lib/metanorma/standoc/cleanup_review.rb +76 -0
- data/lib/metanorma/standoc/cleanup_section.rb +1 -30
- data/lib/metanorma/standoc/cleanup_text.rb +11 -31
- data/lib/metanorma/standoc/cleanup_xref.rb +2 -37
- data/lib/metanorma/standoc/front.rb +6 -3
- data/lib/metanorma/standoc/init.rb +1 -0
- data/lib/metanorma/standoc/inline.rb +0 -1
- data/lib/metanorma/standoc/isodoc.rng +115 -96
- data/lib/metanorma/standoc/lists.rb +1 -0
- data/lib/metanorma/standoc/macros_inline.rb +3 -1
- data/lib/metanorma/standoc/macros_note.rb +0 -1
- data/lib/metanorma/standoc/ref.rb +4 -26
- data/lib/metanorma/standoc/regex.rb +78 -0
- data/lib/metanorma/standoc/reqt.rng +7 -6
- data/lib/metanorma/standoc/terms.rb +2 -9
- data/lib/metanorma/standoc/utils.rb +19 -9
- data/lib/metanorma/standoc/validate.rb +2 -46
- data/lib/metanorma/standoc/validate_schema.rb +104 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- metadata +5 -2
@@ -1,24 +1,27 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!--
|
3
|
-
instantiations of this grammar may replace leaf strings
|
4
|
-
with more elaborated types; e.g. title (text) replaced with
|
5
|
-
title-main, title-intro, title-part; type replaced with
|
6
|
-
enum.
|
7
|
-
|
8
|
-
some renaming at leaf nodes is permissible
|
9
|
-
|
10
|
-
obligations can change both from optional to mandatory,
|
11
|
-
and from mandatory to optional; optional elements may
|
12
|
-
be omitted; freely positioned alternatives may be replaced
|
13
|
-
with strict ordering
|
14
|
-
|
15
|
-
DO NOT introduce a namespace here. We do not want a distinct namespace
|
16
|
-
for these elements, and a distinct namespace for any grammar inheriting
|
17
|
-
these elements; we just want one namespace for any child grammars
|
18
|
-
of this.
|
19
|
-
-->
|
20
|
-
<!-- VERSION v2.0.2 -->
|
21
2
|
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
+
<!-- VERSION v2.0.3 -->
|
4
|
+
|
5
|
+
<!--
|
6
|
+
ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437
|
7
|
+
|
8
|
+
instantiations of this grammar may replace leaf strings
|
9
|
+
with more elaborated types; e.g. title (text) replaced with
|
10
|
+
title-main, title-intro, title-part; type replaced with
|
11
|
+
enum.
|
12
|
+
|
13
|
+
some renaming at leaf nodes is permissible
|
14
|
+
|
15
|
+
obligations can change both from optional to mandatory,
|
16
|
+
and from mandatory to optional; optional elements may
|
17
|
+
be omitted; freely positioned alternatives may be replaced
|
18
|
+
with strict ordering
|
19
|
+
|
20
|
+
DO NOT introduce a namespace here. We do not want a distinct namespace
|
21
|
+
for these elements, and a distinct namespace for any grammar inheriting
|
22
|
+
these elements; we just want one namespace for any child grammars
|
23
|
+
of this.
|
24
|
+
-->
|
22
25
|
<include href="reqt.rng"/>
|
23
26
|
<include href="basicdoc.rng">
|
24
27
|
<define name="amend">
|
@@ -33,15 +36,6 @@
|
|
33
36
|
</zeroOrMore>
|
34
37
|
</element>
|
35
38
|
</define>
|
36
|
-
<define name="fn" combine="interleave">
|
37
|
-
<optional>
|
38
|
-
<attribute name="hiddenref">
|
39
|
-
<a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
|
40
|
-
This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
|
41
|
-
<data type="boolean"/>
|
42
|
-
</attribute>
|
43
|
-
</optional>
|
44
|
-
</define>
|
45
39
|
<define name="index-primary">
|
46
40
|
<element name="primary">
|
47
41
|
<oneOrMore>
|
@@ -423,20 +417,12 @@ normative or informative references, some split references into sections organiz
|
|
423
417
|
</oneOrMore>
|
424
418
|
</choice>
|
425
419
|
</define>
|
426
|
-
<define name="TdAttributes" combine="interleave">
|
427
|
-
<attribute name="style">
|
428
|
-
<a:documentation>CSS style: only background-color supported</a:documentation>
|
429
|
-
</attribute>
|
430
|
-
</define>
|
431
|
-
<define name="ThAttributes" combine="interleave">
|
432
|
-
<attribute name="style">
|
433
|
-
<a:documentation>CSS style: only background-color supported</a:documentation>
|
434
|
-
</attribute>
|
435
|
-
</define>
|
436
420
|
<define name="TrAttributes">
|
437
|
-
<
|
438
|
-
<
|
439
|
-
|
421
|
+
<optional>
|
422
|
+
<attribute name="style">
|
423
|
+
<a:documentation>CSS style: only background-color supported</a:documentation>
|
424
|
+
</attribute>
|
425
|
+
</optional>
|
440
426
|
</define>
|
441
427
|
<define name="table-note">
|
442
428
|
<element name="note">
|
@@ -500,6 +486,22 @@ gives an explicit page orientation</a:documentation>
|
|
500
486
|
</define>
|
501
487
|
</include>
|
502
488
|
<!-- end overrides -->
|
489
|
+
<define name="FnAttributes" combine="interleave">
|
490
|
+
<optional>
|
491
|
+
<attribute name="hiddenref">
|
492
|
+
<a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
|
493
|
+
This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
|
494
|
+
<data type="boolean"/>
|
495
|
+
</attribute>
|
496
|
+
</optional>
|
497
|
+
</define>
|
498
|
+
<define name="TdAttributes" combine="interleave">
|
499
|
+
<optional>
|
500
|
+
<attribute name="style">
|
501
|
+
<a:documentation>CSS style: only background-color supported</a:documentation>
|
502
|
+
</attribute>
|
503
|
+
</optional>
|
504
|
+
</define>
|
503
505
|
<define name="NumberingAttributes" combine="interleave">
|
504
506
|
<optional>
|
505
507
|
<attribute name="number">
|
@@ -678,6 +680,13 @@ titlecase, or lowercase</a:documentation>
|
|
678
680
|
</attribute>
|
679
681
|
</optional>
|
680
682
|
</define>
|
683
|
+
<define name="Basic-Section-Attributes" combine="interleave">
|
684
|
+
<optional>
|
685
|
+
<attribute name="obligation">
|
686
|
+
<ref name="ObligationType"/>
|
687
|
+
</attribute>
|
688
|
+
</optional>
|
689
|
+
</define>
|
681
690
|
<define name="ObligationType">
|
682
691
|
<a:documentation>The force of a clause in a standard document: whether it has normative or informative effect</a:documentation>
|
683
692
|
<choice>
|
@@ -1192,13 +1201,6 @@ numbers</a:documentation>
|
|
1192
1201
|
</attribute>
|
1193
1202
|
</optional>
|
1194
1203
|
</define>
|
1195
|
-
<define name="Basic-Section-Attributes" combine="interleave">
|
1196
|
-
<optional>
|
1197
|
-
<attribute name="obligation">
|
1198
|
-
<ref name="ObligationType"/>
|
1199
|
-
</attribute>
|
1200
|
-
</optional>
|
1201
|
-
</define>
|
1202
1204
|
<define name="reference-clause">
|
1203
1205
|
<a:documentation>References clause with recursive nesting</a:documentation>
|
1204
1206
|
<element name="clause">
|
@@ -1239,7 +1241,7 @@ numbers</a:documentation>
|
|
1239
1241
|
</choice>
|
1240
1242
|
</attribute>
|
1241
1243
|
<attribute name="flavor">
|
1242
|
-
<a:documentation>Metanorma flavor, indicating SDO whose
|
1244
|
+
<a:documentation>Metanorma flavor, indicating SDO whose requirements the realisation aligns to</a:documentation>
|
1243
1245
|
</attribute>
|
1244
1246
|
</define>
|
1245
1247
|
<define name="standard-document">
|
@@ -1249,6 +1251,11 @@ numbers</a:documentation>
|
|
1249
1251
|
<ref name="bibdata">
|
1250
1252
|
<a:documentation>Bibliographic description of the document itself, expressed in the Relaton model</a:documentation>
|
1251
1253
|
</ref>
|
1254
|
+
<zeroOrMore>
|
1255
|
+
<ref name="termdocsource">
|
1256
|
+
<a:documentation>Source for term definitions in the document</a:documentation>
|
1257
|
+
</ref>
|
1258
|
+
</zeroOrMore>
|
1252
1259
|
<optional>
|
1253
1260
|
<ref name="misccontainer">
|
1254
1261
|
<a:documentation>Extension point for extraneous elements that need to be added to standards document as data</a:documentation>
|
@@ -1259,34 +1266,7 @@ numbers</a:documentation>
|
|
1259
1266
|
<a:documentation>Front matter that is repeated at the start of documents issued from an SDO, with content not specific to the document</a:documentation>
|
1260
1267
|
</ref>
|
1261
1268
|
</optional>
|
1262
|
-
<
|
1263
|
-
<ref name="preface">
|
1264
|
-
<a:documentation>Prefatory sections</a:documentation>
|
1265
|
-
</ref>
|
1266
|
-
</optional>
|
1267
|
-
<ref name="sections">
|
1268
|
-
<a:documentation>Main body of document</a:documentation>
|
1269
|
-
</ref>
|
1270
|
-
<zeroOrMore>
|
1271
|
-
<ref name="annex">
|
1272
|
-
<a:documentation>Annex sections</a:documentation>
|
1273
|
-
</ref>
|
1274
|
-
</zeroOrMore>
|
1275
|
-
<optional>
|
1276
|
-
<ref name="bibliography">
|
1277
|
-
<a:documentation>Bibliographic sections</a:documentation>
|
1278
|
-
</ref>
|
1279
|
-
</optional>
|
1280
|
-
<zeroOrMore>
|
1281
|
-
<ref name="indexsect">
|
1282
|
-
<a:documentation>Index of the document</a:documentation>
|
1283
|
-
</ref>
|
1284
|
-
</zeroOrMore>
|
1285
|
-
<optional>
|
1286
|
-
<ref name="colophon">
|
1287
|
-
<a:documentation>Colophon or postface material</a:documentation>
|
1288
|
-
</ref>
|
1289
|
-
</optional>
|
1269
|
+
<ref name="DocumentBody"/>
|
1290
1270
|
<optional>
|
1291
1271
|
<ref name="review-container">
|
1292
1272
|
<a:documentation>Annotations to the document</a:documentation>
|
@@ -1294,6 +1274,36 @@ numbers</a:documentation>
|
|
1294
1274
|
</optional>
|
1295
1275
|
</element>
|
1296
1276
|
</define>
|
1277
|
+
<define name="DocumentBody">
|
1278
|
+
<optional>
|
1279
|
+
<ref name="preface">
|
1280
|
+
<a:documentation>Prefatory sections</a:documentation>
|
1281
|
+
</ref>
|
1282
|
+
</optional>
|
1283
|
+
<ref name="sections">
|
1284
|
+
<a:documentation>Main body of document</a:documentation>
|
1285
|
+
</ref>
|
1286
|
+
<zeroOrMore>
|
1287
|
+
<ref name="annex">
|
1288
|
+
<a:documentation>Annex sections</a:documentation>
|
1289
|
+
</ref>
|
1290
|
+
</zeroOrMore>
|
1291
|
+
<optional>
|
1292
|
+
<ref name="bibliography">
|
1293
|
+
<a:documentation>Bibliographic sections</a:documentation>
|
1294
|
+
</ref>
|
1295
|
+
</optional>
|
1296
|
+
<zeroOrMore>
|
1297
|
+
<ref name="indexsect">
|
1298
|
+
<a:documentation>Index of the document</a:documentation>
|
1299
|
+
</ref>
|
1300
|
+
</zeroOrMore>
|
1301
|
+
<optional>
|
1302
|
+
<ref name="colophon">
|
1303
|
+
<a:documentation>Colophon or postface material</a:documentation>
|
1304
|
+
</ref>
|
1305
|
+
</optional>
|
1306
|
+
</define>
|
1297
1307
|
<define name="misccontainer">
|
1298
1308
|
<a:documentation>Elements added to metanorma-extension are open-ended, and constitute source data</a:documentation>
|
1299
1309
|
<element name="metanorma-extension">
|
@@ -1608,9 +1618,7 @@ used in document amendments</a:documentation>
|
|
1608
1618
|
<define name="term">
|
1609
1619
|
<a:documentation>Terminology entry with its definition</a:documentation>
|
1610
1620
|
<element name="term">
|
1611
|
-
<ref name="
|
1612
|
-
<ref name="LocalizedStringAttributes"/>
|
1613
|
-
<ref name="BlockAttributes"/>
|
1621
|
+
<ref name="TermAttributes"/>
|
1614
1622
|
<oneOrMore>
|
1615
1623
|
<ref name="preferred">
|
1616
1624
|
<a:documentation>One or more names under which the term being defined is canonically known</a:documentation>
|
@@ -1662,6 +1670,11 @@ used in document amendments</a:documentation>
|
|
1662
1670
|
</ref>
|
1663
1671
|
</element>
|
1664
1672
|
</define>
|
1673
|
+
<define name="TermAttributes">
|
1674
|
+
<ref name="OptionalId"/>
|
1675
|
+
<ref name="LocalizedStringAttributes"/>
|
1676
|
+
<ref name="BlockAttributes"/>
|
1677
|
+
</define>
|
1665
1678
|
<define name="preferred">
|
1666
1679
|
<element name="preferred">
|
1667
1680
|
<ref name="Designation"/>
|
@@ -2323,26 +2336,32 @@ links within an SVG file, so that the SVG file can hyperlink to anchors within t
|
|
2323
2336
|
</element>
|
2324
2337
|
</define>
|
2325
2338
|
<define name="ul_li">
|
2326
|
-
<a:documentation>
|
2339
|
+
<a:documentation>Unordered list item for standards documents</a:documentation>
|
2327
2340
|
<element name="li">
|
2328
2341
|
<ref name="OptionalId"/>
|
2329
|
-
<
|
2330
|
-
|
2331
|
-
<a:documentation>Include a checkbox for the list item</a:documentation>
|
2332
|
-
<data type="boolean"/>
|
2333
|
-
</attribute>
|
2334
|
-
</optional>
|
2335
|
-
<optional>
|
2336
|
-
<attribute name="checkedcheckbox">
|
2337
|
-
<a:documentation>Check the checkbox for the list item</a:documentation>
|
2338
|
-
<data type="boolean"/>
|
2339
|
-
</attribute>
|
2340
|
-
</optional>
|
2341
|
-
<oneOrMore>
|
2342
|
-
<ref name="BasicBlock"/>
|
2343
|
-
</oneOrMore>
|
2342
|
+
<ref name="UlLiAttributes"/>
|
2343
|
+
<ref name="UlLiBody"/>
|
2344
2344
|
</element>
|
2345
2345
|
</define>
|
2346
|
+
<define name="UlLiBody">
|
2347
|
+
<oneOrMore>
|
2348
|
+
<ref name="BasicBlock"/>
|
2349
|
+
</oneOrMore>
|
2350
|
+
</define>
|
2351
|
+
<define name="UlLiAttributes">
|
2352
|
+
<optional>
|
2353
|
+
<attribute name="uncheckedcheckbox">
|
2354
|
+
<a:documentation>Include a checkbox for the list item</a:documentation>
|
2355
|
+
<data type="boolean"/>
|
2356
|
+
</attribute>
|
2357
|
+
</optional>
|
2358
|
+
<optional>
|
2359
|
+
<attribute name="checkedcheckbox">
|
2360
|
+
<a:documentation>Check the checkbox for the list item</a:documentation>
|
2361
|
+
<data type="boolean"/>
|
2362
|
+
</attribute>
|
2363
|
+
</optional>
|
2364
|
+
</define>
|
2346
2365
|
<define name="floating-title">
|
2347
2366
|
<a:documentation>A floating title, outside of the clause hierarchy of the document</a:documentation>
|
2348
2367
|
<element name="floating-title">
|
@@ -114,10 +114,12 @@ module Metanorma
|
|
114
114
|
class PassInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
115
115
|
use_dsl
|
116
116
|
named :"pass-format"
|
117
|
+
parse_content_as :text
|
117
118
|
|
118
119
|
def process(parent, target, attrs)
|
120
|
+
#require "debug"; binding.b
|
119
121
|
format = target || "metanorma"
|
120
|
-
out = Asciidoctor::Inline.new(parent, :quoted, attrs[
|
122
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
121
123
|
.gsub(/((?![<>&])[[:punct:]])/, "\\1‌")
|
122
124
|
%{<passthrough-inline formats="#{format}">#{out}</passthrough-inline>}
|
123
125
|
end
|
@@ -67,7 +67,7 @@ module Metanorma
|
|
67
67
|
iso_publisher(t, match[:code])
|
68
68
|
unless match[:fn].nil?
|
69
69
|
t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
|
70
|
-
p <<
|
70
|
+
p << match[:fn].to_s
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -99,7 +99,7 @@ module Metanorma
|
|
99
99
|
iso_publisher(t, match[:code])
|
100
100
|
if match.names.include?("fn") && match[:fn]
|
101
101
|
t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
|
102
|
-
p <<
|
102
|
+
p << match[:fn].to_s
|
103
103
|
end
|
104
104
|
end
|
105
105
|
t.extent type: "part" do |e|
|
@@ -184,30 +184,6 @@ module Metanorma
|
|
184
184
|
use_retrieved_relaton(item, xml)
|
185
185
|
end
|
186
186
|
|
187
|
-
ISO_REF =
|
188
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
189
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
190
|
-
(?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
|
191
|
-
|
192
|
-
ISO_REF_NO_YEAR =
|
193
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
194
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
|
195
|
-
(?:--|–|—|&\#821[12];)\]</ref>,?\s*
|
196
|
-
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
197
|
-
|
198
|
-
ISO_REF_ALL_PARTS =
|
199
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
200
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
|
201
|
-
(?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
|
202
|
-
\(all\sparts\)\]</ref>,?\s*
|
203
|
-
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
|
204
|
-
|
205
|
-
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
206
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
|
207
|
-
|
208
|
-
NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
|
209
|
-
(?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
|
210
|
-
|
211
187
|
def reference1_matches(item)
|
212
188
|
matched = ISO_REF.match item
|
213
189
|
matched2 = ISO_REF_NO_YEAR.match item
|
@@ -233,6 +209,8 @@ module Metanorma
|
|
233
209
|
when 3 then isorefmatches3out(item, xml)
|
234
210
|
end
|
235
211
|
end
|
212
|
+
|
213
|
+
include ::Metanorma::Standoc::Regex
|
236
214
|
end
|
237
215
|
end
|
238
216
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Standoc
|
3
|
+
module Regex
|
4
|
+
# https://medium.com/@rickwang_wxc/in-ruby-given-a-string-detect-if-it-is-valid-numeric-c58275eace60
|
5
|
+
NUMERIC_REGEX = %r{\A((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?\Z}
|
6
|
+
|
7
|
+
# extending localities to cover ISO referencing
|
8
|
+
CONN_REGEX_STR = "(?<conn>and|or|from|to)!".freeze
|
9
|
+
|
10
|
+
LOCALITIES = "section|clause|part|paragraph|chapter|page|line|" \
|
11
|
+
"table|annex|figure|example|note|formula|list|time|anchor|" \
|
12
|
+
"locality:[^ \\t\\n\\r:,;=]+".freeze
|
13
|
+
|
14
|
+
LOCALITY_REGEX_STR = <<~REGEXP.freeze
|
15
|
+
^((#{CONN_REGEX_STR})?
|
16
|
+
(?<locality>#{LOCALITIES})(\\s+|=)
|
17
|
+
(?<ref>[^"][^ \\t\\n,:;-]*|"[^"]+")
|
18
|
+
(-(?<to>[^"][^ \\t\\n,:;-]*|"[^"]"))?|
|
19
|
+
(?<locality2>whole|title|locality:[^ \\t\\n\\r:,;=]+))(?<punct>[,:;]?)\\s*
|
20
|
+
(?<text>.*)$
|
21
|
+
REGEXP
|
22
|
+
|
23
|
+
def to_regex(str)
|
24
|
+
Regexp.new(str.gsub(/\s/, ""), Regexp::IGNORECASE | Regexp::MULTILINE)
|
25
|
+
end
|
26
|
+
|
27
|
+
LOCALITY_REGEX_VALUE_ONLY_STR = <<~REGEXP.freeze
|
28
|
+
^(?<conn0>(#{CONN_REGEX_STR}))
|
29
|
+
(?!whole|title|locality:)
|
30
|
+
(?<value>[^=,;:\\t\\n\\r]+)
|
31
|
+
(?<punct>[,;\\t\\n\\r]|$)
|
32
|
+
REGEXP
|
33
|
+
|
34
|
+
LOCALITY_REGEX_STR_TRIPLEDASH = <<~REGEXP.freeze
|
35
|
+
^(?<locality>(#{CONN_REGEX_STR})?
|
36
|
+
(#{LOCALITIES})(\\s+|=))
|
37
|
+
(?<ref>[^"][^ \\t\\n,:;-]*
|
38
|
+
-[^ \\t\\n,:;"-]+
|
39
|
+
-[^ \\t\\n,:;"]+)
|
40
|
+
(?<text>[,:;]?\\s*
|
41
|
+
.*)$
|
42
|
+
REGEXP
|
43
|
+
|
44
|
+
TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
|
45
|
+
^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)
|
46
|
+
(,\s(?<text>.*))?
|
47
|
+
$
|
48
|
+
REGEXP
|
49
|
+
TERM_REFERENCE_RE =
|
50
|
+
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
|
51
|
+
Regexp::IGNORECASE | Regexp::MULTILINE)
|
52
|
+
|
53
|
+
ISO_REF =
|
54
|
+
%r{^<ref\sid="(?<anchor>[^"]+)">
|
55
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
56
|
+
(?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
|
57
|
+
|
58
|
+
ISO_REF_NO_YEAR =
|
59
|
+
%r{^<ref\sid="(?<anchor>[^"]+)">
|
60
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
|
61
|
+
(?:--|–|—|&\#821[12];)\]</ref>,?\s*
|
62
|
+
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
63
|
+
|
64
|
+
ISO_REF_ALL_PARTS =
|
65
|
+
%r{^<ref\sid="(?<anchor>[^"]+)">
|
66
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
|
67
|
+
(?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
|
68
|
+
\(all\sparts\)\]</ref>,?\s*
|
69
|
+
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
|
70
|
+
|
71
|
+
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
72
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
|
73
|
+
|
74
|
+
NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
|
75
|
+
(?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
+
<define name="requirement">
|
4
|
+
<element name="requirement">
|
5
|
+
<ref name="RequirementType"/>
|
6
|
+
</element>
|
7
|
+
</define>
|
8
|
+
<!-- ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437 -->
|
3
9
|
<!--
|
4
10
|
Presupposes isodoc.rnc, is included in it
|
5
11
|
include "isodoc.rnc" { }
|
@@ -7,14 +13,9 @@
|
|
7
13
|
This is the Metanorma default provisions model; it is overridden by other provisions models,
|
8
14
|
such as Modspec
|
9
15
|
-->
|
10
|
-
<define name="
|
16
|
+
<define name="recommendation">
|
11
17
|
<a:documentation>Specification of an attribute of a subject that is required.
|
12
18
|
NOTE: A requirement can contain other requirements</a:documentation>
|
13
|
-
<element name="requirement">
|
14
|
-
<ref name="RequirementType"/>
|
15
|
-
</element>
|
16
|
-
</define>
|
17
|
-
<define name="recommendation">
|
18
19
|
<a:documentation>Specification of an attribute of a subject that is recommended</a:documentation>
|
19
20
|
<element name="recommendation">
|
20
21
|
<ref name="RequirementType"/>
|
@@ -140,15 +140,6 @@ module Metanorma
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
|
144
|
-
^(?<xref><(xref|concept)[^>]+>(.*?</(xref|concept)>)?)
|
145
|
-
(,\s(?<text>.*))?
|
146
|
-
$
|
147
|
-
REGEXP
|
148
|
-
TERM_REFERENCE_RE =
|
149
|
-
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
|
150
|
-
Regexp::IGNORECASE | Regexp::MULTILINE)
|
151
|
-
|
152
143
|
def extract_termsource_refs(text, node)
|
153
144
|
matched = TERM_REFERENCE_RE.match text
|
154
145
|
matched.nil? and @log.add("AsciiDoc Input", node,
|
@@ -180,6 +171,8 @@ module Metanorma
|
|
180
171
|
end
|
181
172
|
end
|
182
173
|
end
|
174
|
+
|
175
|
+
include ::Metanorma::Standoc::Regex
|
183
176
|
end
|
184
177
|
end
|
185
178
|
end
|
@@ -40,16 +40,18 @@ module Metanorma
|
|
40
40
|
.map { |x| @c.encode(x, :basic, :hexadecimal) }
|
41
41
|
end
|
42
42
|
|
43
|
+
# quoted strings: key="va,lue",
|
43
44
|
def quoted_csv_split(text, delim = ",", eql = "=")
|
44
|
-
# quoted strings: key="va,lue",
|
45
45
|
c = HTMLEntities.new
|
46
|
-
text = c.decode(text).gsub(/([a-zA-Z_]+)#{eql}(["'])(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
text = c.decode(text).gsub(/([a-zA-Z_]+)#{eql}(["'])(.*?)\2/) do |_|
|
47
|
+
key = Regexp.last_match(1)
|
48
|
+
value = Regexp.last_match(3).gsub(" ", " ")
|
49
|
+
"\"#{key}#{eql}#{value}\""
|
50
|
+
end
|
51
|
+
Metanorma::Utils::csv_split(text, delim).map do |x|
|
52
|
+
c.encode(x.sub(/^(["'])(.*?)\1$/, "\\2"),
|
53
|
+
:basic, :hexadecimal)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
def kv_parse(text, delim = ",", eql = "=")
|
@@ -100,6 +102,14 @@ module Metanorma
|
|
100
102
|
para
|
101
103
|
end
|
102
104
|
|
105
|
+
def insert_before(xmldoc, xpath)
|
106
|
+
unless ins = xmldoc.at(xpath).children.first
|
107
|
+
xmldoc.at(xpath) << " "
|
108
|
+
ins = xmldoc.at(xpath).children.first
|
109
|
+
end
|
110
|
+
ins
|
111
|
+
end
|
112
|
+
|
103
113
|
def xml_encode(text)
|
104
114
|
@c.encode(text, :basic, :hexadecimal)
|
105
115
|
.gsub("&gt;", ">").gsub("&lt;", "<").gsub("&amp;", "&")
|
@@ -110,7 +120,7 @@ module Metanorma
|
|
110
120
|
|
111
121
|
SECTION_CONTAINERS =
|
112
122
|
%w(foreword introduction acknowledgements abstract
|
113
|
-
clause references terms definitions annex appendix indexsect
|
123
|
+
clause references terms definitions annex appendix indexsect
|
114
124
|
executivesummary).freeze
|
115
125
|
|
116
126
|
def section_containers
|
@@ -2,8 +2,8 @@ require "metanorma/standoc/utils"
|
|
2
2
|
require_relative "validate_section"
|
3
3
|
require_relative "validate_table"
|
4
4
|
require_relative "validate_term"
|
5
|
+
require_relative "validate_schema"
|
5
6
|
require "nokogiri"
|
6
|
-
require "jing"
|
7
7
|
require "iev"
|
8
8
|
require "pngcheck"
|
9
9
|
|
@@ -98,49 +98,6 @@ module Metanorma
|
|
98
98
|
@log.add("Style", i, err2)
|
99
99
|
end
|
100
100
|
|
101
|
-
def schema_validate(doc, schema)
|
102
|
-
Tempfile.open(["tmp", ".xml"], encoding: "UTF-8") do |f|
|
103
|
-
schema_validate1(f, doc, schema)
|
104
|
-
rescue Jing::Error => e
|
105
|
-
clean_abort("Jing failed with error: #{e}", doc)
|
106
|
-
ensure
|
107
|
-
f.close!
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def schema_validate1(file, doc, schema)
|
112
|
-
file.write(to_xml(doc))
|
113
|
-
file.close
|
114
|
-
errors = Jing.new(schema, encoding: "UTF-8").validate(file.path)
|
115
|
-
warn "Syntax Valid!" if errors.none?
|
116
|
-
errors.each do |e|
|
117
|
-
@log.add("Metanorma XML Syntax",
|
118
|
-
"XML Line #{'%06d' % e[:line]}:#{e[:column]}", e[:message])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
SVG_NS = "http://www.w3.org/2000/svg".freeze
|
123
|
-
|
124
|
-
WILDCARD_ATTRS =
|
125
|
-
"//*[@format] | //stem | //bibdata//description | " \
|
126
|
-
"//formattedref | //bibdata//note | //bibdata/abstract | " \
|
127
|
-
"//bibitem/abstract | //bibitem/note | //metanorma-extension".freeze
|
128
|
-
|
129
|
-
# RelaxNG cannot cope well with wildcard attributes. So we strip
|
130
|
-
# any attributes from FormattedString instances (which can contain
|
131
|
-
# xs:any markup, and are signalled with @format) before validation.
|
132
|
-
def formattedstr_strip(doc)
|
133
|
-
doc.xpath(WILDCARD_ATTRS, "m" => SVG_NS).each do |n|
|
134
|
-
n.elements.each do |e|
|
135
|
-
e.traverse do |e1|
|
136
|
-
e1.element? and e1.each { |k, _v| e1.delete(k) } # rubocop:disable Style/HashEachMethods
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
doc.xpath("//m:svg", "m" => SVG_NS).each { |n| n.replace("<svg/>") }
|
141
|
-
doc
|
142
|
-
end
|
143
|
-
|
144
101
|
def image_validate(doc)
|
145
102
|
image_exists(doc)
|
146
103
|
image_toobig(doc)
|
@@ -198,8 +155,7 @@ module Metanorma
|
|
198
155
|
|
199
156
|
def validate(doc)
|
200
157
|
content_validate(doc)
|
201
|
-
schema_validate(formattedstr_strip(doc.dup),
|
202
|
-
File.join(File.dirname(__FILE__), "isodoc-compile.rng"))
|
158
|
+
schema_validate(formattedstr_strip(doc.dup), schema_location)
|
203
159
|
end
|
204
160
|
|
205
161
|
def repeat_id_validate1(elem)
|