metanorma-standoc 2.2.4 → 2.2.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/.github/workflows/automerge.yml +31 -0
- data/lib/isodoc/html/htmlstyle.css +1 -1
- data/lib/metanorma/standoc/base.rb +1 -0
- data/lib/metanorma/standoc/basicdoc.rng +0 -27
- data/lib/metanorma/standoc/biblio-standoc.rng +164 -0
- data/lib/metanorma/standoc/biblio.rng +45 -18
- data/lib/metanorma/standoc/blocks.rb +2 -1
- data/lib/metanorma/standoc/cleanup.rb +1 -0
- data/lib/metanorma/standoc/cleanup_asciibib.rb +110 -0
- data/lib/metanorma/standoc/cleanup_biblio.rb +5 -111
- data/lib/metanorma/standoc/cleanup_block.rb +7 -6
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +6 -6
- data/lib/metanorma/standoc/cleanup_inline.rb +2 -2
- data/lib/metanorma/standoc/cleanup_text.rb +10 -3
- data/lib/metanorma/standoc/inline.rb +3 -1
- data/lib/metanorma/standoc/isodoc-compile.rng +7 -0
- data/lib/metanorma/standoc/isodoc.rng +32 -195
- data/lib/metanorma/standoc/macros_plantuml.rb +23 -10
- data/lib/metanorma/standoc/validate.rb +8 -8
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +0 -1
- data/spec/metanorma/biblio_spec.rb +152 -144
- data/spec/metanorma/blocks_spec.rb +2 -2
- data/spec/metanorma/cleanup_sections_spec.rb +1 -2
- data/spec/metanorma/cleanup_spec.rb +11 -0
- data/spec/metanorma/inline_spec.rb +70 -8
- data/spec/metanorma/isobib_cache_spec.rb +2 -2
- data/spec/metanorma/macros_plantuml_spec.rb +4 -4
- data/spec/metanorma/macros_spec.rb +2 -2
- data/spec/metanorma/refs_spec.rb +25 -25
- data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +3 -3
- data/spec/vcr_cassettes/bsi16341.yml +70 -72
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +82 -82
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
- data/spec/vcr_cassettes/hide_refs.yml +58 -58
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +22 -22
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +33 -33
- data/spec/vcr_cassettes/isobib_get_123_2.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +37 -21
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
- data/spec/vcr_cassettes/std-link.yml +12 -12
- metadata +6 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '033585c8aaadb0c5672e328edd9c30012ee330cb800cbf8a7f4e2a7e5498a61e'
|
4
|
+
data.tar.gz: 07b1cba33ba7917f68429d91393c8795d787c63e06f60d3f8d00938088e13138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d163281f43172f6c1be2391bb923245f58270efd2f1eb482412b08e41ebdfeed91f6edeb4df61e4e5056feba0fd7c17b673b8d8d324f9837f93ac310052eda73
|
7
|
+
data.tar.gz: 1a8dbeadcc05872bf5daadebf262204461e75f9e39ffd9a0d2b77ebaec68131cd04786cb22a8adfaccfdaf3cad3db3019a51a85b18d8be1a8d363381c7618045
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
# source: https://github.com/marketplace/actions/merge-pull-requests#usage
|
4
|
+
name: automerge
|
5
|
+
on:
|
6
|
+
pull_request:
|
7
|
+
types:
|
8
|
+
- labeled
|
9
|
+
- unlabeled
|
10
|
+
- synchronize
|
11
|
+
- opened
|
12
|
+
- edited
|
13
|
+
- ready_for_review
|
14
|
+
- reopened
|
15
|
+
- unlocked
|
16
|
+
pull_request_review:
|
17
|
+
types:
|
18
|
+
- submitted
|
19
|
+
check_suite:
|
20
|
+
types:
|
21
|
+
- completed
|
22
|
+
status: {}
|
23
|
+
jobs:
|
24
|
+
automerge:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- id: automerge
|
28
|
+
name: automerge
|
29
|
+
uses: "pascalgn/automerge-action@v0.15.3"
|
30
|
+
env:
|
31
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
@@ -1,10 +1,5 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
3
|
-
<include href="biblio.rng">
|
4
|
-
<start>
|
5
|
-
<ref name="document"/>
|
6
|
-
</start>
|
7
|
-
</include>
|
8
3
|
<define name="document">
|
9
4
|
<element name="document">
|
10
5
|
<optional>
|
@@ -1125,26 +1120,4 @@
|
|
1125
1120
|
</zeroOrMore>
|
1126
1121
|
</element>
|
1127
1122
|
</define>
|
1128
|
-
<define name="ext">
|
1129
|
-
<element name="ext">
|
1130
|
-
<ref name="BibDataExtensionType"/>
|
1131
|
-
</element>
|
1132
|
-
</define>
|
1133
|
-
<define name="BibDataExtensionType">
|
1134
|
-
<ref name="doctype"/>
|
1135
|
-
</define>
|
1136
|
-
<define name="doctype">
|
1137
|
-
<element name="doctype">
|
1138
|
-
<ref name="DocumentType"/>
|
1139
|
-
</element>
|
1140
|
-
</define>
|
1141
|
-
<define name="DocumentType">
|
1142
|
-
<value>document</value>
|
1143
|
-
</define>
|
1144
|
-
<define name="BibData">
|
1145
|
-
<ref name="BibliographicItem"/>
|
1146
|
-
<optional>
|
1147
|
-
<ref name="ext"/>
|
1148
|
-
</optional>
|
1149
|
-
</define>
|
1150
1123
|
</grammar>
|
@@ -0,0 +1,164 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<grammar 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
|
+
<include href="biblio.rng">
|
11
|
+
<define name="BibData">
|
12
|
+
<ref name="BibliographicItem"/>
|
13
|
+
<optional>
|
14
|
+
<ref name="ext"/>
|
15
|
+
</optional>
|
16
|
+
</define>
|
17
|
+
</include>
|
18
|
+
<define name="ext">
|
19
|
+
<element name="ext">
|
20
|
+
<ref name="BibDataExtensionType"/>
|
21
|
+
</element>
|
22
|
+
</define>
|
23
|
+
<define name="BibDataExtensionType">
|
24
|
+
<optional>
|
25
|
+
<attribute name="schema-version"/>
|
26
|
+
</optional>
|
27
|
+
<ref name="doctype"/>
|
28
|
+
<optional>
|
29
|
+
<ref name="docsubtype"/>
|
30
|
+
</optional>
|
31
|
+
<optional>
|
32
|
+
<ref name="editorialgroup"/>
|
33
|
+
</optional>
|
34
|
+
<zeroOrMore>
|
35
|
+
<ref name="ics"/>
|
36
|
+
</zeroOrMore>
|
37
|
+
<zeroOrMore>
|
38
|
+
<ref name="structuredidentifier"/>
|
39
|
+
</zeroOrMore>
|
40
|
+
</define>
|
41
|
+
<define name="doctype">
|
42
|
+
<element name="doctype">
|
43
|
+
<optional>
|
44
|
+
<attribute name="abbreviation"/>
|
45
|
+
</optional>
|
46
|
+
<ref name="DocumentType"/>
|
47
|
+
</element>
|
48
|
+
</define>
|
49
|
+
<define name="DocumentType">
|
50
|
+
<value>document</value>
|
51
|
+
</define>
|
52
|
+
<define name="docsubtype">
|
53
|
+
<element name="subdoctype">
|
54
|
+
<ref name="DocumentSubtype"/>
|
55
|
+
</element>
|
56
|
+
</define>
|
57
|
+
<define name="DocumentSubtype">
|
58
|
+
<text/>
|
59
|
+
</define>
|
60
|
+
<define name="editorialgroup">
|
61
|
+
<element name="editorialgroup">
|
62
|
+
<oneOrMore>
|
63
|
+
<ref name="technical-committee"/>
|
64
|
+
</oneOrMore>
|
65
|
+
</element>
|
66
|
+
</define>
|
67
|
+
<define name="technical-committee">
|
68
|
+
<element name="technical-committee">
|
69
|
+
<ref name="IsoWorkgroup"/>
|
70
|
+
</element>
|
71
|
+
</define>
|
72
|
+
<define name="IsoWorkgroup">
|
73
|
+
<optional>
|
74
|
+
<attribute name="number"/>
|
75
|
+
</optional>
|
76
|
+
<optional>
|
77
|
+
<attribute name="type"/>
|
78
|
+
</optional>
|
79
|
+
<optional>
|
80
|
+
<attribute name="identifier"/>
|
81
|
+
</optional>
|
82
|
+
<optional>
|
83
|
+
<attribute name="prefix"/>
|
84
|
+
</optional>
|
85
|
+
<text/>
|
86
|
+
</define>
|
87
|
+
<define name="ics">
|
88
|
+
<element name="ics">
|
89
|
+
<element name="code">
|
90
|
+
<text/>
|
91
|
+
</element>
|
92
|
+
<optional>
|
93
|
+
<element name="text">
|
94
|
+
<text/>
|
95
|
+
</element>
|
96
|
+
</optional>
|
97
|
+
</element>
|
98
|
+
</define>
|
99
|
+
<define name="structuredidentifier">
|
100
|
+
<element name="structuredidentifier">
|
101
|
+
<optional>
|
102
|
+
<attribute name="type"/>
|
103
|
+
</optional>
|
104
|
+
<oneOrMore>
|
105
|
+
<element name="agency">
|
106
|
+
<text/>
|
107
|
+
</element>
|
108
|
+
</oneOrMore>
|
109
|
+
<optional>
|
110
|
+
<element name="class">
|
111
|
+
<text/>
|
112
|
+
</element>
|
113
|
+
</optional>
|
114
|
+
<element name="docnumber">
|
115
|
+
<text/>
|
116
|
+
</element>
|
117
|
+
<optional>
|
118
|
+
<element name="partnumber">
|
119
|
+
<text/>
|
120
|
+
</element>
|
121
|
+
</optional>
|
122
|
+
<optional>
|
123
|
+
<element name="edition">
|
124
|
+
<text/>
|
125
|
+
</element>
|
126
|
+
</optional>
|
127
|
+
<optional>
|
128
|
+
<element name="version">
|
129
|
+
<text/>
|
130
|
+
</element>
|
131
|
+
</optional>
|
132
|
+
<optional>
|
133
|
+
<element name="supplementtype">
|
134
|
+
<text/>
|
135
|
+
</element>
|
136
|
+
</optional>
|
137
|
+
<optional>
|
138
|
+
<element name="supplementnumber">
|
139
|
+
<text/>
|
140
|
+
</element>
|
141
|
+
</optional>
|
142
|
+
<optional>
|
143
|
+
<element name="amendment">
|
144
|
+
<text/>
|
145
|
+
</element>
|
146
|
+
</optional>
|
147
|
+
<optional>
|
148
|
+
<element name="corrigendum">
|
149
|
+
<text/>
|
150
|
+
</element>
|
151
|
+
</optional>
|
152
|
+
<optional>
|
153
|
+
<element name="language">
|
154
|
+
<text/>
|
155
|
+
</element>
|
156
|
+
</optional>
|
157
|
+
<optional>
|
158
|
+
<element name="year">
|
159
|
+
<text/>
|
160
|
+
</element>
|
161
|
+
</optional>
|
162
|
+
</element>
|
163
|
+
</define>
|
164
|
+
</grammar>
|
@@ -33,9 +33,10 @@
|
|
33
33
|
<param name="pattern">([\+\-]?\d{4})((-?)((0[1-9]|1[0-2])((-?)([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]))))?</param>
|
34
34
|
</data>
|
35
35
|
</define>
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
<!-- start = bibitem -->
|
37
|
+
<define name="BibData">
|
38
|
+
<ref name="BibliographicItem"/>
|
39
|
+
</define>
|
39
40
|
<define name="status">
|
40
41
|
<element name="status">
|
41
42
|
<ref name="stage"/>
|
@@ -170,27 +171,25 @@
|
|
170
171
|
</define>
|
171
172
|
<define name="contributor">
|
172
173
|
<element name="contributor">
|
173
|
-
<
|
174
|
+
<oneOrMore>
|
174
175
|
<ref name="role"/>
|
175
|
-
</
|
176
|
+
</oneOrMore>
|
176
177
|
<ref name="ContributorInfo"/>
|
177
178
|
</element>
|
178
179
|
</define>
|
179
180
|
<define name="role">
|
180
181
|
<element name="role">
|
181
|
-
<
|
182
|
-
<
|
183
|
-
<
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
</attribute>
|
193
|
-
</optional>
|
182
|
+
<attribute name="type">
|
183
|
+
<choice>
|
184
|
+
<value>author</value>
|
185
|
+
<value>performer</value>
|
186
|
+
<value>publisher</value>
|
187
|
+
<value>editor</value>
|
188
|
+
<value>adapter</value>
|
189
|
+
<value>translator</value>
|
190
|
+
<value>distributor</value>
|
191
|
+
</choice>
|
192
|
+
</attribute>
|
194
193
|
<zeroOrMore>
|
195
194
|
<ref name="roledescription"/>
|
196
195
|
</zeroOrMore>
|
@@ -512,6 +511,17 @@
|
|
512
511
|
</define>
|
513
512
|
<define name="localityStack">
|
514
513
|
<element name="localityStack">
|
514
|
+
<optional>
|
515
|
+
<attribute name="connective">
|
516
|
+
<choice>
|
517
|
+
<value>and</value>
|
518
|
+
<value>or</value>
|
519
|
+
<value>from</value>
|
520
|
+
<value>to</value>
|
521
|
+
<value/>
|
522
|
+
</choice>
|
523
|
+
</attribute>
|
524
|
+
</optional>
|
515
525
|
<zeroOrMore>
|
516
526
|
<ref name="locality"/>
|
517
527
|
</zeroOrMore>
|
@@ -524,6 +534,17 @@
|
|
524
534
|
</define>
|
525
535
|
<define name="sourceLocalityStack">
|
526
536
|
<element name="sourceLocalityStack">
|
537
|
+
<optional>
|
538
|
+
<attribute name="connective">
|
539
|
+
<choice>
|
540
|
+
<value>and</value>
|
541
|
+
<value>or</value>
|
542
|
+
<value>from</value>
|
543
|
+
<value>to</value>
|
544
|
+
<value/>
|
545
|
+
</choice>
|
546
|
+
</attribute>
|
547
|
+
</optional>
|
527
548
|
<zeroOrMore>
|
528
549
|
<ref name="sourceLocality"/>
|
529
550
|
</zeroOrMore>
|
@@ -626,6 +647,9 @@
|
|
626
647
|
<ref name="BibItemType"/>
|
627
648
|
</attribute>
|
628
649
|
</optional>
|
650
|
+
<optional>
|
651
|
+
<attribute name="schema-version"/>
|
652
|
+
</optional>
|
629
653
|
<optional>
|
630
654
|
<ref name="fetched"/>
|
631
655
|
</optional>
|
@@ -720,6 +744,9 @@
|
|
720
744
|
<ref name="BibItemType"/>
|
721
745
|
</attribute>
|
722
746
|
</optional>
|
747
|
+
<optional>
|
748
|
+
<attribute name="schema-version"/>
|
749
|
+
</optional>
|
723
750
|
<optional>
|
724
751
|
<ref name="fetched"/>
|
725
752
|
</optional>
|
@@ -5,6 +5,7 @@ require_relative "./cleanup_block"
|
|
5
5
|
require_relative "./cleanup_table"
|
6
6
|
require_relative "./cleanup_footnotes"
|
7
7
|
require_relative "./cleanup_ref"
|
8
|
+
require_relative "./cleanup_asciibib"
|
8
9
|
require_relative "./cleanup_biblio"
|
9
10
|
require_relative "./cleanup_boilerplate"
|
10
11
|
require_relative "./cleanup_section"
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "set"
|
2
|
+
require "relaton_bib"
|
3
|
+
|
4
|
+
module Metanorma
|
5
|
+
module Standoc
|
6
|
+
module Cleanup
|
7
|
+
def ref_dl_cleanup(xmldoc)
|
8
|
+
xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
|
9
|
+
bib = dl_bib_extract(c) or next
|
10
|
+
validate_ref_dl(bib, c)
|
11
|
+
bibitemxml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
|
12
|
+
bibitem = Nokogiri::XML(bibitemxml)
|
13
|
+
bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
|
14
|
+
c.replace(bibitem.root)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# do not accept implicit id
|
19
|
+
def validate_ref_dl(bib, clause)
|
20
|
+
id = bib["id"]
|
21
|
+
id ||= clause["id"] unless /^_/.match?(clause["id"])
|
22
|
+
unless id
|
23
|
+
@log.add("Anchors", clause,
|
24
|
+
"The following reference is missing an anchor:\n" \
|
25
|
+
"#{clause.to_xml}")
|
26
|
+
return
|
27
|
+
end
|
28
|
+
@refids << id
|
29
|
+
validate_ref_dl1(bib, id, clause)
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate_ref_dl1(bib, id, clause)
|
33
|
+
bib["title"] or
|
34
|
+
@log.add("Bibliography", clause, "Reference #{id} is missing a title")
|
35
|
+
bib["docid"] or
|
36
|
+
@log.add("Bibliography", clause,
|
37
|
+
"Reference #{id} is missing a document identifier (docid)")
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_from_p(tag, bib, key)
|
41
|
+
return unless bib[tag]
|
42
|
+
|
43
|
+
"<#{key}>#{bib[tag].at('p').children}</#{key}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
# if the content is a single paragraph, replace it with its children
|
47
|
+
# single links replaced with uri
|
48
|
+
def p_unwrap(para)
|
49
|
+
elems = para.elements
|
50
|
+
if elems.size == 1 && elems[0].name == "p"
|
51
|
+
link_unwrap(elems[0]).children.to_xml.strip
|
52
|
+
else
|
53
|
+
para.to_xml.strip
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def link_unwrap(para)
|
58
|
+
elems = para.elements
|
59
|
+
if elems.size == 1 && elems[0].name == "link"
|
60
|
+
para.at("./link").replace(elems[0]["target"].strip)
|
61
|
+
end
|
62
|
+
para
|
63
|
+
end
|
64
|
+
|
65
|
+
def dd_bib_extract(dtd)
|
66
|
+
return nil if dtd.children.empty?
|
67
|
+
|
68
|
+
dtd.at("./dl") and return dl_bib_extract(dtd)
|
69
|
+
elems = dtd.remove.elements
|
70
|
+
return p_unwrap(dtd) unless elems.size == 1 &&
|
71
|
+
%w(ol ul).include?(elems[0].name)
|
72
|
+
|
73
|
+
elems[0].xpath("./li").each_with_object([]) do |li, ret|
|
74
|
+
ret << p_unwrap(li)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_to_hash(bib, key, val)
|
79
|
+
Metanorma::Utils::set_nested_value(bib, key.split("."), val)
|
80
|
+
end
|
81
|
+
|
82
|
+
# definition list, with at most one level of unordered lists
|
83
|
+
def dl_bib_extract(clause, nested = false)
|
84
|
+
dl = clause.at("./dl") or return
|
85
|
+
key = ""
|
86
|
+
bib = dl.xpath("./dt | ./dd").each_with_object({}) do |dtd, m|
|
87
|
+
(dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) and next
|
88
|
+
add_to_hash(m, key, dd_bib_extract(dtd))
|
89
|
+
end
|
90
|
+
clause.xpath("./clause").each do |c1|
|
91
|
+
key = c1&.at("./title")&.text&.downcase&.strip
|
92
|
+
next unless %w(contributor relation series).include? key
|
93
|
+
|
94
|
+
add_to_hash(bib, key, dl_bib_extract(c1, true))
|
95
|
+
end
|
96
|
+
dl_bib_extract_title(bib, clause, nested)
|
97
|
+
end
|
98
|
+
|
99
|
+
def dl_bib_extract_title(bib, clause, nested)
|
100
|
+
(!nested && clause.at("./title")) or return bib
|
101
|
+
title = clause.at("./title").remove.children.to_xml
|
102
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a?(Hash) ||
|
103
|
+
bib["title"].is_a?(String)
|
104
|
+
bib["title"] ||= []
|
105
|
+
bib["title"] << title if !title.empty?
|
106
|
+
bib
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -1,113 +1,6 @@
|
|
1
|
-
require "set"
|
2
|
-
require "relaton_bib"
|
3
|
-
|
4
1
|
module Metanorma
|
5
2
|
module Standoc
|
6
3
|
module Cleanup
|
7
|
-
def ref_dl_cleanup(xmldoc)
|
8
|
-
xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
|
9
|
-
bib = dl_bib_extract(c) or next
|
10
|
-
validate_ref_dl(bib, c)
|
11
|
-
bibitemxml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
|
12
|
-
bibitem = Nokogiri::XML(bibitemxml)
|
13
|
-
bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
|
14
|
-
c.replace(bibitem.root)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# do not accept implicit id
|
19
|
-
def validate_ref_dl(bib, clause)
|
20
|
-
id = bib["id"]
|
21
|
-
id ||= clause["id"] unless /^_/.match?(clause["id"])
|
22
|
-
unless id
|
23
|
-
@log.add("Anchors", clause,
|
24
|
-
"The following reference is missing an anchor:\n"\
|
25
|
-
"#{clause.to_xml}")
|
26
|
-
return
|
27
|
-
end
|
28
|
-
@refids << id
|
29
|
-
validate_ref_dl1(bib, id, clause)
|
30
|
-
end
|
31
|
-
|
32
|
-
def validate_ref_dl1(bib, id, clause)
|
33
|
-
bib["title"] or
|
34
|
-
@log.add("Bibliography", clause, "Reference #{id} is missing a title")
|
35
|
-
bib["docid"] or
|
36
|
-
@log.add("Bibliography", clause,
|
37
|
-
"Reference #{id} is missing a document identifier (docid)")
|
38
|
-
end
|
39
|
-
|
40
|
-
def extract_from_p(tag, bib, key)
|
41
|
-
return unless bib[tag]
|
42
|
-
|
43
|
-
"<#{key}>#{bib[tag].at('p').children}</#{key}>"
|
44
|
-
end
|
45
|
-
|
46
|
-
# if the content is a single paragraph, replace it with its children
|
47
|
-
# single links replaced with uri
|
48
|
-
def p_unwrap(para)
|
49
|
-
elems = para.elements
|
50
|
-
if elems.size == 1 && elems[0].name == "p"
|
51
|
-
link_unwrap(elems[0]).children.to_xml.strip
|
52
|
-
else
|
53
|
-
para.to_xml.strip
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def link_unwrap(para)
|
58
|
-
elems = para.elements
|
59
|
-
if elems.size == 1 && elems[0].name == "link"
|
60
|
-
para.at("./link").replace(elems[0]["target"].strip)
|
61
|
-
end
|
62
|
-
para
|
63
|
-
end
|
64
|
-
|
65
|
-
def dd_bib_extract(dtd)
|
66
|
-
return nil if dtd.children.empty?
|
67
|
-
|
68
|
-
dtd.at("./dl") and return dl_bib_extract(dtd)
|
69
|
-
elems = dtd.remove.elements
|
70
|
-
return p_unwrap(dtd) unless elems.size == 1 &&
|
71
|
-
%w(ol ul).include?(elems[0].name)
|
72
|
-
|
73
|
-
elems[0].xpath("./li").each_with_object([]) do |li, ret|
|
74
|
-
ret << p_unwrap(li)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def add_to_hash(bib, key, val)
|
79
|
-
Metanorma::Utils::set_nested_value(bib, key.split("."), val)
|
80
|
-
end
|
81
|
-
|
82
|
-
# definition list, with at most one level of unordered lists
|
83
|
-
def dl_bib_extract(clause, nested = false)
|
84
|
-
dl = clause.at("./dl") or return
|
85
|
-
key = ""
|
86
|
-
bib = dl.xpath("./dt | ./dd").each_with_object({}) do |dtd, m|
|
87
|
-
(dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) and next
|
88
|
-
add_to_hash(m, key, dd_bib_extract(dtd))
|
89
|
-
end
|
90
|
-
clause.xpath("./clause").each do |c1|
|
91
|
-
key = c1&.at("./title")&.text&.downcase&.strip
|
92
|
-
next unless %w(contributor relation series).include? key
|
93
|
-
|
94
|
-
add_to_hash(bib, key, dl_bib_extract(c1, true))
|
95
|
-
end
|
96
|
-
dl_bib_extract_title(bib, clause, nested)
|
97
|
-
end
|
98
|
-
|
99
|
-
def dl_bib_extract_title(bib, clause, nested)
|
100
|
-
(!nested && clause.at("./title")) or return bib
|
101
|
-
title = clause.at("./title").remove.children.to_xml
|
102
|
-
bib["title"] = [bib["title"]] if bib["title"].is_a?(Hash) ||
|
103
|
-
bib["title"].is_a?(String)
|
104
|
-
bib["title"] ||= []
|
105
|
-
bib["title"] << title if !title.empty?
|
106
|
-
bib
|
107
|
-
end
|
108
|
-
|
109
|
-
# ---
|
110
|
-
|
111
4
|
def formattedref_spans(xmldoc)
|
112
5
|
xmldoc.xpath("//bibitem[formattedref//span]").each do |b|
|
113
6
|
spans = spans_preprocess(extract_content(b))
|
@@ -263,10 +156,11 @@ module Metanorma
|
|
263
156
|
|
264
157
|
def span_to_extent(span, key)
|
265
158
|
values = span.split(/[-–]/)
|
266
|
-
ret = "<extent type='#{key}'><
|
159
|
+
ret = "<extent type='#{key}'><locality>" \
|
160
|
+
"<referenceFrom>#{values[0]}</referenceFrom>"
|
267
161
|
values[1] and
|
268
162
|
ret += "<referenceTo>#{values[1]}</referenceTo>"
|
269
|
-
"#{ret}</extent>"
|
163
|
+
"#{ret}</locality></extent>"
|
270
164
|
end
|
271
165
|
|
272
166
|
def span_to_docid(span, key)
|
@@ -287,10 +181,10 @@ module Metanorma
|
|
287
181
|
|
288
182
|
def span_to_person(span)
|
289
183
|
pre = (span[:"formatted-initials"] and
|
290
|
-
"<formatted-initials>"\
|
184
|
+
"<formatted-initials>" \
|
291
185
|
"#{span[:"formatted-initials"]}</formatted-initials>") ||
|
292
186
|
"<forename>#{span[:givenname]}</forename>"
|
293
|
-
"<person><name>#{pre}<surname>#{span[:surname]}</surname></name>"\
|
187
|
+
"<person><name>#{pre}<surname>#{span[:surname]}</surname></name>" \
|
294
188
|
"</person>"
|
295
189
|
end
|
296
190
|
end
|
@@ -7,7 +7,8 @@ module Metanorma
|
|
7
7
|
def para_cleanup(xmldoc)
|
8
8
|
["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
|
9
9
|
"//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
|
10
|
-
"//
|
10
|
+
"//dl[not(ancestor::bibdata)]",
|
11
|
+
"//note[not(ancestor::bibitem or " \
|
11
12
|
"ancestor::table or ancestor::bibdata)]"].each do |w|
|
12
13
|
inject_id(xmldoc, w)
|
13
14
|
end
|
@@ -106,7 +107,7 @@ module Metanorma
|
|
106
107
|
prev = n.previous_element || next
|
107
108
|
n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
|
108
109
|
end
|
109
|
-
xmldoc.xpath("//note[@keep-separate] | "\
|
110
|
+
xmldoc.xpath("//note[@keep-separate] | " \
|
110
111
|
"//termnote[@keep-separate]").each do |n|
|
111
112
|
n.delete("keep-separate")
|
112
113
|
end
|
@@ -182,10 +183,10 @@ module Metanorma
|
|
182
183
|
end
|
183
184
|
|
184
185
|
def block_index_cleanup(xmldoc)
|
185
|
-
xmldoc.xpath("//quote | //td | //th | //formula | //li | //dt | "\
|
186
|
-
"//dd | //example | //note | //figure | //sourcecode | "\
|
187
|
-
"//admonition | //termnote | //termexample | //form | "\
|
188
|
-
"//requirement | //recommendation | //permission | "\
|
186
|
+
xmldoc.xpath("//quote | //td | //th | //formula | //li | //dt | " \
|
187
|
+
"//dd | //example | //note | //figure | //sourcecode | " \
|
188
|
+
"//admonition | //termnote | //termexample | //form | " \
|
189
|
+
"//requirement | //recommendation | //permission | " \
|
189
190
|
"//imagemap | //svgmap").each do |b|
|
190
191
|
b.xpath("./p[indexterm]").each do |p|
|
191
192
|
indexterm_para?(p) or next
|