metanorma 2.5.12 → 2.5.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/Gemfile +4 -0
- data/lib/metanorma/collection/filelookup/filelookup.rb +33 -0
- data/lib/metanorma/collection/renderer/fileparse.rb +14 -1
- data/lib/metanorma/collection/renderer/utils.rb +50 -2
- data/lib/metanorma/collection/util/util.rb +86 -0
- data/lib/metanorma/compile/compile_options.rb +20 -6
- data/lib/metanorma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf7e165fbc2cd9abb285653e89a551948e734eb0559ec7604a5aca0a95dd5b9a
|
|
4
|
+
data.tar.gz: ec1328b3249691d12013228754fb63bedb4e0af0e96c0632012a0d392b46b639
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ce1de2751cc2a73b7fcf2f02669aa777fa9f12c735091f671db83386b74ea05c20feba9f4cec9e684fa5523689562ac5acdf315b70494dbf99d5d15e5659471
|
|
7
|
+
data.tar.gz: f8d03526b7e4253d50e8fb5c04b3d3758b07d8fbd2fb45e38753b66d7fefde214be5726cf082de910ef8502628c105a08916a2a36a889032477a1b0229f07629
|
data/Gemfile
CHANGED
|
@@ -30,6 +30,10 @@ gem "canon", "~> 0.3.122"
|
|
|
30
30
|
gem "lutaml-store", "~> 0.3.11"
|
|
31
31
|
#gem "metanorma-iho"
|
|
32
32
|
#gem "metanorma-iso", ">= 3.2.0"
|
|
33
|
+
# Floor fontist at the variable-font indexing fix (fontist#531/#532):
|
|
34
|
+
# anything below 3.0.31 misses freshly installed variable fonts on
|
|
35
|
+
# locations lookups ("Fira Code" MissingFontError, metanorma-iho#563).
|
|
36
|
+
gem "fontist", "~> 3.0.32"
|
|
33
37
|
gem "mnconvert"
|
|
34
38
|
gem "pry"
|
|
35
39
|
gem "rake", "~> 13.0"
|
|
@@ -232,6 +232,39 @@ module Metanorma
|
|
|
232
232
|
doc.root["document_suffix"] += document_suffix
|
|
233
233
|
end
|
|
234
234
|
|
|
235
|
+
# Re-key a stored document's ids from the suffix it was stored under
|
|
236
|
+
# to this render's own suffix. Reinflation renders stored Semantic
|
|
237
|
+
# XMLs whose ids were keyed by the staging build's identifier; a
|
|
238
|
+
# sectionsplit render splits them into pages whose ids must equal
|
|
239
|
+
# the anchors the cross-reference passes compose from this render's
|
|
240
|
+
# identifiers. Mirror of add_document_suffix with the same
|
|
241
|
+
# attribute, CSS and SVG coverage, replacing the stored suffix
|
|
242
|
+
# instead of appending one. The stored file itself is never written.
|
|
243
|
+
def swap_document_suffix(identifier, doc)
|
|
244
|
+
stored = doc.root["document_suffix"]
|
|
245
|
+
if stored.nil? || stored.empty?
|
|
246
|
+
return add_document_suffix(identifier, doc)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
suffix = Metanorma::Utils::to_ncname(identifier)
|
|
250
|
+
stored == suffix and return
|
|
251
|
+
|
|
252
|
+
swap_document_suffix_ids(doc, stored, suffix)
|
|
253
|
+
doc.root["document_suffix"] = suffix
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def swap_document_suffix_ids(doc, stored, suffix)
|
|
257
|
+
base_ids = doc.xpath("./@id | .//@id")
|
|
258
|
+
.map { |a| a.value.sub(/_#{Regexp.escape(stored)}\z/, "") }
|
|
259
|
+
.uniq.to_h { |i| [i, true] }
|
|
260
|
+
Util::anchor_id_attributes.each do |(tag_name, attr_name)|
|
|
261
|
+
Util::swap_suffix_to_attrs(doc, [stored, suffix], tag_name,
|
|
262
|
+
attr_name, @isodoc)
|
|
263
|
+
end
|
|
264
|
+
Util::swap_ids_css(doc, base_ids, stored, suffix)
|
|
265
|
+
Util::swap_svg_ids(doc, base_ids, stored, suffix)
|
|
266
|
+
end
|
|
267
|
+
|
|
235
268
|
# return citation url for file
|
|
236
269
|
# @param doc [Boolean] I am a Metanorma document,
|
|
237
270
|
# so my URL should end with html or pdf or whatever
|
|
@@ -34,7 +34,20 @@ module Metanorma
|
|
|
34
34
|
@nested or update_indirect_refs_to_docs(xml, docid, internal_refs, sso)
|
|
35
35
|
# post: bibitem[@type='internal'] anchors resolved to the containing
|
|
36
36
|
# collection document.
|
|
37
|
-
|
|
37
|
+
if sso || !@reinflate
|
|
38
|
+
@files.add_document_suffix(docid, xml)
|
|
39
|
+
elsif @nested
|
|
40
|
+
# Reinflated sectionsplit: the split's Presentation XML was
|
|
41
|
+
# generated from stored XMLs whose ids carry the staging build's
|
|
42
|
+
# suffix, while this render's cross-reference passes compose
|
|
43
|
+
# anchors from this render's identifiers. Re-key the split
|
|
44
|
+
# documents to this render's suffix, so section-page ids equal
|
|
45
|
+
# the link anchors; non-split stored members keep their stored
|
|
46
|
+
# ids untouched. (@nested is the pre-split sectionsplit pass;
|
|
47
|
+
# the render loop's own pass over a sectionsplit parent is
|
|
48
|
+
# discarded, so it needs no suffix handling.)
|
|
49
|
+
@files.swap_document_suffix(docid, xml)
|
|
50
|
+
end
|
|
38
51
|
# post: every @id/@anchor namespaced with this doc's NCName suffix, so
|
|
39
52
|
# concatenated documents do not collide.
|
|
40
53
|
@nested or update_sectionsplit_refs_to_docs(xml, docid, internal_refs,
|
|
@@ -153,15 +153,63 @@ module Metanorma
|
|
|
153
153
|
::Metanorma::Util.log(error, :warning)
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
+
# Image relocation for collection rendering, in three ordered passes:
|
|
157
|
+
# anchor every image target at the document that emitted it, then
|
|
158
|
+
# inline SVGs, then encode what remains as data URIs.
|
|
156
159
|
def datauri_encode(docxml, directory)
|
|
160
|
+
anchor_image_targets(docxml, directory)
|
|
161
|
+
inline_svg_images(docxml, directory)
|
|
162
|
+
datauri_images(docxml, directory)
|
|
163
|
+
docxml
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Image targets are emitted relative to the document that carries them
|
|
167
|
+
# (metanorma#646). Each target must be anchored at the emitting
|
|
168
|
+
# document's directory BEFORE it is resolved: Vectory's datauri
|
|
169
|
+
# fallback tries the process working directory first, so a relative
|
|
170
|
+
# target was resolved against wherever the build happened to run --
|
|
171
|
+
# picking a same-named file from the wrong tree, or missing both
|
|
172
|
+
# bases and failing the render. Data URIs, remote URLs and absolute
|
|
173
|
+
# paths carry their own base and pass through; a target that anchors
|
|
174
|
+
# to an existing file is pinned to that absolute path, so only the
|
|
175
|
+
# file's bytes reach the output and the output is build-directory
|
|
176
|
+
# independent. A target that anchors to nothing keeps its emitted
|
|
177
|
+
# form, so a missing image stays a build-independent dangling
|
|
178
|
+
# reference.
|
|
179
|
+
def anchor_image_targets(docxml, directory)
|
|
180
|
+
docxml.xpath(ns("//image")).each do |i|
|
|
181
|
+
anchor_image_target(i, directory)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def inline_svg_images(docxml, directory)
|
|
157
186
|
docxml.xpath(ns("//image")).each do |i|
|
|
158
187
|
read_in_if_svg(i, directory.sub(%r{(?<!=/)$}, "/"))
|
|
159
188
|
end
|
|
160
|
-
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def datauri_images(docxml, directory)
|
|
192
|
+
docxml.xpath(ns("//image")).each do |i|
|
|
161
193
|
(i["src"] && !i["src"].empty?) or next
|
|
162
194
|
i["src"] = Vectory::Utils::datauri(i["src"], directory)
|
|
163
195
|
end
|
|
164
|
-
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def anchor_image_target(img, directory)
|
|
199
|
+
src = img["src"]
|
|
200
|
+
anchorable_base?(src) or return
|
|
201
|
+
path = File.expand_path(src, directory)
|
|
202
|
+
File.file?(path) or return
|
|
203
|
+
img["src"] = path
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# A target whose base is already determined cannot be re-anchored.
|
|
207
|
+
def anchorable_base?(src)
|
|
208
|
+
return false if src.nil? || src.empty?
|
|
209
|
+
|
|
210
|
+
!(Vectory::Utils.datauri?(src) ||
|
|
211
|
+
Vectory::Utils.url?(src) ||
|
|
212
|
+
Vectory::Utils.absolute_path?(src))
|
|
165
213
|
end
|
|
166
214
|
|
|
167
215
|
def read_in_if_svg(img, localdir)
|
|
@@ -55,6 +55,92 @@ module Metanorma
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# Re-key an attribute value from one document suffix to another:
|
|
59
|
+
# a value ending "_#{from}" keeps its base and ends "_#{to}"
|
|
60
|
+
# instead, and a value carrying neither suffix gets "_#{to}".
|
|
61
|
+
# Mirror of add_suffix_to_attrs for documents whose ids were keyed
|
|
62
|
+
# by a previous build's suffix.
|
|
63
|
+
def swap_suffix_to_attrs(doc, suffixes, tag, attr, isodoc)
|
|
64
|
+
from, to = suffixes
|
|
65
|
+
suffix_swap?(from, to) or return
|
|
66
|
+
doc.xpath(isodoc.ns("//#{tag}[@#{attr}]" \
|
|
67
|
+
"[not(ancestor-or-self::*[local-name()='svg'])]"))
|
|
68
|
+
.each do |elem|
|
|
69
|
+
a = elem.attributes[attr].value
|
|
70
|
+
elem.attributes[attr].value = swap_suffix_value(a, from, to)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def swap_suffix_value(value, from, to)
|
|
75
|
+
value = value.sub(/_#{Regexp.escape(from)}\z/, "")
|
|
76
|
+
/_#{Regexp.escape(to)}$/.match?(value) or value = "#{value}_#{to}"
|
|
77
|
+
value
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Re-key id references in CSS (style attributes and style elements,
|
|
81
|
+
# outside SVGs) from one document suffix to another. Mirror of
|
|
82
|
+
# update_ids_css for documents keyed by a previous build's suffix.
|
|
83
|
+
def swap_ids_css(document, ids, from, to)
|
|
84
|
+
suffix_swap?(from, to) or return
|
|
85
|
+
document.xpath(".//m:style[not(ancestor::i:svg)]",
|
|
86
|
+
"m" => SVG_NS, "i" => SVG_NS).each do |s|
|
|
87
|
+
s.children = swap_ids_css_string(s.children.to_xml, ids, from, to)
|
|
88
|
+
end
|
|
89
|
+
document.xpath(".//*[@style][not(ancestor::i:svg)]",
|
|
90
|
+
"i" => SVG_NS).each do |s|
|
|
91
|
+
s["style"] = swap_ids_css_string(s["style"], ids, from, to)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Re-key id references inside a string: every "<id>_#{from}" token
|
|
96
|
+
# whose base is a known id (in "#id" url references, "[id='…']"
|
|
97
|
+
# selectors, or bare attribute values) becomes "<id>_#{to}".
|
|
98
|
+
# Single pass over the string; `ids` maps base ids to true.
|
|
99
|
+
def swap_ids_css_string(style, ids, from, to)
|
|
100
|
+
return style unless style.include?("_#{from}")
|
|
101
|
+
|
|
102
|
+
from_re = Regexp.escape(from)
|
|
103
|
+
style.gsub(%r(\b([\w.:-]+)_#{from_re}\b)) do
|
|
104
|
+
base = Regexp.last_match(1)
|
|
105
|
+
ids.include?(base) or next Regexp.last_match(0)
|
|
106
|
+
"#{base}_#{to}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Re-key standalone SVG ids and their internal CSS from one
|
|
111
|
+
# document suffix to another. Mirror of the Vectory leg of
|
|
112
|
+
# url_in_css_styles for documents keyed by a previous build.
|
|
113
|
+
def swap_svg_ids(doc, ids, from, to)
|
|
114
|
+
suffix_swap?(from, to) or return
|
|
115
|
+
doc.xpath("//i:svg[not(ancestor::*[local-name()='svgmap'])]",
|
|
116
|
+
"i" => SVG_NS).each do |svg|
|
|
117
|
+
swap_svg_ids1(svg, ids, from, to)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def swap_svg_ids1(svg, ids, from, to)
|
|
122
|
+
svg.xpath(". | .//*[@*]").each do |n|
|
|
123
|
+
n.attribute_nodes.each do |x|
|
|
124
|
+
x.value = swap_ids_css_string(x.value, ids, from, to)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
swap_svg_css(svg, ids, from, to)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def swap_svg_css(svg, ids, from, to)
|
|
131
|
+
svg.xpath(".//m:style", "m" => SVG_NS).each do |st|
|
|
132
|
+
st.children = swap_ids_css_string(st.children.to_xml, ids,
|
|
133
|
+
from, to)
|
|
134
|
+
end
|
|
135
|
+
svg.xpath(".//*[@style]").each do |n|
|
|
136
|
+
n["style"] = swap_ids_css_string(n["style"], ids, from, to)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def suffix_swap?(from, to)
|
|
141
|
+
!(from.nil? || from.empty? || from == to)
|
|
142
|
+
end
|
|
143
|
+
|
|
58
144
|
def hash_key_detect(directives, key, variable)
|
|
59
145
|
c = directives.detect { |x| x.key == key } or
|
|
60
146
|
return variable
|
|
@@ -7,14 +7,28 @@ module Metanorma
|
|
|
7
7
|
options&.dig(:require)&.each { |r| require r }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
OUTPUT_EXTENSIONS_XPATH =
|
|
11
|
+
"/*/*[local-name()='metanorma-extension']/" \
|
|
12
|
+
"*[local-name()='presentation-metadata']/" \
|
|
13
|
+
"*[local-name()='output-extensions']".freeze
|
|
14
|
+
|
|
10
15
|
def extract_xml_options(file)
|
|
11
16
|
xml = Nokogiri::XML(file, &:huge)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
xml.root or return {}
|
|
18
|
+
# Keys are set only when present: options_in_file merges this hash
|
|
19
|
+
# over the AsciiDoc header options, and an absent key must not
|
|
20
|
+
# clear them.
|
|
21
|
+
{ type: xml_root_type(xml), extensions: xml_output_extensions(xml) }
|
|
22
|
+
.compact
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def xml_root_type(xml)
|
|
26
|
+
@registry.root_tags.find { |_, v| v == xml.root.name }&.first
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def xml_output_extensions(xml)
|
|
30
|
+
ext = xml.at(OUTPUT_EXTENSIONS_XPATH)&.text&.strip
|
|
31
|
+
ext unless ext.nil? || ext.empty?
|
|
18
32
|
end
|
|
19
33
|
|
|
20
34
|
def extract_options(filename, options)
|
data/lib/metanorma/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|