metanorma-standoc 2.8.11 → 2.9.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/.rubocop.yml +1 -1
- data/lib/metanorma/standoc/anchor.rb +3 -3
- data/lib/metanorma/standoc/base.rb +1 -1
- data/lib/metanorma/standoc/blocks.rb +5 -5
- data/lib/metanorma/standoc/blocks_image.rb +1 -1
- data/lib/metanorma/standoc/blocks_notes.rb +6 -6
- data/lib/metanorma/standoc/cleanup.rb +15 -0
- data/lib/metanorma/standoc/cleanup_block.rb +1 -1
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +67 -31
- data/lib/metanorma/standoc/cleanup_maths.rb +24 -1
- data/lib/metanorma/standoc/cleanup_ref.rb +0 -1
- data/lib/metanorma/standoc/cleanup_section.rb +5 -9
- data/lib/metanorma/standoc/cleanup_section_names.rb +5 -5
- data/lib/metanorma/standoc/cleanup_terms.rb +6 -5
- data/lib/metanorma/standoc/cleanup_xref.rb +6 -10
- data/lib/metanorma/standoc/converter.rb +1 -0
- data/lib/metanorma/standoc/init.rb +23 -2
- data/lib/metanorma/standoc/inline.rb +5 -5
- data/lib/metanorma/standoc/isodoc.rng +5 -5
- data/lib/metanorma/standoc/lists.rb +4 -4
- data/lib/metanorma/standoc/macros.rb +16 -44
- data/lib/metanorma/standoc/macros_embed.rb +14 -12
- data/lib/metanorma/standoc/macros_inline.rb +38 -75
- data/lib/metanorma/standoc/macros_link.rb +81 -0
- data/lib/metanorma/standoc/ref.rb +9 -12
- data/lib/metanorma/standoc/ref_queue.rb +2 -4
- data/lib/metanorma/standoc/ref_utility.rb +2 -2
- data/lib/metanorma/standoc/section.rb +3 -3
- data/lib/metanorma/standoc/terms.rb +2 -2
- data/lib/metanorma/standoc/utils.rb +22 -2
- data/lib/metanorma/standoc/validate.rb +14 -2
- data/lib/metanorma/standoc/validate_table.rb +7 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +5 -4
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08c688771192b46a0cabe0ec82dc8b88902a49577b4af1fafb8c3efc00192a6d'
|
4
|
+
data.tar.gz: 27b915f4d6ba5ebe4c8a16cf1c02a26f9cf37af524d6d3bdbc145ce360280df7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0717e6c250f4ae7b649ce1943abf0665dad4abdf1b9b20021681e64a141967c34d53a3ed4de04b8112a4cc8ea8df79f4afd46ea96aa28622d2b6d0314f349a0
|
7
|
+
data.tar.gz: 41d8468137fd2b538597dd8379b1364f189c0d500cba23b691513754a84eb3423aa8eb46794258cdad7e21c799f518b305f46240817d4858dcb24d8848050a80
|
data/.rubocop.yml
CHANGED
@@ -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:, style: @xrefstyle }
|
38
38
|
inline_anchor_xref_attrs1(attrs, t, text)
|
39
39
|
end
|
40
40
|
|
@@ -46,13 +46,13 @@ module Metanorma
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def inline_anchor_xref_attrs1(attrs, target, text)
|
49
|
-
{ target
|
49
|
+
{ target:, hidden: attrs["hidden"],
|
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
53
|
style: attrs["style"] || @xrefstyle,
|
54
54
|
droploc: attrs.key?("droploc") ? true : nil,
|
55
|
-
text:
|
55
|
+
text: }.compact
|
56
56
|
end
|
57
57
|
|
58
58
|
XREF_ATTRS = "hidden|style|droploc|capital|lowercase|label".freeze
|
@@ -130,7 +130,7 @@ module Metanorma
|
|
130
130
|
%w(presentation semantic).each do |t|
|
131
131
|
/^#{t}-metadata-/.match?(k) or next
|
132
132
|
k = k.sub(/^#{t}-metadata-/, "")
|
133
|
-
|
133
|
+
quoted_csv_split(v)&.each do |c|
|
134
134
|
ret << "<#{t}-metadata><#{k}>#{c}</#{k}></#{t}-metadata>"
|
135
135
|
end
|
136
136
|
end
|
@@ -90,7 +90,7 @@ module Metanorma
|
|
90
90
|
)) do |ex|
|
91
91
|
wrap_in_para(node, ex)
|
92
92
|
end
|
93
|
-
end.join("
|
93
|
+
end.join("")
|
94
94
|
end
|
95
95
|
|
96
96
|
def example(node)
|
@@ -128,7 +128,7 @@ module Metanorma
|
|
128
128
|
figure_title(node, ex)
|
129
129
|
wrap_in_para(node, ex)
|
130
130
|
end
|
131
|
-
end.join("
|
131
|
+
end.join("")
|
132
132
|
end
|
133
133
|
|
134
134
|
def example_attrs(node)
|
@@ -141,7 +141,7 @@ module Metanorma
|
|
141
141
|
node.title.nil? or ex.name { |name| name << node.title }
|
142
142
|
wrap_in_para(node, ex)
|
143
143
|
end
|
144
|
-
end.join("
|
144
|
+
end.join("")
|
145
145
|
end
|
146
146
|
|
147
147
|
def para_attrs(node)
|
@@ -158,7 +158,7 @@ module Metanorma
|
|
158
158
|
xml.p **para_attrs(node) do |xml_t|
|
159
159
|
xml_t << node.content
|
160
160
|
end
|
161
|
-
end.join("
|
161
|
+
end.join("")
|
162
162
|
end
|
163
163
|
|
164
164
|
def quote_attrs(node)
|
@@ -183,7 +183,7 @@ module Metanorma
|
|
183
183
|
quote_attribution(node, q)
|
184
184
|
wrap_in_para(node, q)
|
185
185
|
end
|
186
|
-
end.join("
|
186
|
+
end.join("")
|
187
187
|
end
|
188
188
|
|
189
189
|
def listing_attrs(node)
|
@@ -32,7 +32,7 @@ module Metanorma
|
|
32
32
|
xml.review **sidebar_attrs(node) do |r|
|
33
33
|
wrap_in_para(node, r)
|
34
34
|
end
|
35
|
-
end.join("
|
35
|
+
end.join("")
|
36
36
|
end
|
37
37
|
|
38
38
|
def todo_attrs(node)
|
@@ -41,7 +41,7 @@ module Metanorma
|
|
41
41
|
attr_code(id_attr(node)
|
42
42
|
.merge(reviewer: node.attr("reviewer") || node.attr("source") ||
|
43
43
|
"(Unknown)",
|
44
|
-
date
|
44
|
+
date:, type: "todo"))
|
45
45
|
end
|
46
46
|
|
47
47
|
def todo(node)
|
@@ -49,7 +49,7 @@ module Metanorma
|
|
49
49
|
xml.review **todo_attrs(node) do |r|
|
50
50
|
wrap_in_para(node, r)
|
51
51
|
end
|
52
|
-
end.join("
|
52
|
+
end.join("")
|
53
53
|
end
|
54
54
|
|
55
55
|
def termnote(node)
|
@@ -57,7 +57,7 @@ module Metanorma
|
|
57
57
|
xml.termnote **termnote_attrs(node) do |ex|
|
58
58
|
wrap_in_para(node, ex)
|
59
59
|
end
|
60
|
-
end.join("
|
60
|
+
end.join("")
|
61
61
|
end
|
62
62
|
|
63
63
|
def note(node)
|
@@ -67,7 +67,7 @@ module Metanorma
|
|
67
67
|
xml.note **note_attrs(node) do |c|
|
68
68
|
wrap_in_para(node, c)
|
69
69
|
end
|
70
|
-
end.join("
|
70
|
+
end.join("")
|
71
71
|
end
|
72
72
|
|
73
73
|
def boilerplate_note(node)
|
@@ -101,7 +101,7 @@ module Metanorma
|
|
101
101
|
node.title.nil? or a.name { |name| name << node.title }
|
102
102
|
wrap_in_para(node, a)
|
103
103
|
end
|
104
|
-
end.join("
|
104
|
+
end.join("")
|
105
105
|
end
|
106
106
|
|
107
107
|
def admonition_alternatives(node)
|
@@ -64,6 +64,7 @@ module Metanorma
|
|
64
64
|
bookmark_cleanup(xmldoc)
|
65
65
|
termdef_cleanup(xmldoc) # feeds: relaton_iev_cleanup, term_index_cleanup
|
66
66
|
relaton_iev_cleanup(xmldoc)
|
67
|
+
relaton_log_cleanup(xmldoc)
|
67
68
|
element_name_cleanup(xmldoc)
|
68
69
|
term_index_cleanup(xmldoc)
|
69
70
|
bpart_cleanup(xmldoc)
|
@@ -97,6 +98,20 @@ module Metanorma
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
101
|
+
RELATON_SEVERITIES =
|
102
|
+
{ "INFO": 3, "WARN": 2, "ERROR": 1, "FATAL": 0,
|
103
|
+
"UNKNOWN": 3 }.freeze
|
104
|
+
|
105
|
+
def relaton_log_cleanup(_xmldoc)
|
106
|
+
@relaton_log or return
|
107
|
+
@relaton_log.rewind
|
108
|
+
@relaton_log.string.split(/(?<=})\n(?={)/).each do |l|
|
109
|
+
e = JSON.parse(l)
|
110
|
+
@log.add("Relaton", e["key"], e["message"],
|
111
|
+
severity: RELATON_SEVERITIES[e["severity"].to_sym])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
100
115
|
def docidentifier_cleanup(xmldoc); end
|
101
116
|
|
102
117
|
TEXT_ELEMS =
|
@@ -163,7 +163,7 @@ module Metanorma
|
|
163
163
|
acc << safe_noko(a[0], node.document)
|
164
164
|
a.size == 4 or next
|
165
165
|
acc << Asciidoctor.convert(
|
166
|
-
a[2], doctype: :inline, backend:
|
166
|
+
a[2], doctype: :inline, backend: self&.backend&.to_sym || :standoc
|
167
167
|
)
|
168
168
|
end.join
|
169
169
|
end
|
@@ -2,19 +2,15 @@ module Metanorma
|
|
2
2
|
module Standoc
|
3
3
|
module Cleanup
|
4
4
|
def external_terms_boilerplate(sources)
|
5
|
-
@i18n.
|
6
|
-
|
7
|
-
|
8
|
-
@lang, @script, @locale
|
9
|
-
)
|
5
|
+
e = @i18n.external_terms_boilerplate
|
6
|
+
@i18n.l10n(e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "???"),
|
7
|
+
@lang, @script, @locale)
|
10
8
|
end
|
11
9
|
|
12
10
|
def internal_external_terms_boilerplate(sources)
|
13
|
-
@i18n.
|
14
|
-
|
15
|
-
|
16
|
-
@lang, @script
|
17
|
-
)
|
11
|
+
e = @i18n.internal_external_terms_boilerplate
|
12
|
+
@i18n.l10n(e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "??"),
|
13
|
+
@lang, @script)
|
18
14
|
end
|
19
15
|
|
20
16
|
def term_defs_boilerplate(div, source, term, _preface, isodoc)
|
@@ -26,8 +22,7 @@ module Metanorma
|
|
26
22
|
end
|
27
23
|
a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate
|
28
24
|
else term_defs_boilerplate_cont(source, term, isodoc)
|
29
|
-
end
|
30
|
-
a and div.next = a
|
25
|
+
end and div.next = a
|
31
26
|
end
|
32
27
|
|
33
28
|
def term_defs_boilerplate_cont(src, term, isodoc)
|
@@ -42,19 +37,42 @@ module Metanorma
|
|
42
37
|
end
|
43
38
|
|
44
39
|
def norm_ref_preface(ref)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
40
|
+
ins = norm_ref_boilerplate_insert_location(ref)
|
41
|
+
ins2 = norm_ref_process_boilerplate_note(ref)
|
42
|
+
ins2 == :populated and return
|
43
|
+
ins2 == :missing or ins = ins2
|
44
|
+
refs = ref.elements.select do |e|
|
45
|
+
%w(references bibitem).include? e.name
|
46
|
+
end
|
47
|
+
pref = refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref
|
48
|
+
ins.next = "<p>#{pref}</p>"
|
49
|
+
end
|
50
|
+
|
51
|
+
def norm_ref_process_boilerplate_note(ref)
|
52
|
+
ins2 = ref.at("./note[@type = 'boilerplate']") or return :missing
|
53
|
+
if ins2 && ins2.text.strip.downcase == "(default)"
|
54
|
+
ins2.children = " "
|
55
|
+
ins2.children.first
|
56
|
+
else :populated
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def norm_ref_boilerplate_insert_location(ref)
|
61
|
+
while (n = ref.parent) && %w(clause references).include?(n&.name)
|
62
|
+
n.elements.detect do |e|
|
63
|
+
!%(title references).include?(e.name) &&
|
64
|
+
!e.at("./self::clause[@type = 'boilerplate']") &&
|
65
|
+
!e.at("./self::clause[.//references][not(.//clause[not(.//bibitem)])]")
|
66
|
+
end and break
|
67
|
+
ref = n
|
53
68
|
end
|
69
|
+
ref.at("./title")
|
54
70
|
end
|
55
71
|
|
56
|
-
TERM_CLAUSE =
|
57
|
-
|
72
|
+
TERM_CLAUSE =
|
73
|
+
"//sections//terms[not(.//ancestor::clause[@type = 'terms'])] | " \
|
74
|
+
"//sections/clause[descendant::terms][@type = 'terms'] | " \
|
75
|
+
"//sections/clause[not(@type = 'terms')]//terms".freeze
|
58
76
|
|
59
77
|
NORM_REF =
|
60
78
|
"//bibliography/references[@normative = 'true'][not(@hidden)] | " \
|
@@ -100,18 +118,33 @@ module Metanorma
|
|
100
118
|
|
101
119
|
def termdef_boilerplate_insert_location(xmldoc)
|
102
120
|
f = xmldoc.at(self.class::TERM_CLAUSE)
|
103
|
-
root = xmldoc.at("//sections/terms | //sections/clause[
|
104
|
-
|
105
|
-
|
106
|
-
f
|
121
|
+
root = xmldoc.at("//sections/terms | //sections/clause[@type = 'terms']")
|
122
|
+
if f && root && f["id"] != root["id"]
|
123
|
+
f = termdef_boilerplate_climb_up(f, root)
|
124
|
+
elsif !f && root then f = root
|
125
|
+
end
|
107
126
|
f
|
108
127
|
end
|
109
128
|
|
129
|
+
def termdef_boilerplate_climb_up(clause, container)
|
130
|
+
container.at(".//*[@id = '#{clause['id']}']") or return clause
|
131
|
+
while (n = clause.parent)
|
132
|
+
n.at(".//definitions") and break
|
133
|
+
clause = n
|
134
|
+
n["id"] == container["id"] and break
|
135
|
+
end
|
136
|
+
clause
|
137
|
+
end
|
138
|
+
|
110
139
|
def termdef_boilerplate_insert1(sect, xmldoc, isodoc)
|
111
|
-
sect.at("./
|
112
|
-
|
113
|
-
|
114
|
-
|
140
|
+
ins = sect.at("./title")
|
141
|
+
if (ins2 = sect.at("./clause[@type = 'boilerplate'] | " \
|
142
|
+
"./note[@type = 'boilerplate']"))
|
143
|
+
ins2.text.strip.downcase == "(default)" or return
|
144
|
+
ins2.children = " "
|
145
|
+
ins = ins2.children.first
|
146
|
+
end
|
147
|
+
term_defs_boilerplate(ins, xmldoc.xpath(".//termdocsource"),
|
115
148
|
sect.at(".//term"), sect.at(".//p"), isodoc)
|
116
149
|
end
|
117
150
|
|
@@ -120,7 +153,10 @@ module Metanorma
|
|
120
153
|
termdef_boilerplate_cleanup(xmldoc)
|
121
154
|
termdef_boilerplate_insert(xmldoc, isodoc)
|
122
155
|
unwrap_boilerplate_clauses(xmldoc, self.class::TERM_CLAUSE)
|
123
|
-
f = xmldoc.at(self.class::NORM_REF)
|
156
|
+
if f = xmldoc.at(self.class::NORM_REF)
|
157
|
+
norm_ref_preface(f)
|
158
|
+
unwrap_boilerplate_clauses(f, ".")
|
159
|
+
end
|
124
160
|
initial_boilerplate(xmldoc, isodoc)
|
125
161
|
end
|
126
162
|
|
@@ -27,7 +27,7 @@ module Metanorma
|
|
27
27
|
end
|
28
28
|
|
29
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+)?$}
|
30
|
+
NUMERIC_REGEX = %r{^((\+|-)?\d*\.?\d+)([eE](\+|-){1}\d+)?$}
|
31
31
|
|
32
32
|
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
33
33
|
|
@@ -204,6 +204,28 @@ module Metanorma
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
|
+
def mathml_mn_format(math)
|
208
|
+
math.xpath(".//m:mn", "m" => MATHML_NS).each do |m|
|
209
|
+
profile = mathml_mn_profile(m)
|
210
|
+
attr = profile.each_with_object([]) do |(k, v), acc|
|
211
|
+
v == "nil" and next
|
212
|
+
acc << "#{k}='#{v}'"
|
213
|
+
end.join(",")
|
214
|
+
attr.empty? or m["data-metanorma-numberformat"] = attr
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def mathml_mn_profile(mnum)
|
219
|
+
fmt = @numberfmt_default&.dup || {}
|
220
|
+
fmt1 = {}
|
221
|
+
fmt2 = kv_parse(mnum["data-metanorma-numberformat"] || "")
|
222
|
+
if fmt2["profile"]
|
223
|
+
fmt1 = @numberfmt_prof[fmt2["profile"]] || {}
|
224
|
+
fmt2.delete("profile")
|
225
|
+
end
|
226
|
+
fmt.merge(fmt1).merge(fmt2)
|
227
|
+
end
|
228
|
+
|
207
229
|
def mathml_cleanup(xmldoc)
|
208
230
|
unitsml = Asciimath2UnitsML::Conv.new(asciimath2unitsml_options)
|
209
231
|
xmldoc.xpath("//stem[@type = 'MathML'][not(@validate = 'false')]")
|
@@ -214,6 +236,7 @@ module Metanorma
|
|
214
236
|
unitsml.MathML2UnitsML(x)
|
215
237
|
mathml_mathvariant(x)
|
216
238
|
mathml_italicise(x)
|
239
|
+
mathml_mn_format(x)
|
217
240
|
end
|
218
241
|
mathml_unitsML(xmldoc)
|
219
242
|
end
|
@@ -16,9 +16,7 @@ module Metanorma
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def move_clauses_into_preface(xml, preface)
|
19
|
-
xml.xpath("//*[@preface]").each
|
20
|
-
to_preface(preface, c)
|
21
|
-
end
|
19
|
+
xml.xpath("//*[@preface]").each { |c| to_preface(preface, c) }
|
22
20
|
end
|
23
21
|
|
24
22
|
def to_preface(preface, clause)
|
@@ -202,10 +200,9 @@ module Metanorma
|
|
202
200
|
end
|
203
201
|
|
204
202
|
# only move clausebefore notes at the very end of preface
|
205
|
-
def endofpreface_clausebefore(
|
206
|
-
|
207
|
-
.
|
208
|
-
textafter = xmldoc.xpath("//preface//*") & x.xpath("./following::*")
|
203
|
+
def endofpreface_clausebefore(xml, ins)
|
204
|
+
xml.xpath("//preface//*[@beforeclauses = 'true']").reverse.each do |x|
|
205
|
+
textafter = xml.xpath("//preface//*") & x.xpath("./following::*")
|
209
206
|
textafter.text.strip.empty? or break
|
210
207
|
x.delete("beforeclauses")
|
211
208
|
ins.previous = x.remove
|
@@ -241,9 +238,8 @@ module Metanorma
|
|
241
238
|
def floating_title_preface2sections(xmldoc)
|
242
239
|
t = xmldoc.at("//preface/floating-title") or return
|
243
240
|
s = xmldoc.at("//sections")
|
244
|
-
|
241
|
+
t.next_element or
|
245
242
|
s.children.first.previous = t.remove
|
246
|
-
end
|
247
243
|
end
|
248
244
|
end
|
249
245
|
end
|
@@ -84,15 +84,15 @@ module Metanorma
|
|
84
84
|
|
85
85
|
def section_names_terms1_cleanup(xml)
|
86
86
|
auto_name_terms(xml) or return
|
87
|
-
replace_title(xml, "//terms#{SYMnoABBR} | //clause[
|
87
|
+
replace_title(xml, "//terms#{SYMnoABBR} | //clause[@type = 'terms']#{SYMnoABBR}",
|
88
88
|
@i18n&.termsdefsymbols, true)
|
89
|
-
replace_title(xml, "//terms#{ABBRnoSYM} | //clause[
|
89
|
+
replace_title(xml, "//terms#{ABBRnoSYM} | //clause[@type = 'terms']#{ABBRnoSYM}",
|
90
90
|
@i18n&.termsdefabbrev, true)
|
91
|
-
replace_title(xml, "//terms#{SYMABBR} | //clause[
|
91
|
+
replace_title(xml, "//terms#{SYMABBR} | //clause[@type = 'terms']#{SYMABBR}",
|
92
92
|
@i18n&.termsdefsymbolsabbrev, true)
|
93
|
-
replace_title(xml, "//terms#{NO_SYMABBR} | //clause[
|
93
|
+
replace_title(xml, "//terms#{NO_SYMABBR} | //clause[@type = 'terms']#{NO_SYMABBR}",
|
94
94
|
@i18n&.termsdefsymbolsabbrev, true)
|
95
|
-
replace_title(xml, "//terms[not(.//definitions)] | //clause[
|
95
|
+
replace_title(xml, "//terms[not(.//definitions)] | //clause[@type = 'terms'][not(.//definitions)]",
|
96
96
|
@i18n&.termsdef, true)
|
97
97
|
end
|
98
98
|
|
@@ -74,7 +74,10 @@ module Metanorma
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def term_children_cleanup(xmldoc)
|
77
|
-
xmldoc.xpath("//terms[terms][not(term)]").each
|
77
|
+
xmldoc.xpath("//terms[terms][not(term)]").each do |t|
|
78
|
+
t.name = "clause"
|
79
|
+
t["type"] = "terms"
|
80
|
+
end
|
78
81
|
xmldoc.xpath("//term").each do |t|
|
79
82
|
%w(termnote termexample termsource term).each do |w|
|
80
83
|
t.xpath("./#{w}").each { |n| t << n.remove }
|
@@ -122,8 +125,7 @@ module Metanorma
|
|
122
125
|
end
|
123
126
|
|
124
127
|
def term_index_cleanup(xmldoc)
|
125
|
-
|
126
|
-
|
128
|
+
@index_terms or return
|
127
129
|
xmldoc.xpath("//preferred").each do |p|
|
128
130
|
index_cleanup1(p.at("./expression/name | ./letter-symbol/name"),
|
129
131
|
p.xpath("./field-of-application | ./usage-info")
|
@@ -135,8 +137,7 @@ module Metanorma
|
|
135
137
|
end
|
136
138
|
|
137
139
|
def index_cleanup1(term, fieldofappl)
|
138
|
-
|
139
|
-
|
140
|
+
term or return
|
140
141
|
idx = term.children.dup
|
141
142
|
fieldofappl.empty? or idx << ", <#{fieldofappl}>"
|
142
143
|
term << "<index><primary>#{idx.to_xml}</primary></index>"
|
@@ -95,10 +95,9 @@ module Metanorma
|
|
95
95
|
elem.xpath("./localityStack").size < 2 and return
|
96
96
|
elem.xpath("./localityStack[not(@connective)]").each do |l|
|
97
97
|
n = l.next_element
|
98
|
-
l["connective"] =
|
99
|
-
|
100
|
-
|
101
|
-
else "and" end
|
98
|
+
l["connective"] = "and"
|
99
|
+
n && n.name == "localityStack" && n["connective"] == "to" and
|
100
|
+
l["connective"] = "from"
|
102
101
|
end
|
103
102
|
end
|
104
103
|
|
@@ -111,8 +110,7 @@ module Metanorma
|
|
111
110
|
elem.name = name
|
112
111
|
elem["bibitemid"] = elem["target"]
|
113
112
|
if ref = @anchors&.dig(elem["target"], :xref)
|
114
|
-
t = @anchors.dig(elem["target"], :id, elem["style"]) and
|
115
|
-
ref = t
|
113
|
+
t = @anchors.dig(elem["target"], :id, elem["style"]) and ref = t
|
116
114
|
elem["citeas"] = @c.decode(ref)
|
117
115
|
else xref_to_eref1(elem)
|
118
116
|
end
|
@@ -141,9 +139,7 @@ module Metanorma
|
|
141
139
|
e.name = "erefstack"
|
142
140
|
e.delete("bibitemid")
|
143
141
|
e.delete("citeas")
|
144
|
-
e.xpath("./eref").each
|
145
|
-
e1["type"] = e["type"]
|
146
|
-
end
|
142
|
+
e.xpath("./eref").each { |e1| e1["type"] = e["type"] }
|
147
143
|
e.delete("type")
|
148
144
|
end
|
149
145
|
end
|
@@ -219,7 +215,7 @@ module Metanorma
|
|
219
215
|
unless a.size < 2 || a[0].empty? || a[1].empty?
|
220
216
|
elem["target"] = "#{a[0]}_#{a[1]}"
|
221
217
|
a.size > 2 and
|
222
|
-
elem.children = %{anchor="#{a[2
|
218
|
+
elem.children = %{anchor="#{a[2..].join}",#{elem.children&.text}}
|
223
219
|
elem["type"] = a[0]
|
224
220
|
@internal_eref_namespaces << a[0]
|
225
221
|
xref_to_eref(elem, "eref")
|
@@ -67,6 +67,7 @@ module Metanorma
|
|
67
67
|
inline_macro Metanorma::Standoc::ToCInlineMacro
|
68
68
|
inline_macro Metanorma::Standoc::PassInlineMacro
|
69
69
|
inline_macro Metanorma::Standoc::StdLinkInlineMacro
|
70
|
+
inline_macro Metanorma::Standoc::NumberInlineMacro
|
70
71
|
block Metanorma::Standoc::ToDoAdmonitionBlock
|
71
72
|
block Metanorma::Standoc::EditorAdmonitionBlock
|
72
73
|
treeprocessor Metanorma::Standoc::EditorInlineAdmonitionBlock
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
1
3
|
module Metanorma
|
2
4
|
module Standoc
|
3
5
|
module Base
|
@@ -10,6 +12,7 @@ module Metanorma
|
|
10
12
|
init_output(node) # feeds init_biblio
|
11
13
|
init_i18n(node)
|
12
14
|
init_biblio(node)
|
15
|
+
init_math(node)
|
13
16
|
@metadata_attrs = metadata_attrs(node)
|
14
17
|
end
|
15
18
|
|
@@ -42,12 +45,11 @@ module Metanorma
|
|
42
45
|
def init_processing(node)
|
43
46
|
@novalid = node.attr("novalid")
|
44
47
|
@smartquotes = node.attr("smartquotes") != "false"
|
45
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
46
|
-
node.attr("mn-keep-asciimath") != "false"
|
47
48
|
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
48
49
|
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
49
50
|
@datauriimage = node.attr("data-uri-image") != "false"
|
50
51
|
@datauriattachment = node.attr("data-uri-attachment") != "false"
|
52
|
+
@dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
|
51
53
|
@blockunnumbered = (node.attr("block-unnumbered") || "").split(",")
|
52
54
|
.map(&:strip)
|
53
55
|
end
|
@@ -101,6 +103,7 @@ module Metanorma
|
|
101
103
|
def init_biblio(node)
|
102
104
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
103
105
|
@no_isobib = node.attr("no-isobib")
|
106
|
+
init_bib_log
|
104
107
|
@bibdb = nil
|
105
108
|
init_bib_caches(node)
|
106
109
|
init_iev_caches(node)
|
@@ -108,6 +111,24 @@ module Metanorma
|
|
108
111
|
::Metanorma::Standoc::LocalBiblio.new(node, @localdir, self)
|
109
112
|
end
|
110
113
|
|
114
|
+
def init_bib_log
|
115
|
+
@relaton_log = StringIO.new
|
116
|
+
relaton_logger = Relaton::Logger::Log
|
117
|
+
.new(@relaton_log, levels: %i(info warn error fatal unknown),
|
118
|
+
formatter: Relaton::Logger::FormatterJSON)
|
119
|
+
Relaton.logger_pool[:my_logger] = relaton_logger
|
120
|
+
end
|
121
|
+
|
122
|
+
def init_math(node)
|
123
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
124
|
+
node.attr("mn-keep-asciimath") != "false"
|
125
|
+
@numberfmt_default = kv_parse(node.attr("number-presentation"))
|
126
|
+
@numberfmt_prof = node.attributes.each_with_object({}) do |(k, v), m|
|
127
|
+
p = /^number-presentation-profile-(.*)$/.match(k) or next
|
128
|
+
m[p[1]] = kv_parse(v)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
111
132
|
def requirements_processor
|
112
133
|
Metanorma::Requirements
|
113
134
|
end
|
@@ -43,21 +43,21 @@ module Metanorma
|
|
43
43
|
if /<([^:>&]+:)?math(\s+[^>&]+)?> |
|
44
44
|
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
|
45
45
|
math = xml_encode(text)
|
46
|
-
xml.stem
|
46
|
+
xml.stem(type: "MathML", block:) do |s|
|
47
47
|
s << math
|
48
48
|
end
|
49
49
|
elsif style == :latexmath then latex_parse(text, xml, block)
|
50
50
|
else
|
51
|
-
xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block:
|
51
|
+
xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block:
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
def latex_parse(text, xml, block)
|
56
56
|
latex = latex_parse1(text, block) or
|
57
|
-
return xml.stem
|
58
|
-
xml.stem
|
57
|
+
return xml.stem(type: "MathML", block:)
|
58
|
+
xml.stem(type: "MathML", block:) do |s|
|
59
59
|
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
|
60
|
-
|
60
|
+
.elements[0]
|
61
61
|
math.delete("alttext")
|
62
62
|
s.parent.children = math
|
63
63
|
s << "<latexmath>#{text}</latexmath>"
|
@@ -17,7 +17,7 @@
|
|
17
17
|
these elements; we just want one namespace for any child grammars
|
18
18
|
of this.
|
19
19
|
-->
|
20
|
-
<!-- VERSION v1.3.
|
20
|
+
<!-- VERSION v1.3.3 -->
|
21
21
|
<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">
|
22
22
|
<include href="reqt.rng"/>
|
23
23
|
<include href="basicdoc.rng">
|
@@ -331,9 +331,9 @@
|
|
331
331
|
<zeroOrMore>
|
332
332
|
<ref name="table-note"/>
|
333
333
|
</zeroOrMore>
|
334
|
-
<
|
334
|
+
<zeroOrMore>
|
335
335
|
<ref name="source"/>
|
336
|
-
</
|
336
|
+
</zeroOrMore>
|
337
337
|
</define>
|
338
338
|
<define name="FigureAttr">
|
339
339
|
<optional>
|
@@ -380,9 +380,9 @@
|
|
380
380
|
<zeroOrMore>
|
381
381
|
<ref name="note"/>
|
382
382
|
</zeroOrMore>
|
383
|
-
<
|
383
|
+
<zeroOrMore>
|
384
384
|
<ref name="source"/>
|
385
|
-
</
|
385
|
+
</zeroOrMore>
|
386
386
|
</define>
|
387
387
|
<define name="source">
|
388
388
|
<element name="source">
|