metanorma-standoc 3.0.3 → 3.0.5
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/isodoc/html/htmlstyle.css +7 -0
- data/lib/metanorma/standoc/base.rb +5 -7
- data/lib/metanorma/standoc/basicdoc.rng +48 -35
- data/lib/metanorma/standoc/biblio-standoc.rng +37 -7
- data/lib/metanorma/standoc/biblio.rng +30 -18
- data/lib/metanorma/standoc/blocks.rb +21 -1
- data/lib/metanorma/standoc/cleanup.rb +2 -0
- data/lib/metanorma/standoc/cleanup_bibdata.rb +17 -5
- data/lib/metanorma/standoc/cleanup_block.rb +1 -1
- data/lib/metanorma/standoc/cleanup_inline.rb +7 -6
- data/lib/metanorma/standoc/cleanup_maths.rb +2 -3
- data/lib/metanorma/standoc/cleanup_review.rb +60 -0
- data/lib/metanorma/standoc/cleanup_section.rb +3 -38
- data/lib/metanorma/standoc/cleanup_section_names.rb +25 -0
- data/lib/metanorma/standoc/cleanup_table.rb +22 -0
- data/lib/metanorma/standoc/cleanup_text.rb +11 -31
- data/lib/metanorma/standoc/cleanup_xref.rb +2 -37
- data/lib/metanorma/standoc/converter.rb +2 -0
- 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 +126 -80
- data/lib/metanorma/standoc/macros_inline.rb +27 -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/section.rb +1 -1
- data/lib/metanorma/standoc/terms.rb +2 -9
- data/lib/metanorma/standoc/utils.rb +8 -0
- 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
- data/metanorma-standoc.gemspec +2 -2
- metadata +9 -7
- data/Gemfile.devel +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e924f78d6a7faa7600c28fc8c620014dd16ea0246ab146fdbc96a3053a7763
|
4
|
+
data.tar.gz: 903657557475a6c7dde6657427f2a56456ad10c7587c40981cca2429b9f44e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 183934838205bfca5d8d94bd540eefc23e6fcf552086f730d779e1fc4e7b2b292bbf10fd934f281336ad999c4bd9331444f729d825319ee5be5945a1c26f8147
|
7
|
+
data.tar.gz: 2a859472f86af39724db162280a4e3aff7775a88398e1b859a81cc7fa982eab255f5b7e60100d7ad143cfa3f2535093f201bd3446984474e949d8932bc8497e2
|
@@ -11,30 +11,28 @@ require_relative "localbib"
|
|
11
11
|
require_relative "init"
|
12
12
|
require "mn-requirements"
|
13
13
|
|
14
|
-
require 'set'
|
15
|
-
|
16
14
|
module Asciidoctor
|
17
15
|
module Compliance
|
18
|
-
ADMONITION_STYLES.add(
|
16
|
+
ADMONITION_STYLES.add("EDITOR") unless ADMONITION_STYLES.include?("EDITOR")
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
module Metanorma
|
23
21
|
module Standoc
|
24
22
|
module Base
|
25
|
-
#XML_ROOT_TAG = "standard-document".freeze
|
26
|
-
#XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
|
23
|
+
# XML_ROOT_TAG = "standard-document".freeze
|
24
|
+
# XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
|
27
25
|
FONTS_MANIFEST = "fonts-manifest".freeze
|
28
26
|
|
29
27
|
attr_accessor :log
|
30
28
|
|
31
29
|
def xml_root_tag
|
32
|
-
#self.class::XML_ROOT_TAG
|
30
|
+
# self.class::XML_ROOT_TAG
|
33
31
|
"metanorma"
|
34
32
|
end
|
35
33
|
|
36
34
|
def xml_namespace
|
37
|
-
#self.class::XML_NAMESPACE
|
35
|
+
# self.class::XML_NAMESPACE
|
38
36
|
"https://www.metanorma.org/ns/standoc"
|
39
37
|
end
|
40
38
|
|
@@ -382,33 +382,7 @@ in a document (e.g. sourcecode annotations)</a:documentation>
|
|
382
382
|
<a:documentation>Block intended to capture reviewer comments about some text in the document</a:documentation>
|
383
383
|
<element name="review">
|
384
384
|
<ref name="RequiredId"/>
|
385
|
-
<
|
386
|
-
<a:documentation>The party who has offered the comment</a:documentation>
|
387
|
-
</attribute>
|
388
|
-
<optional>
|
389
|
-
<attribute name="type">
|
390
|
-
<a:documentation>The type of reviewer comment</a:documentation>
|
391
|
-
</attribute>
|
392
|
-
</optional>
|
393
|
-
<optional>
|
394
|
-
<attribute name="date">
|
395
|
-
<a:documentation>The date when the comment was made</a:documentation>
|
396
|
-
<data type="dateTime"/>
|
397
|
-
</attribute>
|
398
|
-
</optional>
|
399
|
-
<optional>
|
400
|
-
<attribute name="from">
|
401
|
-
<a:documentation>Identifier for the start of the text or point in the text to which the comment applies.
|
402
|
-
If not provided, the comment applies in the vicinity of the place it has been inserted into the text</a:documentation>
|
403
|
-
<data type="IDREF"/>
|
404
|
-
</attribute>
|
405
|
-
</optional>
|
406
|
-
<optional>
|
407
|
-
<attribute name="to">
|
408
|
-
<a:documentation>Identifier for the end of the text to which the comment applies</a:documentation>
|
409
|
-
<data type="IDREF"/>
|
410
|
-
</attribute>
|
411
|
-
</optional>
|
385
|
+
<ref name="ReviewAttributes"/>
|
412
386
|
<oneOrMore>
|
413
387
|
<ref name="paragraph">
|
414
388
|
<a:documentation>Reviewer comments content</a:documentation>
|
@@ -416,6 +390,35 @@ If not provided, the comment applies in the vicinity of the place it has been in
|
|
416
390
|
</oneOrMore>
|
417
391
|
</element>
|
418
392
|
</define>
|
393
|
+
<define name="ReviewAttributes">
|
394
|
+
<attribute name="reviewer">
|
395
|
+
<a:documentation>The party who has offered the comment</a:documentation>
|
396
|
+
</attribute>
|
397
|
+
<optional>
|
398
|
+
<attribute name="type">
|
399
|
+
<a:documentation>The type of reviewer comment</a:documentation>
|
400
|
+
</attribute>
|
401
|
+
</optional>
|
402
|
+
<optional>
|
403
|
+
<attribute name="date">
|
404
|
+
<a:documentation>The date when the comment was made</a:documentation>
|
405
|
+
<data type="dateTime"/>
|
406
|
+
</attribute>
|
407
|
+
</optional>
|
408
|
+
<optional>
|
409
|
+
<attribute name="from">
|
410
|
+
<a:documentation>Identifier for the start of the text or point in the text to which the comment applies.
|
411
|
+
If not provided, the comment applies in the vicinity of the place it has been inserted into the text</a:documentation>
|
412
|
+
<data type="IDREF"/>
|
413
|
+
</attribute>
|
414
|
+
</optional>
|
415
|
+
<optional>
|
416
|
+
<attribute name="to">
|
417
|
+
<a:documentation>Identifier for the end of the text to which the comment applies</a:documentation>
|
418
|
+
<data type="IDREF"/>
|
419
|
+
</attribute>
|
420
|
+
</optional>
|
421
|
+
</define>
|
419
422
|
<define name="NumberingAttributes">
|
420
423
|
<optional>
|
421
424
|
<attribute name="unnumbered">
|
@@ -857,6 +860,7 @@ in case the table cannot be rendered accessibly (HTML 5)</a:documentation>
|
|
857
860
|
<define name="tr">
|
858
861
|
<a:documentation>Sequence of cells to be displayed as a row in a table</a:documentation>
|
859
862
|
<element name="tr">
|
863
|
+
<ref name="TrAttributes"/>
|
860
864
|
<oneOrMore>
|
861
865
|
<choice>
|
862
866
|
<ref name="td">
|
@@ -869,6 +873,9 @@ in case the table cannot be rendered accessibly (HTML 5)</a:documentation>
|
|
869
873
|
</oneOrMore>
|
870
874
|
</element>
|
871
875
|
</define>
|
876
|
+
<define name="TrAttributes">
|
877
|
+
<empty/>
|
878
|
+
</define>
|
872
879
|
<define name="tr-no-id">
|
873
880
|
<a:documentation>Sequence of cells to be displayed as a row in a table: optional ID attributes recursively (for use in Relaton, metadata)</a:documentation>
|
874
881
|
<element name="tr">
|
@@ -1694,16 +1701,22 @@ which can be bookmarks as well as block or section references</a:documentation>
|
|
1694
1701
|
<a:documentation>Inline reference to a paragraph or paragraphs, appearing as a footnote.
|
1695
1702
|
The target of a footnote is the location it is embedded in within the text</a:documentation>
|
1696
1703
|
<element name="fn">
|
1697
|
-
<
|
1698
|
-
|
1699
|
-
</attribute>
|
1700
|
-
<oneOrMore>
|
1701
|
-
<ref name="paragraph">
|
1702
|
-
<a:documentation>The content of the footnote</a:documentation>
|
1703
|
-
</ref>
|
1704
|
-
</oneOrMore>
|
1704
|
+
<ref name="FnAttributes"/>
|
1705
|
+
<ref name="FnBody"/>
|
1705
1706
|
</element>
|
1706
1707
|
</define>
|
1708
|
+
<define name="FnBody">
|
1709
|
+
<oneOrMore>
|
1710
|
+
<ref name="paragraph">
|
1711
|
+
<a:documentation>The content of the footnote</a:documentation>
|
1712
|
+
</ref>
|
1713
|
+
</oneOrMore>
|
1714
|
+
</define>
|
1715
|
+
<define name="FnAttributes">
|
1716
|
+
<attribute name="reference">
|
1717
|
+
<a:documentation>The number of the footnote, used to identify it visually</a:documentation>
|
1718
|
+
</attribute>
|
1719
|
+
</define>
|
1707
1720
|
<define name="callout">
|
1708
1721
|
<a:documentation>Inline reference to a paragraph or paragraphs, appearing as annotation of source code</a:documentation>
|
1709
1722
|
<element name="callout">
|
@@ -1,13 +1,14 @@
|
|
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">
|
3
|
-
<!--
|
4
|
-
Add-ons to biblio.rnc for standoc model: defines the extension point BibDataExtensionType
|
5
|
-
of relaton
|
6
|
-
|
7
|
-
Specialisations as for biblio.rnc. Extension point can be redefined completely for a flavour of standoc
|
8
|
-
(SDO); but other elements in Bibdata can only be extended (more specialised vocabularies for Bibdata)
|
9
|
-
-->
|
10
3
|
<include href="biblio.rng">
|
4
|
+
<!-- ALERT: we cannot have comments on root element, as they intervene with https://github.com/metanorma/metanorma/issues/437 fix -->
|
5
|
+
<!--
|
6
|
+
Add-ons to biblio.rnc for standoc model: defines the extension point BibDataExtensionType
|
7
|
+
of relaton
|
8
|
+
|
9
|
+
Specialisations as for biblio.rnc. Extension point can be redefined completely for a flavour of standoc
|
10
|
+
(SDO); but other elements in Bibdata can only be extended (more specialised vocabularies for Bibdata)
|
11
|
+
-->
|
11
12
|
<define name="BibData">
|
12
13
|
<a:documentation>The bibliographic description of a standardisation document</a:documentation>
|
13
14
|
<ref name="StandardBibliographicItem"/>
|
@@ -91,6 +92,9 @@ a standards definition organization</a:documentation>
|
|
91
92
|
<a:documentation>Representation of the identifier for the standardisation document, giving its individual semantic components</a:documentation>
|
92
93
|
</ref>
|
93
94
|
</zeroOrMore>
|
95
|
+
<ref name="DocumentImages">
|
96
|
+
<a:documentation>Coverpage and other images to be rendered with document</a:documentation>
|
97
|
+
</ref>
|
94
98
|
</define>
|
95
99
|
<define name="doctype">
|
96
100
|
<a:documentation>Classification of the standardisation document</a:documentation>
|
@@ -268,6 +272,32 @@ and not those document components</a:documentation>
|
|
268
272
|
</optional>
|
269
273
|
</element>
|
270
274
|
</define>
|
275
|
+
<define name="DocumentImages">
|
276
|
+
<zeroOrMore>
|
277
|
+
<element name="coverpage-image">
|
278
|
+
<a:documentation>Images to be displayed on the coverpage of the document</a:documentation>
|
279
|
+
<ref name="image-no-id"/>
|
280
|
+
</element>
|
281
|
+
</zeroOrMore>
|
282
|
+
<zeroOrMore>
|
283
|
+
<element name="innercoverpage-image">
|
284
|
+
<a:documentation>Images to be displayed on the inner coverpage of the document</a:documentation>
|
285
|
+
<ref name="image-no-id"/>
|
286
|
+
</element>
|
287
|
+
</zeroOrMore>
|
288
|
+
<zeroOrMore>
|
289
|
+
<element name="tocside-image">
|
290
|
+
<a:documentation>Images to be displayed on the Table of Contents page of the document</a:documentation>
|
291
|
+
<ref name="image-no-id"/>
|
292
|
+
</element>
|
293
|
+
</zeroOrMore>
|
294
|
+
<zeroOrMore>
|
295
|
+
<element name="backpage-image">
|
296
|
+
<a:documentation>Images to be displayed on the backpage of the document</a:documentation>
|
297
|
+
<ref name="image-no-id"/>
|
298
|
+
</element>
|
299
|
+
</zeroOrMore>
|
300
|
+
</define>
|
271
301
|
<define name="StandardBibliographicItem">
|
272
302
|
<ref name="BibliographicItem"/>
|
273
303
|
<zeroOrMore>
|
@@ -1,23 +1,25 @@
|
|
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
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
|
+
<!--
|
4
|
+
ALERT: we cannot have comments on root element, as they intervene with https://github.com/metanorma/metanorma/issues/437 fix
|
5
|
+
|
6
|
+
Instantiations of this grammar may replace leaf strings
|
7
|
+
with more elaborated types; e.g. title (text) replaced with
|
8
|
+
title-main, title-intro, title-part; type replaced with
|
9
|
+
enum.
|
10
|
+
|
11
|
+
Some renaming at leaf nodes is permissible
|
12
|
+
|
13
|
+
Obligations can change both from optional to mandatory,
|
14
|
+
and from mandatory to optional; optional elements may
|
15
|
+
be omitted; freely positioned alternatives may be replaced
|
16
|
+
with strict ordering
|
17
|
+
|
18
|
+
DO NOT introduce a namespace here. We do not want a distinct namespace
|
19
|
+
for these elements, and a distinct namespace for any grammar inheriting
|
20
|
+
these elements; we just want one namespace for any child grammars
|
21
|
+
of this.
|
22
|
+
-->
|
21
23
|
<!--
|
22
24
|
https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/
|
23
25
|
iso8601date = xsd:string { pattern = "([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?" }
|
@@ -1241,6 +1243,11 @@ Refer to `BibliographicItem` for definitions</a:documentation>
|
|
1241
1243
|
</define>
|
1242
1244
|
<define name="formattedref">
|
1243
1245
|
<element name="formattedref">
|
1246
|
+
<optional>
|
1247
|
+
<attribute name="format">
|
1248
|
+
<a:documentation>format of formatted reference; Metanorma assumes references are formatted as Metanorma XML</a:documentation>
|
1249
|
+
</attribute>
|
1250
|
+
</optional>
|
1244
1251
|
<oneOrMore>
|
1245
1252
|
<ref name="TextElement"/>
|
1246
1253
|
</oneOrMore>
|
@@ -1812,6 +1819,11 @@ May be used to differentiate rendering of notes in bibliographies</a:documentati
|
|
1812
1819
|
<a:documentation>Abstract of bibliographic item</a:documentation>
|
1813
1820
|
<element name="abstract">
|
1814
1821
|
<ref name="LocalizedStringAttributes"/>
|
1822
|
+
<optional>
|
1823
|
+
<attribute name="format">
|
1824
|
+
<a:documentation>What format the formatted abstract is in. In Metanorma, assumed to be Metanorma XML</a:documentation>
|
1825
|
+
</attribute>
|
1826
|
+
</optional>
|
1815
1827
|
<choice>
|
1816
1828
|
<oneOrMore>
|
1817
1829
|
<ref name="BasicBlockNoId">
|
@@ -214,10 +214,30 @@ module Metanorma
|
|
214
214
|
noko do |xml|
|
215
215
|
xml.passthrough **attr_code(formats:
|
216
216
|
node.attr("format") || "metanorma") do |p|
|
217
|
-
|
217
|
+
content = @c.encode(node.content, :basic, :hexadecimal)
|
218
|
+
p << content
|
219
|
+
passthrough_validate(node, node.content, content)
|
218
220
|
end
|
219
221
|
end
|
220
222
|
end
|
223
|
+
|
224
|
+
PASSTHROUGH_ERR = <<~ERRMSG.freeze
|
225
|
+
This is not valid Metanorma XML. If you intended a different format, such as HTML, you need to specify `format=` on the pass markup;
|
226
|
+
refer to https://www.metanorma.org/author/topics/blocks/passthroughs/
|
227
|
+
ERRMSG
|
228
|
+
|
229
|
+
# need to validate Metanorma XML before it passes to textcleanup,
|
230
|
+
# where passthrough wrapper and escaped tags are removed:
|
231
|
+
# <passthrough format="metanorma><tag></passthrough> => <tag>
|
232
|
+
# Do not treat not well-formed XML as invalid,
|
233
|
+
# as it may be fragment, e.g. unterminated start of element markup
|
234
|
+
def passthrough_validate(node, content, encoded_content)
|
235
|
+
valid, = validate_document_fragment(content.dup)
|
236
|
+
err =
|
237
|
+
"Invalid passthrough content: #{encoded_content}\n#{PASSTHROUGH_ERR}"
|
238
|
+
!valid and
|
239
|
+
@log.add("Metanorma XML Syntax", node, err, severity: 0)
|
240
|
+
end
|
221
241
|
end
|
222
242
|
end
|
223
243
|
end
|
@@ -19,6 +19,7 @@ require_relative "cleanup_image"
|
|
19
19
|
require_relative "cleanup_reqt"
|
20
20
|
require_relative "cleanup_text"
|
21
21
|
require_relative "cleanup_toc"
|
22
|
+
require_relative "cleanup_review"
|
22
23
|
require_relative "cleanup_dochistory"
|
23
24
|
require "relaton_iev"
|
24
25
|
|
@@ -82,6 +83,7 @@ module Metanorma
|
|
82
83
|
boilerplate_cleanup(xmldoc) # feeds: xref_cleanup for new <<>> introduced
|
83
84
|
xref_cleanup(xmldoc)
|
84
85
|
svgmap_cleanup(xmldoc) # feeds: img_cleanup
|
86
|
+
review_cleanup(xmldoc)
|
85
87
|
toc_cleanup(xmldoc)
|
86
88
|
smartquotes_cleanup(xmldoc)
|
87
89
|
linebreak_cleanup(xmldoc)
|
@@ -58,7 +58,7 @@ module Metanorma
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def indirect_eref_to_xref(eref, ident)
|
61
|
+
def indirect_eref_to_xref(eref, ident, id_map=nil)
|
62
62
|
loc = eref.at("./localityStack[locality[@type = 'anchor']]") ||
|
63
63
|
eref.at("./locality[@type = 'anchor']")
|
64
64
|
loc = loc&.remove&.text || ident
|
@@ -66,18 +66,30 @@ module Metanorma
|
|
66
66
|
eref.delete("bibitemid")
|
67
67
|
eref.delete("citeas")
|
68
68
|
eref["target"] = loc
|
69
|
-
|
69
|
+
if id_map
|
70
|
+
return if id_map.has_key?(loc)
|
71
|
+
else
|
72
|
+
eref.document.at("//*[@id = '#{loc}']") and return
|
73
|
+
end
|
70
74
|
eref.children = %(** Missing target #{loc})
|
71
75
|
eref["target"] = ident
|
72
76
|
end
|
73
77
|
|
74
78
|
def resolve_local_indirect_erefs(xmldoc, refs, prefix)
|
79
|
+
# Pre-index elements by ID
|
80
|
+
id_map = xmldoc.xpath("//*[@id]").each_with_object({}) do |node, map|
|
81
|
+
map[node["id"]] = node
|
82
|
+
end
|
83
|
+
|
84
|
+
# Pre-index all <eref> elements by bibitemid
|
85
|
+
eref_map = xmldoc.xpath("//eref[@bibitemid]").group_by { |e| e["bibitemid"] }
|
86
|
+
|
75
87
|
refs.each_with_object([]) do |r, m|
|
76
88
|
id = r.sub(/^#{prefix}_/, "")
|
77
|
-
n =
|
89
|
+
n = id_map[id]
|
78
90
|
if n&.at("./ancestor-or-self::*[@type = '#{prefix}']")
|
79
|
-
|
80
|
-
indirect_eref_to_xref(e, id)
|
91
|
+
eref_map[r]&.each do |e|
|
92
|
+
indirect_eref_to_xref(e, id, id_map)
|
81
93
|
end
|
82
94
|
else m << r
|
83
95
|
end
|
@@ -145,10 +145,9 @@ module Metanorma
|
|
145
145
|
elem.xpath(IDREF).each do |s|
|
146
146
|
if (ret = Metanorma::Utils::to_ncname(s.value)) != (orig = s.value)
|
147
147
|
s.value = ret
|
148
|
-
output = s.parent.dup
|
149
|
-
output.children.remove
|
150
148
|
@log.add("Anchors", s.parent,
|
151
|
-
"normalised identifier
|
149
|
+
"normalised identifier to #{ret} from #{orig}",
|
150
|
+
display: false)
|
152
151
|
end
|
153
152
|
end
|
154
153
|
end
|
@@ -157,10 +156,9 @@ module Metanorma
|
|
157
156
|
elem.xpath("//xref/@target").each do |s|
|
158
157
|
if (ret = to_xreftarget(s.value)) != (orig = s.value)
|
159
158
|
s.value = ret
|
160
|
-
output = s.parent.dup
|
161
|
-
output.children.remove
|
162
159
|
@log.add("Anchors", s.parent,
|
163
|
-
"normalised identifier
|
160
|
+
"normalised identifier to #{ret} from #{orig}",
|
161
|
+
display: false)
|
164
162
|
end
|
165
163
|
end
|
166
164
|
end
|
@@ -198,6 +196,9 @@ module Metanorma
|
|
198
196
|
p.name = "passthrough"
|
199
197
|
p.children = select_odd_chars(p.children.to_xml)
|
200
198
|
end
|
199
|
+
doc.xpath("//passthrough[@format = 'metanorma']").each do |p|
|
200
|
+
p.replace(p.children)
|
201
|
+
end
|
201
202
|
doc.xpath("//identifier").each do |p|
|
202
203
|
p.children = select_odd_chars(p.children.to_xml)
|
203
204
|
end
|
@@ -26,9 +26,6 @@ module Metanorma
|
|
26
26
|
asciimath2mathml_err(elem.to_xml, e)
|
27
27
|
end
|
28
28
|
|
29
|
-
# https://medium.com/@rickwang_wxc/in-ruby-given-a-string-detect-if-it-is-valid-numeric-c58275eace60
|
30
|
-
NUMERIC_REGEX = %r{^((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?$}
|
31
|
-
|
32
29
|
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
33
30
|
|
34
31
|
def asciimath_parse(expr, elem)
|
@@ -191,6 +188,8 @@ module Metanorma
|
|
191
188
|
.each { |x| mathml_number_format(x) }
|
192
189
|
mathml_unitsml(xmldoc)
|
193
190
|
end
|
191
|
+
|
192
|
+
include ::Metanorma::Standoc::Regex
|
194
193
|
end
|
195
194
|
end
|
196
195
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def review_cleanup(xmldoc)
|
5
|
+
reviews = xmldoc.xpath("//review")
|
6
|
+
reviews.empty? and return
|
7
|
+
ctr = xmldoc.root.add_child("<review-container/>").first
|
8
|
+
reviews.each do |r|
|
9
|
+
review_set_location(r)
|
10
|
+
ctr << r
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def review_insert_bookmark(review, id)
|
15
|
+
parent = review.parent
|
16
|
+
children = parent.children
|
17
|
+
index = children.index(review)
|
18
|
+
x = previous_review_siblings(children, index) ||
|
19
|
+
following_review_siblings(children, index)
|
20
|
+
ins = if x then x.at(".//text()")
|
21
|
+
else review.before("<p> </p>").previous.at(".//text()")
|
22
|
+
end
|
23
|
+
ins.previous = "<bookmark id='#{id}'/>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def previous_review_siblings(children, index)
|
27
|
+
x = nil
|
28
|
+
(index - 1).downto(0) do |i|
|
29
|
+
node = children[i]
|
30
|
+
if node.element? && node.name != "review" && node.text.strip != ""
|
31
|
+
x = node
|
32
|
+
break
|
33
|
+
end
|
34
|
+
end
|
35
|
+
x
|
36
|
+
end
|
37
|
+
|
38
|
+
def following_review_siblings(children, index)
|
39
|
+
x = nil
|
40
|
+
(index + 1).upto(children.size - 1) do |i|
|
41
|
+
node = children[i]
|
42
|
+
if node.element? && node.name != "review" && node.text.strip != ""
|
43
|
+
x = node
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
x
|
48
|
+
end
|
49
|
+
|
50
|
+
def review_set_location(review)
|
51
|
+
unless review["from"]
|
52
|
+
id = "_#{UUIDTools::UUID.random_create}"
|
53
|
+
review_insert_bookmark(review, id)
|
54
|
+
review["from"] = id
|
55
|
+
end
|
56
|
+
review["to"] ||= review["from"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -96,9 +96,7 @@ module Metanorma
|
|
96
96
|
y.name == "annex" || !y.ancestors("annex").empty? and next
|
97
97
|
y.wrap("<annex/>")
|
98
98
|
y.parent["id"] = "_#{UUIDTools::UUID.random_create}"
|
99
|
-
%w(obligation language script).each
|
100
|
-
y.parent[w] = y[w]
|
101
|
-
end
|
99
|
+
%w(obligation language script).each { |w| y.parent[w] = y[w] }
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
@@ -192,7 +190,7 @@ module Metanorma
|
|
192
190
|
xmldoc.at("//sections") or return
|
193
191
|
ins = insert_before(xmldoc, "//sections")
|
194
192
|
xmldoc.xpath("//sections//*[@beforeclauses = 'true']")
|
195
|
-
.
|
193
|
+
.reverse_each do |x|
|
196
194
|
x.delete("beforeclauses")
|
197
195
|
ins.previous = x.remove
|
198
196
|
end
|
@@ -201,46 +199,13 @@ module Metanorma
|
|
201
199
|
|
202
200
|
# only move clausebefore notes at the very end of preface
|
203
201
|
def endofpreface_clausebefore(xml, ins)
|
204
|
-
xml.xpath("//preface//*[@beforeclauses = 'true']").
|
202
|
+
xml.xpath("//preface//*[@beforeclauses = 'true']").reverse_each do |x|
|
205
203
|
textafter = xml.xpath("//preface//*") & x.xpath("./following::*")
|
206
204
|
textafter.text.strip.empty? or break
|
207
205
|
x.delete("beforeclauses")
|
208
206
|
ins.previous = x.remove
|
209
207
|
end
|
210
208
|
end
|
211
|
-
|
212
|
-
def insert_before(xmldoc, xpath)
|
213
|
-
unless ins = xmldoc.at(xpath).children.first
|
214
|
-
xmldoc.at(xpath) << " "
|
215
|
-
ins = xmldoc.at(xpath).children.first
|
216
|
-
end
|
217
|
-
ins
|
218
|
-
end
|
219
|
-
|
220
|
-
def floatingtitle_cleanup(xmldoc)
|
221
|
-
pop_floating_title(xmldoc) # done again, after endofpreface_clausebefore
|
222
|
-
floating_title_preface2sections(xmldoc)
|
223
|
-
end
|
224
|
-
|
225
|
-
def pop_floating_title(xmldoc)
|
226
|
-
loop do
|
227
|
-
found = false
|
228
|
-
xmldoc.xpath("//floating-title").each do |t|
|
229
|
-
t.next_element.nil? or next
|
230
|
-
%w(sections annex preface).include? t.parent.name and next
|
231
|
-
t.parent.next = t
|
232
|
-
found = true
|
233
|
-
end
|
234
|
-
break unless found
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def floating_title_preface2sections(xmldoc)
|
239
|
-
t = xmldoc.at("//preface/floating-title") or return
|
240
|
-
s = xmldoc.at("//sections")
|
241
|
-
t.next_element or
|
242
|
-
s.children.first.previous = t.remove
|
243
|
-
end
|
244
209
|
end
|
245
210
|
end
|
246
211
|
end
|
@@ -156,6 +156,31 @@ module Metanorma
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
159
|
+
|
160
|
+
def floatingtitle_cleanup(xmldoc)
|
161
|
+
pop_floating_title(xmldoc) # done again, after endofpreface_clausebefore
|
162
|
+
floating_title_preface2sections(xmldoc)
|
163
|
+
end
|
164
|
+
|
165
|
+
def pop_floating_title(xmldoc)
|
166
|
+
loop do
|
167
|
+
found = false
|
168
|
+
xmldoc.xpath("//floating-title").each do |t|
|
169
|
+
t.next_element.nil? or next
|
170
|
+
%w(sections annex preface).include? t.parent.name and next
|
171
|
+
t.parent.next = t
|
172
|
+
found = true
|
173
|
+
end
|
174
|
+
break unless found
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def floating_title_preface2sections(xmldoc)
|
179
|
+
t = xmldoc.at("//preface/floating-title") or return
|
180
|
+
s = xmldoc.at("//sections")
|
181
|
+
t.next_element or
|
182
|
+
s.children.first.previous = t.remove
|
183
|
+
end
|
159
184
|
end
|
160
185
|
end
|
161
186
|
end
|
@@ -47,6 +47,8 @@ module Metanorma
|
|
47
47
|
sources_table_cleanup(xmldoc)
|
48
48
|
notes_table_cleanup(xmldoc)
|
49
49
|
header_rows_cleanup(xmldoc)
|
50
|
+
tr_style_cleanup(xmldoc)
|
51
|
+
td_style_cleanup(xmldoc)
|
50
52
|
end
|
51
53
|
|
52
54
|
def sources_table_cleanup(xmldoc)
|
@@ -75,6 +77,26 @@ module Metanorma
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
80
|
+
|
81
|
+
def tr_style_cleanup(xmldoc)
|
82
|
+
xmldoc.xpath("//tr[.//tr-style]").each do |tr|
|
83
|
+
ret = tr.xpath(".//tr-style").each_with_object([]) do |s, m|
|
84
|
+
m << s.text
|
85
|
+
end
|
86
|
+
tr["style"] = ret.join(";")
|
87
|
+
end
|
88
|
+
xmldoc.xpath(".//tr-style").each(&:remove)
|
89
|
+
end
|
90
|
+
|
91
|
+
def td_style_cleanup(xmldoc)
|
92
|
+
xmldoc.xpath("//td[.//td-style] | //th[.//td-style]").each do |tr|
|
93
|
+
ret = tr.xpath(".//td-style").each_with_object([]) do |s, m|
|
94
|
+
m << s.text
|
95
|
+
end
|
96
|
+
tr["style"] = ret.join(";")
|
97
|
+
end
|
98
|
+
xmldoc.xpath(".//td-style").each(&:remove)
|
99
|
+
end
|
78
100
|
end
|
79
101
|
end
|
80
102
|
end
|