metanorma-standoc 1.3.13 → 1.3.14
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/macos.yml +5 -1
- data/.github/workflows/ubuntu.yml +5 -1
- data/.github/workflows/windows.yml +5 -1
- data/lib/asciidoctor/standoc/base.rb +1 -0
- data/lib/asciidoctor/standoc/basicdoc.rng +20 -6
- data/lib/asciidoctor/standoc/cleanup.rb +13 -110
- data/lib/asciidoctor/standoc/cleanup_block.rb +5 -108
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_inline.rb +125 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -73
- data/lib/asciidoctor/standoc/cleanup_section.rb +195 -0
- data/lib/asciidoctor/standoc/front.rb +1 -88
- data/lib/asciidoctor/standoc/front_contributor.rb +99 -0
- data/lib/asciidoctor/standoc/isodoc.rng +532 -18
- data/lib/asciidoctor/standoc/macros.rb +79 -45
- data/lib/asciidoctor/standoc/reqt.rb +3 -1
- data/lib/asciidoctor/standoc/reqt.rng +2 -2
- data/lib/asciidoctor/standoc/validate.rb +4 -4
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor-standoc/base_spec.rb +2 -2
- data/spec/asciidoctor-standoc/blocks_spec.rb +10 -9
- data/spec/asciidoctor-standoc/cleanup_spec.rb +13 -11
- data/spec/asciidoctor-standoc/inline_spec.rb +1 -1
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -2
- data/spec/asciidoctor-standoc/macros_spec.rb +140 -2
- data/spec/asciidoctor-standoc/refs_spec.rb +4 -0
- data/spec/asciidoctor-standoc/section_spec.rb +14 -14
- data/spec/asciidoctor-standoc/validate_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f57016af79feef706f7aa6f7ed25429151d28a991a1256d18a7c7f360398a57
|
4
|
+
data.tar.gz: deb09cc891267c6e447284b92cb4a62681ec2663c80be7ff6e1e6c9c6b0e58ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f28f65b3aa564d8fba875a77237fe4841920cf05823cfc849a65c24b582ced8037ff719e6463526e673ee151f3f00898884141f395ac3ad996ef3e225e081b4
|
7
|
+
data.tar.gz: 44124272721075937694660b04f7bb1ad3b3348069aa2f56a4353befdd8311f49575686db43a27006b84a5e95173c8a9a4eaf763475baf803f7ffb663f393b4c
|
data/.github/workflows/macos.yml
CHANGED
@@ -17,6 +17,7 @@ module Asciidoctor
|
|
17
17
|
inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
|
18
18
|
inline_macro Asciidoctor::Standoc::DomainTermInlineMacro
|
19
19
|
inline_macro Asciidoctor::Standoc::HTML5RubyMacro
|
20
|
+
inline_macro Asciidoctor::Standoc::ConceptInlineMacro
|
20
21
|
block Asciidoctor::Standoc::ToDoAdmonitionBlock
|
21
22
|
treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
|
22
23
|
block Asciidoctor::Standoc::PlantUMLBlockMacro
|
@@ -55,9 +55,6 @@
|
|
55
55
|
<zeroOrMore>
|
56
56
|
<ref name="BasicBlock"/>
|
57
57
|
</zeroOrMore>
|
58
|
-
<zeroOrMore>
|
59
|
-
<ref name="note"/>
|
60
|
-
</zeroOrMore>
|
61
58
|
</define>
|
62
59
|
<define name="references">
|
63
60
|
<element name="references">
|
@@ -99,6 +96,10 @@
|
|
99
96
|
<ref name="example"/>
|
100
97
|
<ref name="review"/>
|
101
98
|
<ref name="pre"/>
|
99
|
+
<ref name="note"/>
|
100
|
+
<ref name="pagebreak"/>
|
101
|
+
<ref name="hr"/>
|
102
|
+
<ref name="bookmark"/>
|
102
103
|
</choice>
|
103
104
|
</define>
|
104
105
|
<define name="paragraph">
|
@@ -341,7 +342,14 @@
|
|
341
342
|
<define name="tname">
|
342
343
|
<element name="name">
|
343
344
|
<oneOrMore>
|
344
|
-
<
|
345
|
+
<choice>
|
346
|
+
<ref name="PureTextElement"/>
|
347
|
+
<ref name="eref"/>
|
348
|
+
<ref name="stem"/>
|
349
|
+
<ref name="keyword"/>
|
350
|
+
<ref name="xref"/>
|
351
|
+
<ref name="hyperlink"/>
|
352
|
+
</choice>
|
345
353
|
</oneOrMore>
|
346
354
|
</element>
|
347
355
|
</define>
|
@@ -592,14 +600,20 @@
|
|
592
600
|
<define name="em">
|
593
601
|
<element name="em">
|
594
602
|
<zeroOrMore>
|
595
|
-
<
|
603
|
+
<choice>
|
604
|
+
<ref name="PureTextElement"/>
|
605
|
+
<ref name="stem"/>
|
606
|
+
</choice>
|
596
607
|
</zeroOrMore>
|
597
608
|
</element>
|
598
609
|
</define>
|
599
610
|
<define name="strong">
|
600
611
|
<element name="strong">
|
601
612
|
<zeroOrMore>
|
602
|
-
<
|
613
|
+
<choice>
|
614
|
+
<ref name="PureTextElement"/>
|
615
|
+
<ref name="stem"/>
|
616
|
+
</choice>
|
603
617
|
</zeroOrMore>
|
604
618
|
</element>
|
605
619
|
</define>
|
@@ -6,6 +6,8 @@ require_relative "./cleanup_block.rb"
|
|
6
6
|
require_relative "./cleanup_footnotes.rb"
|
7
7
|
require_relative "./cleanup_ref.rb"
|
8
8
|
require_relative "./cleanup_boilerplate.rb"
|
9
|
+
require_relative "./cleanup_section.rb"
|
10
|
+
require_relative "./cleanup_inline.rb"
|
9
11
|
require "relaton_iev"
|
10
12
|
|
11
13
|
module Asciidoctor
|
@@ -43,11 +45,11 @@ module Asciidoctor
|
|
43
45
|
reference_names(xmldoc)
|
44
46
|
xref_cleanup(xmldoc)
|
45
47
|
origin_cleanup(xmldoc)
|
48
|
+
concept_cleanup(xmldoc)
|
46
49
|
RelatonIev::iev_cleanup(xmldoc, @bibdb)
|
47
50
|
element_name_cleanup(xmldoc)
|
48
51
|
bpart_cleanup(xmldoc)
|
49
52
|
quotesource_cleanup(xmldoc)
|
50
|
-
para_cleanup(xmldoc)
|
51
53
|
callout_cleanup(xmldoc)
|
52
54
|
footnote_cleanup(xmldoc)
|
53
55
|
empty_element_cleanup(xmldoc)
|
@@ -59,6 +61,7 @@ module Asciidoctor
|
|
59
61
|
requirement_cleanup(xmldoc)
|
60
62
|
bibdata_cleanup(xmldoc)
|
61
63
|
boilerplate_cleanup(xmldoc)
|
64
|
+
para_cleanup(xmldoc)
|
62
65
|
xmldoc
|
63
66
|
end
|
64
67
|
|
@@ -132,115 +135,6 @@ module Asciidoctor
|
|
132
135
|
align_callouts_to_annotations(xmldoc)
|
133
136
|
end
|
134
137
|
|
135
|
-
def termdef_stem_cleanup(xmldoc)
|
136
|
-
xmldoc.xpath("//term/p/stem").each do |a|
|
137
|
-
if a.parent.elements.size == 1 # para contains just a stem expression
|
138
|
-
t = Nokogiri::XML::Element.new("admitted", xmldoc)
|
139
|
-
parent = a.parent
|
140
|
-
t.children = a.remove
|
141
|
-
parent.replace(t)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def termdomain_cleanup(xmldoc)
|
147
|
-
xmldoc.xpath("//p/domain").each do |a|
|
148
|
-
prev = a.parent.previous
|
149
|
-
prev.next = a.remove
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def termdomain1_cleanup(xmldoc)
|
154
|
-
xmldoc.xpath("//domain").each do |d|
|
155
|
-
defn = d.at("../definition") and
|
156
|
-
defn.previous = d.remove
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def termdefinition_cleanup(xmldoc)
|
161
|
-
xmldoc.xpath("//term").each do |d|
|
162
|
-
first_child = d.at("./p | ./figure | ./formula") || return
|
163
|
-
t = Nokogiri::XML::Element.new("definition", xmldoc)
|
164
|
-
first_child.replace(t)
|
165
|
-
t << first_child.remove
|
166
|
-
d.xpath("./p | ./figure | ./formula").each { |n| t << n.remove }
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def termdef_unnest_cleanup(xmldoc)
|
171
|
-
# release termdef tags from surrounding paras
|
172
|
-
nodes = xmldoc.xpath("//p/admitted | //p/deprecates")
|
173
|
-
while !nodes.empty?
|
174
|
-
nodes[0].parent.replace(nodes[0].parent.children)
|
175
|
-
nodes = xmldoc.xpath("//p/admitted | //p/deprecates")
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def termdef_boilerplate_cleanup(xmldoc)
|
180
|
-
xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
|
181
|
-
end
|
182
|
-
|
183
|
-
def termdef_subclause_cleanup(xmldoc)
|
184
|
-
xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
|
185
|
-
end
|
186
|
-
|
187
|
-
def termdocsource_cleanup(xmldoc)
|
188
|
-
f = xmldoc.at("//preface | //sections")
|
189
|
-
xmldoc.xpath("//termdocsource").each do |s|
|
190
|
-
f.previous = s.remove
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def term_children_cleanup(xmldoc)
|
195
|
-
xmldoc.xpath("//term").each do |t|
|
196
|
-
t.xpath("./termnote").each { |n| t << n.remove }
|
197
|
-
t.xpath("./termexample").each { |n| t << n.remove }
|
198
|
-
t.xpath("./termsource").each { |n| t << n.remove }
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def termdef_cleanup(xmldoc)
|
203
|
-
termdef_unnest_cleanup(xmldoc)
|
204
|
-
termdef_stem_cleanup(xmldoc)
|
205
|
-
termdomain_cleanup(xmldoc)
|
206
|
-
termdefinition_cleanup(xmldoc)
|
207
|
-
termdomain1_cleanup(xmldoc)
|
208
|
-
termdef_boilerplate_cleanup(xmldoc)
|
209
|
-
termdef_subclause_cleanup(xmldoc)
|
210
|
-
term_children_cleanup(xmldoc)
|
211
|
-
termdocsource_cleanup(xmldoc)
|
212
|
-
end
|
213
|
-
|
214
|
-
def empty_text_before_first_element(x)
|
215
|
-
x.children.each do |c|
|
216
|
-
return false if c.text? and /\S/.match(c.text)
|
217
|
-
return true if c.element?
|
218
|
-
end
|
219
|
-
true
|
220
|
-
end
|
221
|
-
|
222
|
-
def strip_initial_space(x)
|
223
|
-
if x.children[0].text?
|
224
|
-
if !/\S/.match(x.children[0].text)
|
225
|
-
x.children[0].remove
|
226
|
-
else
|
227
|
-
x.children[0].content = x.children[0].text.gsub(/^ /, "")
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def bookmark_cleanup(xmldoc)
|
233
|
-
xmldoc.xpath("//li[descendant::bookmark]").each do |x|
|
234
|
-
if x&.elements&.first&.name == "p" &&
|
235
|
-
x&.elements&.first&.elements&.first&.name == "bookmark"
|
236
|
-
if empty_text_before_first_element(x.elements[0])
|
237
|
-
x["id"] = x.elements[0].elements[0].remove["id"]
|
238
|
-
strip_initial_space(x.elements[0])
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
138
|
def mathml_cleanup(xmldoc)
|
245
139
|
xmldoc.xpath("//stem[@type = 'MathML']").each do |x|
|
246
140
|
next if x.children.any? { |y| y.element? }
|
@@ -253,6 +147,15 @@ module Asciidoctor
|
|
253
147
|
x.children = math
|
254
148
|
end
|
255
149
|
end
|
150
|
+
|
151
|
+
# allows us to deal with doc relation localities,
|
152
|
+
# temporarily stashed to "bpart"
|
153
|
+
def bpart_cleanup(xmldoc)
|
154
|
+
xmldoc.xpath("//relation/bpart").each do |x|
|
155
|
+
extract_localities(x)
|
156
|
+
x.replace(x.children)
|
157
|
+
end
|
158
|
+
end
|
256
159
|
end
|
257
160
|
end
|
258
161
|
end
|
@@ -4,14 +4,15 @@ require "htmlentities"
|
|
4
4
|
require "json"
|
5
5
|
require "pathname"
|
6
6
|
require "open-uri"
|
7
|
-
require "pp"
|
8
7
|
|
9
8
|
module Asciidoctor
|
10
9
|
module Standoc
|
11
10
|
module Cleanup
|
12
11
|
def para_cleanup(xmldoc)
|
13
|
-
|
14
|
-
|
12
|
+
["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
|
13
|
+
"//ul[not(ancestor::bibdata)]",
|
14
|
+
"//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"
|
15
|
+
].each { |w| inject_id(xmldoc, w) }
|
15
16
|
end
|
16
17
|
|
17
18
|
def inject_id(xmldoc, path)
|
@@ -119,50 +120,6 @@ module Asciidoctor
|
|
119
120
|
subfigure_cleanup(xmldoc)
|
120
121
|
end
|
121
122
|
|
122
|
-
def make_preface(x, s)
|
123
|
-
if x.at("//foreword | //introduction")
|
124
|
-
preface = s.add_previous_sibling("<preface/>").first
|
125
|
-
foreword = x.at("//foreword")
|
126
|
-
preface.add_child foreword.remove if foreword
|
127
|
-
introduction = x.at("//introduction")
|
128
|
-
preface.add_child introduction.remove if introduction
|
129
|
-
end
|
130
|
-
make_abstract(x, s)
|
131
|
-
end
|
132
|
-
|
133
|
-
def make_abstract(x, s)
|
134
|
-
if x.at("//abstract[not(ancestor::bibitem)]")
|
135
|
-
preface = s.at("//preface") || s.add_previous_sibling("<preface/>").first
|
136
|
-
abstract = x.at("//abstract[not(ancestor::bibitem)]").remove
|
137
|
-
preface.prepend_child abstract.remove
|
138
|
-
bibabstract = bibabstract_location(x)
|
139
|
-
dupabstract = abstract.dup
|
140
|
-
dupabstract.traverse { |n| n.remove_attribute("id") }
|
141
|
-
dupabstract.remove_attribute("language")
|
142
|
-
dupabstract.remove_attribute("script")
|
143
|
-
bibabstract.next = dupabstract
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def bibabstract_location(x)
|
148
|
-
bibabstract = x.at("//bibdata/script") || x.at("//bibdata/language") ||
|
149
|
-
x.at("//bibdata/contributor[not(following-sibling::contributor)]") ||
|
150
|
-
x.at("//bibdata/date[not(following-sibling::date)]") ||
|
151
|
-
x.at("//docnumber") ||
|
152
|
-
x.at("//bibdata/docidentifier[not(following-sibling::docidentifier)]") ||
|
153
|
-
x.at("//bibdata/uri[not(following-sibling::uri)]") ||
|
154
|
-
x.at("//bibdata/title[not(following-sibling::title)]")
|
155
|
-
end
|
156
|
-
|
157
|
-
def make_bibliography(x, s)
|
158
|
-
if x.at("//sections/references")
|
159
|
-
biblio = s.add_next_sibling("<bibliography/>").first
|
160
|
-
x.xpath("//sections/references").each do |r|
|
161
|
-
biblio.add_child r.remove
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
123
|
ELEMS_ALLOW_NOTES =
|
167
124
|
%w[p formula ul ol dl figure].freeze
|
168
125
|
|
@@ -179,66 +136,6 @@ module Asciidoctor
|
|
179
136
|
end
|
180
137
|
end
|
181
138
|
|
182
|
-
def sections_order_cleanup(x)
|
183
|
-
s = x.at("//sections")
|
184
|
-
make_preface(x, s)
|
185
|
-
make_bibliography(x, s)
|
186
|
-
x.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
|
187
|
-
end
|
188
|
-
|
189
|
-
def maxlevel(x)
|
190
|
-
max = 5
|
191
|
-
x.xpath("//clause[@level]").each do |c|
|
192
|
-
max = c["level"].to_i if max < c["level"].to_i
|
193
|
-
end
|
194
|
-
max
|
195
|
-
end
|
196
|
-
|
197
|
-
def sections_level_cleanup(x)
|
198
|
-
m = maxlevel(x)
|
199
|
-
return if m < 6
|
200
|
-
m.downto(6).each do |l|
|
201
|
-
x.xpath("//clause[@level = '#{l}']").each do |c|
|
202
|
-
c.delete("level")
|
203
|
-
c.previous_element << c.remove
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def sections_cleanup(x)
|
209
|
-
sections_order_cleanup(x)
|
210
|
-
sections_level_cleanup(x)
|
211
|
-
end
|
212
|
-
|
213
|
-
def obligations_cleanup(x)
|
214
|
-
obligations_cleanup_info(x)
|
215
|
-
obligations_cleanup_norm(x)
|
216
|
-
obligations_cleanup_inherit(x)
|
217
|
-
end
|
218
|
-
|
219
|
-
def obligations_cleanup_info(x)
|
220
|
-
(s = x.at("//foreword")) && s["obligation"] = "informative"
|
221
|
-
(s = x.at("//introduction")) && s["obligation"] = "informative"
|
222
|
-
x.xpath("//references").each { |r| r["obligation"] = "informative" }
|
223
|
-
end
|
224
|
-
|
225
|
-
def obligations_cleanup_norm(x)
|
226
|
-
(s = x.at("//clause[title = 'Scope']")) && s["obligation"] = "normative"
|
227
|
-
(s = x.at("//clause[title = 'Symbols and Abbreviated Terms']")) &&
|
228
|
-
s["obligation"] = "normative"
|
229
|
-
x.xpath("//terms").each { |r| r["obligation"] = "normative" }
|
230
|
-
x.xpath("//symbols-abbrevs").each { |r| r["obligation"] = "normative" }
|
231
|
-
end
|
232
|
-
|
233
|
-
def obligations_cleanup_inherit(x)
|
234
|
-
x.xpath("//annex | //clause").each do |r|
|
235
|
-
r["obligation"] = "normative" unless r["obligation"]
|
236
|
-
end
|
237
|
-
x.xpath(Utils::SUBCLAUSE_XPATH).each do |r|
|
238
|
-
r["obligation"] = r.at("./ancestor::*/@obligation").text
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
139
|
def requirement_cleanup(x)
|
243
140
|
x.xpath("//requirement | //recommendation | //permission").each do |r|
|
244
141
|
r.children.each do |e|
|
@@ -258,7 +155,7 @@ module Asciidoctor
|
|
258
155
|
n = d.next.remove
|
259
156
|
d << n.children
|
260
157
|
end
|
261
|
-
r.xpath("./description[
|
158
|
+
r.xpath("./description[normalize-space(.)='']").each do |d|
|
262
159
|
d.replace("\n")
|
263
160
|
end
|
264
161
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def empty_text_before_first_element(x)
|
5
|
+
x.children.each do |c|
|
6
|
+
return false if c.text? and /\S/.match(c.text)
|
7
|
+
return true if c.element?
|
8
|
+
end
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def strip_initial_space(x)
|
13
|
+
if x.children[0].text?
|
14
|
+
if !/\S/.match(x.children[0].text)
|
15
|
+
x.children[0].remove
|
16
|
+
else
|
17
|
+
x.children[0].content = x.children[0].text.gsub(/^ /, "")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def bookmark_cleanup(xmldoc)
|
23
|
+
xmldoc.xpath("//li[descendant::bookmark]").each do |x|
|
24
|
+
if x&.elements&.first&.name == "p" &&
|
25
|
+
x&.elements&.first&.elements&.first&.name == "bookmark"
|
26
|
+
if empty_text_before_first_element(x.elements[0])
|
27
|
+
x["id"] = x.elements[0].elements[0].remove["id"]
|
28
|
+
strip_initial_space(x.elements[0])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# extending localities to cover ISO referencing
|
35
|
+
LOCALITY_REGEX_STR = <<~REGEXP.freeze
|
36
|
+
^((?<locality>section|clause|part|paragraph|chapter|page|
|
37
|
+
table|annex|figure|example|note|formula|list|
|
38
|
+
locality:[^ \\t\\n\\r:,]+)(\\s+|=)
|
39
|
+
(?<ref>[^"][^ \\t\\n,:-]*|"[^"]+")
|
40
|
+
(-(?<to>[^"][^ \\t\\n,:-]*|"[^"]"))?|
|
41
|
+
(?<locality2>whole|locality:[^ \\t\\n\\r:,]+))[,:]?\\s*
|
42
|
+
(?<text>.*)$
|
43
|
+
REGEXP
|
44
|
+
LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
|
45
|
+
Regexp::IGNORECASE | Regexp::MULTILINE)
|
46
|
+
|
47
|
+
def tq(x)
|
48
|
+
x.sub(/^"/, "").sub(/"$/, "")
|
49
|
+
end
|
50
|
+
|
51
|
+
def extract_localities(x)
|
52
|
+
text = x&.children&.first&.remove&.text
|
53
|
+
while (m = LOCALITY_RE.match text)
|
54
|
+
ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
|
55
|
+
refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
|
56
|
+
loc = m[:locality]&.downcase || m[:locality2]&.downcase
|
57
|
+
x.add_child("<locality type='#{loc}'>#{ref}#{refto}</locality>")
|
58
|
+
text = m[:text]
|
59
|
+
end
|
60
|
+
x.add_child(text) if text
|
61
|
+
end
|
62
|
+
|
63
|
+
def xref_to_eref(x)
|
64
|
+
x["bibitemid"] = x["target"]
|
65
|
+
x["citeas"] = @anchors&.dig(x["target"], :xref) ||
|
66
|
+
warn("#{x['target']} is not a real reference!")
|
67
|
+
x.delete("target")
|
68
|
+
extract_localities(x) unless x.children.empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
def xref_cleanup(xmldoc)
|
72
|
+
xmldoc.xpath("//xref").each do |x|
|
73
|
+
if refid? x["target"]
|
74
|
+
x.name = "eref"
|
75
|
+
xref_to_eref(x)
|
76
|
+
else
|
77
|
+
x.delete("type")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def quotesource_cleanup(xmldoc)
|
83
|
+
xmldoc.xpath("//quote/source | //terms/source").each do |x|
|
84
|
+
xref_to_eref(x)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def origin_cleanup(xmldoc)
|
89
|
+
xmldoc.xpath("//origin").each do |x|
|
90
|
+
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) ||
|
91
|
+
warn("#{x['bibitemid']} is not a real reference!")
|
92
|
+
extract_localities(x) unless x.children.empty?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def concept_cleanup(xmldoc)
|
97
|
+
xmldoc.xpath("//concept").each do |x|
|
98
|
+
x.delete("term") if x["term"].empty?
|
99
|
+
if /:/.match(x["key"]) then concept_termbase_cleanup(x)
|
100
|
+
elsif refid? x["key"] then concept_eref_cleanup(x)
|
101
|
+
else
|
102
|
+
concept_xref_cleanup(x)
|
103
|
+
end
|
104
|
+
x.delete("key")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def concept_termbase_cleanup(x)
|
109
|
+
text = x&.children&.first&.remove&.text
|
110
|
+
termbase, key = x["key"].split(/:/, 2)
|
111
|
+
x.add_child(%(<termref base="#{termbase}" target="#{key}">#{text}</termref>))
|
112
|
+
end
|
113
|
+
|
114
|
+
def concept_xref_cleanup(x)
|
115
|
+
text = x&.children&.first&.remove&.text
|
116
|
+
x.add_child(%(<xref target="#{x['key']}">#{text}</xref>))
|
117
|
+
end
|
118
|
+
|
119
|
+
def concept_eref_cleanup(x)
|
120
|
+
x.children = "<eref>#{x.children.to_xml}</eref>"
|
121
|
+
extract_localities(x.first_element_child)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -4,77 +4,6 @@ require "relaton_bib"
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Standoc
|
6
6
|
module Cleanup
|
7
|
-
# extending localities to cover ISO referencing
|
8
|
-
LOCALITY_REGEX_STR = <<~REGEXP.freeze
|
9
|
-
^((?<locality>section|clause|part|paragraph|chapter|page|
|
10
|
-
table|annex|figure|example|note|formula|list|
|
11
|
-
locality:[^ \\t\\n\\r:,]+)(\\s+|=)
|
12
|
-
(?<ref>[^"][^ \\t\\n,:-]*|"[^"]+")
|
13
|
-
(-(?<to>[^"][^ \\t\\n,:-]*|"[^"]"))?|
|
14
|
-
(?<locality2>whole|locality:[^ \\t\\n\\r:,]+))[,:]?\\s*
|
15
|
-
(?<text>.*)$
|
16
|
-
REGEXP
|
17
|
-
LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
|
18
|
-
Regexp::IGNORECASE | Regexp::MULTILINE)
|
19
|
-
|
20
|
-
def tq(x)
|
21
|
-
x.sub(/^"/, "").sub(/"$/, "")
|
22
|
-
end
|
23
|
-
|
24
|
-
def extract_localities(x)
|
25
|
-
text = x.children.first.remove.text
|
26
|
-
while (m = LOCALITY_RE.match text)
|
27
|
-
ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
|
28
|
-
refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
|
29
|
-
loc = m[:locality]&.downcase || m[:locality2]&.downcase
|
30
|
-
x.add_child("<locality type='#{loc}'>#{ref}#{refto}</locality>")
|
31
|
-
text = m[:text]
|
32
|
-
end
|
33
|
-
x.add_child(text)
|
34
|
-
end
|
35
|
-
|
36
|
-
def xref_to_eref(x)
|
37
|
-
x["bibitemid"] = x["target"]
|
38
|
-
x["citeas"] = @anchors&.dig(x["target"], :xref) ||
|
39
|
-
warn("#{x['target']} is not a real reference!")
|
40
|
-
x.delete("target")
|
41
|
-
extract_localities(x) unless x.children.empty?
|
42
|
-
end
|
43
|
-
|
44
|
-
def xref_cleanup(xmldoc)
|
45
|
-
xmldoc.xpath("//xref").each do |x|
|
46
|
-
if refid? x["target"]
|
47
|
-
x.name = "eref"
|
48
|
-
xref_to_eref(x)
|
49
|
-
else
|
50
|
-
x.delete("type")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# allows us to deal with doc relation localities,
|
56
|
-
# temporarily stashed to "bpart"
|
57
|
-
def bpart_cleanup(xmldoc)
|
58
|
-
xmldoc.xpath("//relation/bpart").each do |x|
|
59
|
-
extract_localities(x)
|
60
|
-
x.replace(x.children)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def quotesource_cleanup(xmldoc)
|
65
|
-
xmldoc.xpath("//quote/source | //terms/source").each do |x|
|
66
|
-
xref_to_eref(x)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def origin_cleanup(xmldoc)
|
71
|
-
xmldoc.xpath("//origin").each do |x|
|
72
|
-
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) ||
|
73
|
-
warn("#{x['bibitemid']} is not a real reference!")
|
74
|
-
extract_localities(x) unless x.children.empty?
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
7
|
def biblio_reorder(xmldoc)
|
79
8
|
xmldoc.xpath("//references[title = 'Bibliography']").each do |r|
|
80
9
|
biblio_reorder1(r)
|
@@ -85,8 +14,8 @@ module Asciidoctor
|
|
85
14
|
bib = sort_biblio(refs.xpath("./bibitem"))
|
86
15
|
refs.xpath("./bibitem").each { |b| b.remove }
|
87
16
|
bib.reverse.each do |b|
|
88
|
-
|
89
|
-
|
17
|
+
insert = refs.at("./title") and insert.next = b.to_xml or
|
18
|
+
refs.children.first.add_previous_sibling b.to_xml
|
90
19
|
end
|
91
20
|
refs.xpath("./references").each { |r| biblio_reorder1(r) }
|
92
21
|
end
|