metanorma-standoc 3.1.10 → 3.2.1
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/anchor.rb +3 -2
- data/lib/metanorma/standoc/base.rb +2 -2
- data/lib/metanorma/standoc/biblio.rng +4 -4
- data/lib/metanorma/standoc/blocks.rb +4 -8
- data/lib/metanorma/standoc/cleanup.rb +31 -61
- data/lib/metanorma/standoc/cleanup_asciibib.rb +7 -10
- data/lib/metanorma/standoc/cleanup_attachment.rb +1 -2
- data/lib/metanorma/standoc/cleanup_bibdata.rb +9 -0
- data/lib/metanorma/standoc/cleanup_bibitem.rb +29 -2
- data/lib/metanorma/standoc/cleanup_block.rb +1 -2
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +1 -2
- data/lib/metanorma/standoc/cleanup_footnotes.rb +1 -2
- data/lib/metanorma/standoc/cleanup_inline.rb +44 -4
- data/lib/metanorma/standoc/cleanup_maths.rb +3 -3
- data/lib/metanorma/standoc/cleanup_section_names.rb +1 -0
- data/lib/metanorma/standoc/cleanup_terms_boilerplate.rb +1 -3
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +2 -3
- data/lib/metanorma/standoc/cleanup_xref.rb +14 -11
- data/lib/metanorma/standoc/converter.rb +7 -5
- data/lib/metanorma/standoc/front.rb +27 -25
- data/lib/metanorma/standoc/front_committee.rb +5 -5
- data/lib/metanorma/standoc/front_contributor.rb +14 -14
- data/lib/metanorma/standoc/front_ext.rb +7 -5
- data/lib/metanorma/standoc/front_organisation.rb +16 -21
- data/lib/metanorma/standoc/init.rb +31 -5
- data/lib/metanorma/standoc/inline.rb +31 -12
- data/lib/metanorma/standoc/isodoc.rng +27 -10
- data/lib/metanorma/standoc/lists.rb +1 -1
- data/lib/metanorma/standoc/localbib.rb +5 -9
- data/lib/metanorma/standoc/log.rb +207 -0
- data/lib/metanorma/standoc/macros_embed.rb +5 -3
- data/lib/metanorma/standoc/macros_link.rb +2 -3
- data/lib/metanorma/standoc/macros_terms.rb +2 -0
- data/lib/metanorma/standoc/ref.rb +12 -13
- data/lib/metanorma/standoc/ref_queue.rb +4 -6
- data/lib/metanorma/standoc/ref_sect.rb +3 -6
- data/lib/metanorma/standoc/ref_utility.rb +4 -13
- data/lib/metanorma/standoc/section.rb +3 -9
- data/lib/metanorma/standoc/spans_to_bibitem.rb +12 -1
- data/lib/metanorma/standoc/spans_to_bibitem_preprocessing.rb +11 -7
- data/lib/metanorma/standoc/table.rb +1 -1
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +7 -18
- data/lib/metanorma/standoc/terms.rb +2 -4
- data/lib/metanorma/standoc/utils.rb +27 -2
- data/lib/metanorma/standoc/validate.rb +9 -17
- data/lib/metanorma/standoc/validate_image.rb +52 -9
- data/lib/metanorma/standoc/validate_schema.rb +3 -2
- data/lib/metanorma/standoc/validate_section.rb +3 -6
- data/lib/metanorma/standoc/validate_table.rb +3 -5
- data/lib/metanorma/standoc/validate_term.rb +4 -14
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +5 -3
- metadata +49 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10660a42ed7862e1985812db06bfba17b763ff8e2d1e30f61d09eb5739c1a0b9
|
|
4
|
+
data.tar.gz: 9e90a193f69f066f3d63650abb39abb3943f55cd2fe14474b72866dcf75e791b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70e5255195aba9303da9db4c2088997f59bc00bef4f4358548c77780a575a652a217519d05f6f37884f4f89c1f7601a19d88f6943bb2f2ec5f5ab75485368ac1
|
|
7
|
+
data.tar.gz: a5092f7c6848a6038e98aa9aafcee2170650d7f0b9160a796b807bf6ca85f607eedbfffaedf6d88eca797f56ca9509f0abada15f192f70c0e8b691d383b548c3
|
|
@@ -34,7 +34,7 @@ module Metanorma
|
|
|
34
34
|
t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
|
|
35
35
|
attrs, text = inline_anchor_xref_match(text)
|
|
36
36
|
attrs.empty? and
|
|
37
|
-
return { target: t, type: "inline", text:,
|
|
37
|
+
return { target: t, type: "inline", text:, defaultstyle: @xrefstyle }
|
|
38
38
|
inline_anchor_xref_attrs1(attrs, t, text)
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -50,7 +50,8 @@ module Metanorma
|
|
|
50
50
|
type: attrs.key?("fn") ? "footnote" : "inline",
|
|
51
51
|
case: %w(capital lowercase).detect { |x| attrs.key?(x) },
|
|
52
52
|
label: attrs["label"],
|
|
53
|
-
style: attrs["style"]
|
|
53
|
+
style: attrs["style"],
|
|
54
|
+
defaultstyle: @xrefstyle,
|
|
54
55
|
droploc: attrs.key?("droploc") || nil,
|
|
55
56
|
text: }.compact
|
|
56
57
|
end
|
|
@@ -22,7 +22,7 @@ module Metanorma
|
|
|
22
22
|
module Standoc
|
|
23
23
|
module Base
|
|
24
24
|
include IsolatedConverter
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
# XML_ROOT_TAG = "standard-document".freeze
|
|
27
27
|
# XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
|
|
28
28
|
FONTS_MANIFEST = "fonts-manifest".freeze
|
|
@@ -44,7 +44,7 @@ module Metanorma
|
|
|
44
44
|
clean_exit
|
|
45
45
|
ret
|
|
46
46
|
rescue StandardError => e
|
|
47
|
-
@log.add("
|
|
47
|
+
@log.add("STANDOC_50", nil, params: [e.message])
|
|
48
48
|
clean_exit
|
|
49
49
|
raise e
|
|
50
50
|
end
|
|
@@ -690,7 +690,7 @@ Examples include GRID, LEI, CrossRef, and Ringgold</a:documentation>
|
|
|
690
690
|
<define name="CitationType">
|
|
691
691
|
<attribute name="bibitemid">
|
|
692
692
|
<a:documentation>Bibliographic item that the citation applies to, referenced as the anchor of a bibliographic description</a:documentation>
|
|
693
|
-
<
|
|
693
|
+
<ref name="IdRefType"/>
|
|
694
694
|
</attribute>
|
|
695
695
|
<choice>
|
|
696
696
|
<zeroOrMore>
|
|
@@ -1296,17 +1296,17 @@ for which this claim of validity is made, if applicable</a:documentation>
|
|
|
1296
1296
|
</define>
|
|
1297
1297
|
<define name="validityBegins">
|
|
1298
1298
|
<element name="validityBegins">
|
|
1299
|
-
<ref name="
|
|
1299
|
+
<ref name="ISO8601DateTime"/>
|
|
1300
1300
|
</element>
|
|
1301
1301
|
</define>
|
|
1302
1302
|
<define name="validityEnds">
|
|
1303
1303
|
<element name="validityEnds">
|
|
1304
|
-
<ref name="
|
|
1304
|
+
<ref name="ISO8601DateTime"/>
|
|
1305
1305
|
</element>
|
|
1306
1306
|
</define>
|
|
1307
1307
|
<define name="validityRevision">
|
|
1308
1308
|
<element name="revision">
|
|
1309
|
-
<ref name="
|
|
1309
|
+
<ref name="ISO8601DateTime"/>
|
|
1310
1310
|
</element>
|
|
1311
1311
|
</define>
|
|
1312
1312
|
<define name="TypedTitleString">
|
|
@@ -48,9 +48,7 @@ module Metanorma
|
|
|
48
48
|
|
|
49
49
|
def block_title(node, out)
|
|
50
50
|
node.title.nil? and return
|
|
51
|
-
out
|
|
52
|
-
name << node.title
|
|
53
|
-
end
|
|
51
|
+
add_noko_elem(out, "name", node.title, id_attr(nil))
|
|
54
52
|
end
|
|
55
53
|
|
|
56
54
|
def form_attrs(node)
|
|
@@ -180,11 +178,10 @@ module Metanorma
|
|
|
180
178
|
if node.attr("citetitle")
|
|
181
179
|
m = /^(?<cite>[^,]+)(?:,(?<text>.*$))?$/m.match node.attr("citetitle")
|
|
182
180
|
out.source **attr_code(target: m[:cite], type: "inline") do |s|
|
|
183
|
-
s <<
|
|
181
|
+
s << m[:text]
|
|
184
182
|
end
|
|
185
183
|
end
|
|
186
|
-
node.attr("attribution")
|
|
187
|
-
out.author { |a| a << node.attr("attribution") }
|
|
184
|
+
add_noko_elem(out, "author", node.attr("attribution"))
|
|
188
185
|
end
|
|
189
186
|
|
|
190
187
|
def quote(node)
|
|
@@ -244,9 +241,8 @@ module Metanorma
|
|
|
244
241
|
# as it may be fragment, e.g. unterminated start of element markup
|
|
245
242
|
def passthrough_validate(node, content, encoded_content)
|
|
246
243
|
valid, = validate_document_fragment(content.dup)
|
|
247
|
-
err = "Invalid passthrough content: #{encoded_content}\n#{PASSTHRU_ERR}"
|
|
248
244
|
!valid and
|
|
249
|
-
@log.add("
|
|
245
|
+
@log.add("STANDOC_42", node, params: [encoded_content])
|
|
250
246
|
end
|
|
251
247
|
end
|
|
252
248
|
end
|
|
@@ -31,6 +31,7 @@ module Metanorma
|
|
|
31
31
|
element_name_cleanup(xmldoc)
|
|
32
32
|
source_include_cleanup(xmldoc) # feeds: misccontainer_cleanup
|
|
33
33
|
passthrough_cleanup(xmldoc) # feeds: smartquotes_cleanup
|
|
34
|
+
annotation_cleanup(xmldoc)
|
|
34
35
|
unnumbered_blocks_cleanup(xmldoc)
|
|
35
36
|
termdocsource_cleanup(xmldoc) # feeds: metadata_cleanup
|
|
36
37
|
metadata_cleanup(xmldoc) # feeds: boilerplate_cleanup, bibdata_cleanup,
|
|
@@ -83,7 +84,7 @@ module Metanorma
|
|
|
83
84
|
ext_contributor_cleanup(xmldoc) # feeds: bibdata_cleanup
|
|
84
85
|
ext_dochistory_cleanup(xmldoc) # feeds: bibdata_cleanup
|
|
85
86
|
bibdata_cleanup(xmldoc) # feeds: boilerplate_cleanup
|
|
86
|
-
boilerplate_cleanup(xmldoc) # feeds: xref_cleanup for new <<>>
|
|
87
|
+
boilerplate_cleanup(xmldoc) # feeds: xref_cleanup for new <<>>
|
|
87
88
|
# introduced, pres_metadata_cleanup
|
|
88
89
|
pres_metadata_cleanup(xmldoc)
|
|
89
90
|
xref_cleanup(xmldoc)
|
|
@@ -106,24 +107,34 @@ module Metanorma
|
|
|
106
107
|
def relaton_iev_cleanup(xmldoc)
|
|
107
108
|
_, err = RelatonIev::iev_cleanup(xmldoc, @bibdb)
|
|
108
109
|
err.each do |e|
|
|
109
|
-
@log.add("
|
|
110
|
+
@log.add("RELATON_5", nil, params: e)
|
|
110
111
|
end
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
RELATON_SEVERITIES =
|
|
114
|
-
{ "INFO":
|
|
115
|
-
"UNKNOWN":
|
|
115
|
+
{ "INFO": "RELATON_4", "WARN": "RELATON_3", "ERROR": "RELATON_2",
|
|
116
|
+
"FATAL": "RELATON_1", "UNKNOWN": "RELATON_4" }.freeze
|
|
116
117
|
|
|
117
118
|
def relaton_log_cleanup(_xmldoc)
|
|
118
119
|
@relaton_log or return
|
|
119
120
|
@relaton_log.rewind
|
|
120
121
|
@relaton_log.string.split(/(?<=})\n(?={)/).each do |l|
|
|
121
122
|
e = JSON.parse(l)
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
relaton_log_add?(e) and
|
|
124
|
+
@log.add(RELATON_SEVERITIES[e["severity"].to_sym], e["key"],
|
|
125
|
+
params: [e["message"]])
|
|
124
126
|
end
|
|
125
127
|
end
|
|
126
128
|
|
|
129
|
+
def relaton_log_add?(entry)
|
|
130
|
+
entry["message"].include?("Fetching from") and return false
|
|
131
|
+
entry["message"].include?("Downloaded index from") and return false
|
|
132
|
+
entry["message"].start_with?("Found:") or return true
|
|
133
|
+
id = /^Found: `(.+)`$/.match(entry["message"]) or return true
|
|
134
|
+
entry["key"].end_with?(id[1]) and return false
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
|
|
127
138
|
def docidentifier_cleanup(xmldoc); end
|
|
128
139
|
|
|
129
140
|
TEXT_ELEMS =
|
|
@@ -142,9 +153,8 @@ module Metanorma
|
|
|
142
153
|
|
|
143
154
|
def empty_element_cleanup(xmldoc)
|
|
144
155
|
xmldoc.xpath("//#{TEXT_ELEMS.join(' | //')}").each do |x|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
x.remove if x.children.empty?
|
|
156
|
+
x.name == "name" && x.parent.name == "expression" and next
|
|
157
|
+
x.children.empty? and x.remove
|
|
148
158
|
end
|
|
149
159
|
end
|
|
150
160
|
|
|
@@ -152,58 +162,6 @@ module Metanorma
|
|
|
152
162
|
xmldoc.traverse { |n| n.name = n.name.tr("_", "-") }
|
|
153
163
|
end
|
|
154
164
|
|
|
155
|
-
# allows us to deal with doc relation localities,
|
|
156
|
-
# temporarily stashed to "bpart"
|
|
157
|
-
def bpart_cleanup(xmldoc)
|
|
158
|
-
xmldoc.xpath("//relation/bpart").each do |x|
|
|
159
|
-
extract_localities(x)
|
|
160
|
-
x.replace(x.children)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def variant_cleanup(xmldoc)
|
|
165
|
-
variant_space_cleanup(xmldoc)
|
|
166
|
-
xmldoc.xpath("//*[lang-variant]").each do |c|
|
|
167
|
-
if only_langvariant_children?(c)
|
|
168
|
-
duplicate_langvariants(c, c.xpath("./lang-variant"))
|
|
169
|
-
else
|
|
170
|
-
c.xpath(".//lang-variant").each { |x| x.name = "span" }
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def only_langvariant_children?(node)
|
|
176
|
-
node.children.none? do |n|
|
|
177
|
-
n.name != "lang-variant" && (!n.text? || !n.text.strip.empty?)
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def duplicate_langvariants(container, variants)
|
|
182
|
-
lang_variant_to_node(variants.first, container)
|
|
183
|
-
variants[1..].reverse.each do |node|
|
|
184
|
-
new = container.dup
|
|
185
|
-
lang_variant_to_node(node, new)
|
|
186
|
-
container.next = new
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def lang_variant_to_node(variant, node)
|
|
191
|
-
node.children = variant.children
|
|
192
|
-
node["lang"] = variant["lang"]
|
|
193
|
-
node.delete("script")
|
|
194
|
-
variant["script"] and node["script"] = variant["script"]
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def variant_space_cleanup(xmldoc)
|
|
198
|
-
xmldoc.xpath("//*[lang-variant]").each do |c|
|
|
199
|
-
c.next.nil? || c.next.next.nil? and next
|
|
200
|
-
if c.next.text? && c.next.next.name == "lang-variant"
|
|
201
|
-
c.next.text.gsub(/\s/, "").empty? and
|
|
202
|
-
c.next.remove
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
165
|
def metadata_cleanup(xmldoc)
|
|
208
166
|
bibdata_published(xmldoc) # feeds: bibdata_cleanup,
|
|
209
167
|
# docidentifier_cleanup (in generic: template)
|
|
@@ -221,6 +179,18 @@ module Metanorma
|
|
|
221
179
|
x.children = @isodoc.populate_template(to_xml(x.children), nil)
|
|
222
180
|
end
|
|
223
181
|
end
|
|
182
|
+
|
|
183
|
+
def annotation_cleanup(xmldoc)
|
|
184
|
+
ret = xmldoc.xpath("//annotation[@type = 'ignore-log']")
|
|
185
|
+
.each_with_object([]) do |ann, m|
|
|
186
|
+
error_ids = Array(csv_split(ann.text || "", ","))
|
|
187
|
+
m << { from: ann["from"], to: ann["to"], error_ids: error_ids }
|
|
188
|
+
ann
|
|
189
|
+
end
|
|
190
|
+
config = @log.suppress_log
|
|
191
|
+
config[:locations] += ret
|
|
192
|
+
@log.suppress_log = config
|
|
193
|
+
end
|
|
224
194
|
end
|
|
225
195
|
end
|
|
226
196
|
end
|
|
@@ -26,9 +26,7 @@ module Metanorma
|
|
|
26
26
|
id = bib["id"]
|
|
27
27
|
id ||= clause["anchor"] unless /^_/.match?(clause["anchor"])
|
|
28
28
|
unless id
|
|
29
|
-
@log.add("
|
|
30
|
-
"The following reference is missing an anchor:\n" \
|
|
31
|
-
"#{clause.to_xml}", severity: 1)
|
|
29
|
+
@log.add("STANDOC_10", clause, params: [clause.to_xml])
|
|
32
30
|
return
|
|
33
31
|
end
|
|
34
32
|
@refids << id
|
|
@@ -36,13 +34,12 @@ module Metanorma
|
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
def validate_ref_dl1(bib, id, clause)
|
|
39
|
-
bib["title"]
|
|
40
|
-
@log.add("
|
|
41
|
-
|
|
42
|
-
bib["docid"]
|
|
43
|
-
@log.add("
|
|
44
|
-
|
|
45
|
-
severity: 1)
|
|
37
|
+
if !bib["title"]
|
|
38
|
+
@log.add("STANDOC_11", clause, params: [id])
|
|
39
|
+
end
|
|
40
|
+
if !bib["docid"]
|
|
41
|
+
@log.add("STANDOC_12", clause, params: [id])
|
|
42
|
+
end
|
|
46
43
|
end
|
|
47
44
|
|
|
48
45
|
def extract_from_p(tag, bib, key)
|
|
@@ -53,8 +53,7 @@ module Metanorma
|
|
|
53
53
|
def valid_attachment?(path, bib)
|
|
54
54
|
File.exist?(path) and return true
|
|
55
55
|
p = Pathname.new(path).cleanpath
|
|
56
|
-
@log.add("
|
|
57
|
-
severity: 0)
|
|
56
|
+
@log.add("STANDOC_9", bib, params: [p])
|
|
58
57
|
false
|
|
59
58
|
end
|
|
60
59
|
|
|
@@ -196,6 +196,15 @@ module Metanorma
|
|
|
196
196
|
def published?(stage, _xmldoc)
|
|
197
197
|
stage.casecmp("published").zero?
|
|
198
198
|
end
|
|
199
|
+
|
|
200
|
+
# allows us to deal with doc relation localities,
|
|
201
|
+
# temporarily stashed to "bpart"
|
|
202
|
+
def bpart_cleanup(xmldoc)
|
|
203
|
+
xmldoc.xpath("//relation/bpart").each do |x|
|
|
204
|
+
extract_localities(x)
|
|
205
|
+
x.replace(x.children)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
199
208
|
end
|
|
200
209
|
end
|
|
201
210
|
end
|
|
@@ -16,13 +16,14 @@ module Metanorma
|
|
|
16
16
|
def new_bibitem_from_formattedref_spans(bib)
|
|
17
17
|
ret = SpansToBibitem.new(bib).convert
|
|
18
18
|
ret.err.each do |e|
|
|
19
|
-
@log.add(
|
|
19
|
+
@log.add(e[:fatal] ? "STANDOC_52" : "STANDOC_53",
|
|
20
|
+
bib, params: [e[:msg]])
|
|
20
21
|
end
|
|
21
22
|
ret.out
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def merge_bibitem_from_formattedref_spans(bib, new)
|
|
25
|
-
|
|
26
|
+
merge_bibitem_from_formattedref_span_attrs(bib, new)
|
|
26
27
|
if bib.at("./title") && bib["amend"]
|
|
27
28
|
# there already is a fetched record here: merge
|
|
28
29
|
bib.children = MergeBibitems
|
|
@@ -33,6 +34,12 @@ module Metanorma
|
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
def merge_bibitem_from_formattedref_span_attrs(bib, new)
|
|
38
|
+
%w(type).each do |k|
|
|
39
|
+
new[k] and bib[k] = new[k]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
36
43
|
def fold_notes_into_biblio(refs)
|
|
37
44
|
refs.xpath("./bibitem").each do |r|
|
|
38
45
|
while r&.next_element&.name == "note"
|
|
@@ -194,6 +201,25 @@ module Metanorma
|
|
|
194
201
|
bibitem.parent["normative"] == "true"
|
|
195
202
|
end
|
|
196
203
|
|
|
204
|
+
def bibitem_i18n(xmldoc)
|
|
205
|
+
xmldoc.xpath("//references/bibitem").each do |b|
|
|
206
|
+
s = b.at("./script")
|
|
207
|
+
l = b.at("./language")
|
|
208
|
+
s && l and next
|
|
209
|
+
ins = bibitem_i18n_insert(b)
|
|
210
|
+
s or ins.next = "<script>#{@script}</script>"
|
|
211
|
+
l or ins.next = "<language>#{@lang}</language>"
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def bibitem_i18n_insert(bib)
|
|
216
|
+
bib.at("./note[last()]") || bib.at("./version[last()]") ||
|
|
217
|
+
bib.at("./edition[last()]") || bib.at("./contributor[last()]") ||
|
|
218
|
+
bib.at("./date[last()]") || bib.at("./docnumber[last()]") ||
|
|
219
|
+
bib.at("./docidentifier[last()]") || bib.at("./source[last()]") ||
|
|
220
|
+
bib.at("./title[last()]") || bib.children.first
|
|
221
|
+
end
|
|
222
|
+
|
|
197
223
|
def bibitem_cleanup(xmldoc)
|
|
198
224
|
bibitem_nested_id(xmldoc) # feeds remove_dup_bibtem_id
|
|
199
225
|
ref_dl_cleanup(xmldoc)
|
|
@@ -202,6 +228,7 @@ module Metanorma
|
|
|
202
228
|
remove_empty_docid(xmldoc)
|
|
203
229
|
empty_docid_to_title(xmldoc)
|
|
204
230
|
remove_dup_bibtem_id(xmldoc)
|
|
231
|
+
bibitem_i18n(xmldoc)
|
|
205
232
|
attachment_cleanup(xmldoc)
|
|
206
233
|
end
|
|
207
234
|
end
|
|
@@ -233,8 +233,7 @@ module Metanorma
|
|
|
233
233
|
def ol_cleanup(doc)
|
|
234
234
|
doc.xpath("//ol[@explicit-type]").each do |x|
|
|
235
235
|
x.delete("explicit-type")
|
|
236
|
-
@log.add("
|
|
237
|
-
"Style override set for ordered list", display: false)
|
|
236
|
+
@log.add("STANDOC_14", x, display: false)
|
|
238
237
|
end
|
|
239
238
|
end
|
|
240
239
|
|
|
@@ -116,8 +116,7 @@ module Metanorma
|
|
|
116
116
|
filename.nil? || filename.empty? and return
|
|
117
117
|
filename = filename.strip
|
|
118
118
|
unless File.exist?(filename)
|
|
119
|
-
|
|
120
|
-
@log.add("Include", nil, msg, severity: 0)
|
|
119
|
+
@log.add("STANDOC_1", nil, params: [filename])
|
|
121
120
|
return
|
|
122
121
|
end
|
|
123
122
|
|
|
@@ -112,8 +112,7 @@ module Metanorma
|
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
def footnote_block_error(fnote)
|
|
115
|
-
@log.add("
|
|
116
|
-
"Could not resolve footnoteblock:[#{fnote.text}]", severity: 1)
|
|
115
|
+
@log.add("STANDOC_15", fnote, params: [fnote.text])
|
|
117
116
|
fnote.children = "[ERROR]"
|
|
118
117
|
end
|
|
119
118
|
|
|
@@ -18,8 +18,7 @@ module Metanorma
|
|
|
18
18
|
a.text? or return
|
|
19
19
|
if /\S/.match?(a.text)
|
|
20
20
|
a.content = a.text.lstrip
|
|
21
|
-
else
|
|
22
|
-
a.remove
|
|
21
|
+
else a.remove
|
|
23
22
|
end
|
|
24
23
|
end
|
|
25
24
|
|
|
@@ -174,8 +173,7 @@ module Metanorma
|
|
|
174
173
|
xmldoc.xpath("//link[@target]").each do |l|
|
|
175
174
|
l["target"] = Addressable::URI.parse(l["target"]).to_s
|
|
176
175
|
rescue Addressable::URI::InvalidURIError
|
|
177
|
-
|
|
178
|
-
@log.add("Anchors", l, err, severity: 0)
|
|
176
|
+
@log.add("STANDOC_8", l, params: [l["target"]])
|
|
179
177
|
end
|
|
180
178
|
end
|
|
181
179
|
|
|
@@ -190,6 +188,48 @@ module Metanorma
|
|
|
190
188
|
end
|
|
191
189
|
end
|
|
192
190
|
|
|
191
|
+
def variant_cleanup(xmldoc)
|
|
192
|
+
variant_space_cleanup(xmldoc)
|
|
193
|
+
xmldoc.xpath("//*[lang-variant]").each do |c|
|
|
194
|
+
if only_langvariant_children?(c)
|
|
195
|
+
duplicate_langvariants(c, c.xpath("./lang-variant"))
|
|
196
|
+
else
|
|
197
|
+
c.xpath(".//lang-variant").each { |x| x.name = "span" }
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def only_langvariant_children?(node)
|
|
203
|
+
node.children.none? do |n|
|
|
204
|
+
n.name != "lang-variant" && (!n.text? || !n.text.strip.empty?)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def duplicate_langvariants(container, variants)
|
|
209
|
+
lang_variant_to_node(variants.first, container)
|
|
210
|
+
variants[1..].reverse.each do |node|
|
|
211
|
+
new = container.dup
|
|
212
|
+
lang_variant_to_node(node, new)
|
|
213
|
+
container.next = new
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def lang_variant_to_node(variant, node)
|
|
218
|
+
node.children = variant.children
|
|
219
|
+
node["lang"] = variant["lang"]
|
|
220
|
+
node.delete("script")
|
|
221
|
+
variant["script"] and node["script"] = variant["script"]
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def variant_space_cleanup(xmldoc)
|
|
225
|
+
xmldoc.xpath("//*[lang-variant]").each do |c|
|
|
226
|
+
c.next.nil? || c.next.next.nil? and next
|
|
227
|
+
c.next.text? && c.next.next.name == "lang-variant" &&
|
|
228
|
+
c.next.text.gsub(/\s/, "").empty? and
|
|
229
|
+
c.next.remove
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
193
233
|
private
|
|
194
234
|
|
|
195
235
|
# skip ZWNJ inserted to prevent regexes operating in asciidoctor
|
|
@@ -39,15 +39,15 @@ module Metanorma
|
|
|
39
39
|
expr.strip.empty? and return
|
|
40
40
|
unitsml = if expr.include?("unitsml")
|
|
41
41
|
{ unitsml: { xml: true, multiplier: :space } }
|
|
42
|
-
else {}
|
|
42
|
+
else {}
|
|
43
|
+
end
|
|
43
44
|
Plurimath::Math.parse(expr, "asciimath")
|
|
44
45
|
.to_mathml(**{ display_style: elem["block"] }.merge(unitsml))
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def asciimath2mathml_err(text, expr)
|
|
49
|
-
|
|
50
|
-
@log.add("Maths", nil, err, severity: 0)
|
|
50
|
+
@log.add("STANDOC_6", nil, params: [expr, text])
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def asciimath2mathml_wrap(xml)
|
|
@@ -30,9 +30,7 @@ module Metanorma
|
|
|
30
30
|
def verify_term_defs_source(source)
|
|
31
31
|
source.each do |s|
|
|
32
32
|
@anchors[s["bibitemid"]] or
|
|
33
|
-
@log.add("
|
|
34
|
-
"term source #{s['bibitemid']} not referenced",
|
|
35
|
-
severity: 1)
|
|
33
|
+
@log.add("STANDOC_28", nil, params: [s["bibitemid"]])
|
|
36
34
|
end
|
|
37
35
|
end
|
|
38
36
|
|
|
@@ -116,8 +116,7 @@ module Metanorma
|
|
|
116
116
|
def dl_to_designation(dlist)
|
|
117
117
|
prev = dlist.previous_element
|
|
118
118
|
unless %w(preferred admitted deprecates related).include? prev&.name
|
|
119
|
-
@log.add("
|
|
120
|
-
"not follow a term designation")
|
|
119
|
+
@log.add("STANDOC_20", dlist)
|
|
121
120
|
return nil
|
|
122
121
|
end
|
|
123
122
|
prev
|
|
@@ -182,7 +181,7 @@ module Metanorma
|
|
|
182
181
|
DESIGNATOR.each do |n|
|
|
183
182
|
t.xpath("./#{n}/expression/name").each_with_object([]) do |d, m|
|
|
184
183
|
if m.include?(d.text)
|
|
185
|
-
@log.add("
|
|
184
|
+
@log.add("STANDOC_21", t, params: [d.text])
|
|
186
185
|
d.parent.parent.remove
|
|
187
186
|
end
|
|
188
187
|
m << d.text
|
|
@@ -85,15 +85,14 @@ module Metanorma
|
|
|
85
85
|
else xref_to_eref1(elem)
|
|
86
86
|
end
|
|
87
87
|
elem.delete("target")
|
|
88
|
+
elem.delete("defaultstyle") # xrefstyle default
|
|
88
89
|
extract_localities(elem)
|
|
89
90
|
end
|
|
90
91
|
|
|
91
92
|
def xref_to_eref1(elem)
|
|
92
93
|
elem["citeas"] = ""
|
|
93
94
|
@internal_eref_namespaces.include?(elem["type"]) or
|
|
94
|
-
@log.add("
|
|
95
|
-
"#{elem['target']} does not have a corresponding " \
|
|
96
|
-
"anchor ID in the bibliography!")
|
|
95
|
+
@log.add("STANDOC_30", elem, params: [elem["target"]])
|
|
97
96
|
end
|
|
98
97
|
|
|
99
98
|
def xref_cleanup(xmldoc)
|
|
@@ -161,8 +160,7 @@ module Metanorma
|
|
|
161
160
|
y.size == 1 and
|
|
162
161
|
y.unshift(l.dig(i + 1, 0) == "to" ? "from" : "and")
|
|
163
162
|
%w(and from to or).include?(y[0]) or
|
|
164
|
-
@log.add("
|
|
165
|
-
"Illegal cross-reference connective: #{y[0]}", severity: 0)
|
|
163
|
+
@log.add("STANDOC_31", xref, params: [y[0]])
|
|
166
164
|
y
|
|
167
165
|
end
|
|
168
166
|
end
|
|
@@ -182,10 +180,11 @@ module Metanorma
|
|
|
182
180
|
xmldoc.xpath("//xref").each do |x|
|
|
183
181
|
%r{:(?!//)}.match?(x["target"]) and xref_to_internal_eref(x)
|
|
184
182
|
x.name == "xref" or next
|
|
185
|
-
if refid? x["target"]
|
|
186
|
-
xref_to_eref(x, "eref")
|
|
183
|
+
if refid? x["target"] then xref_to_eref(x, "eref")
|
|
187
184
|
elsif @anchor_alias[x["target"]] then xref_alias(x)
|
|
188
|
-
else
|
|
185
|
+
else
|
|
186
|
+
x.delete("type")
|
|
187
|
+
xref_default_style(x)
|
|
189
188
|
end
|
|
190
189
|
end
|
|
191
190
|
end
|
|
@@ -206,6 +205,12 @@ module Metanorma
|
|
|
206
205
|
elem["style"] == "id" && elem.text.strip.empty? and
|
|
207
206
|
elem << elem["target"]
|
|
208
207
|
elem["target"] = @anchor_alias[elem["target"]]
|
|
208
|
+
xref_default_style(elem)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def xref_default_style(elem)
|
|
212
|
+
elem["defaultstyle"] and elem["style"] ||= elem["defaultstyle"]
|
|
213
|
+
elem.delete("defaultstyle")
|
|
209
214
|
end
|
|
210
215
|
|
|
211
216
|
def quotesource_cleanup(xmldoc)
|
|
@@ -220,9 +225,7 @@ module Metanorma
|
|
|
220
225
|
end
|
|
221
226
|
xmldoc.xpath("//origin").each do |x|
|
|
222
227
|
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) or
|
|
223
|
-
@log.add("
|
|
224
|
-
"#{x['bibitemid']} does not have a corresponding anchor " \
|
|
225
|
-
"ID in the bibliography!")
|
|
228
|
+
@log.add("STANDOC_32", x, params: [x["bibitemid"]])
|
|
226
229
|
extract_localities(x)
|
|
227
230
|
end
|
|
228
231
|
end
|
|
@@ -14,6 +14,7 @@ require_relative "utils"
|
|
|
14
14
|
require_relative "cleanup"
|
|
15
15
|
require_relative "reqt"
|
|
16
16
|
require_relative "macros"
|
|
17
|
+
require_relative "log"
|
|
17
18
|
|
|
18
19
|
module Metanorma
|
|
19
20
|
module Standoc
|
|
@@ -117,9 +118,11 @@ module Metanorma
|
|
|
117
118
|
end
|
|
118
119
|
|
|
119
120
|
def local_log(doc)
|
|
120
|
-
@log = doc&.options&.dig(:log)
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
unless @log = doc&.options&.dig(:log)
|
|
122
|
+
@log = Metanorma::Utils::Log.new
|
|
123
|
+
@local_log = true
|
|
124
|
+
end
|
|
125
|
+
@log.add_msg(log_messages)
|
|
123
126
|
end
|
|
124
127
|
|
|
125
128
|
class << self
|
|
@@ -141,8 +144,7 @@ module Metanorma
|
|
|
141
144
|
|
|
142
145
|
def skip(node, name = nil)
|
|
143
146
|
name = name || node.node_name
|
|
144
|
-
|
|
145
|
-
@log.add("AsciiDoc Input", node, w, severity: 1)
|
|
147
|
+
@log.add("STANDOC_29", node, params: [name])
|
|
146
148
|
nil
|
|
147
149
|
end
|
|
148
150
|
|