metanorma-utils 1.2.1 → 1.2.2
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/utils/image.rb +41 -8
- data/lib/utils/version.rb +1 -1
- data/spec/fixtures/action_schemaexpg1.svg +3 -1
- data/spec/utils_spec.rb +19 -13
- 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: 52b94adefc23d35f664e35438604432f951f29d15ccb5622f64447a79eaa14d0
|
4
|
+
data.tar.gz: 5e68045ce2aaf9c6a34ec8793d8f75b1e3bb065fe4a733db84101f4bee31cf2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5e47154cf50378f9960ddd1f782d3ec35c4c92395d3e74a0f734ad7f77c510c401ad26e46fa4aae96b30784e0263e407e93b6d58daf97070b9f2628a72b57ff
|
7
|
+
data.tar.gz: adec26a807cb648a9b6ad5d6cc3e6251f0b79eba52e1901f99cf102ef61db425bb6ea3e1676e51af1a5d9ab9a0b5aeda1e0c6f071ff48238e2fa103fae0b7d48
|
data/lib/utils/image.rb
CHANGED
@@ -37,23 +37,23 @@ module Metanorma
|
|
37
37
|
|
38
38
|
def svgmap_rewrite(xmldoc, localdirectory = "")
|
39
39
|
n = Namespace.new(xmldoc)
|
40
|
-
xmldoc.xpath(n.ns("//svgmap")).
|
41
|
-
next unless svgmap_rewrite0(s, n, localdirectory)
|
40
|
+
xmldoc.xpath(n.ns("//svgmap")).each_with_index do |s, i|
|
41
|
+
next unless svgmap_rewrite0(s, n, localdirectory, i)
|
42
42
|
next if s.at(n.ns("./target/eref"))
|
43
43
|
|
44
44
|
s.replace(s.at(n.ns("./figure")))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def svgmap_rewrite0(svgmap, namespace, localdirectory)
|
48
|
+
def svgmap_rewrite0(svgmap, namespace, localdirectory, idx)
|
49
49
|
if (i = svgmap.at(namespace.ns(".//image"))) && (src = i["src"])
|
50
50
|
path = svgmap_rewrite0_path(src, localdirectory)
|
51
51
|
File.file?(path) or return false
|
52
52
|
svg = Nokogiri::XML(File.read(path, encoding: "utf-8"))
|
53
|
-
i.replace(svgmap_rewrite1(svgmap, svg.root, namespace))
|
53
|
+
i.replace(svgmap_rewrite1(svgmap, svg.root, namespace, idx))
|
54
54
|
/^data:/.match(src) and i["src"] = datauri(path)
|
55
55
|
elsif i = svgmap.at(".//m:svg", "m" => SVG_NS)
|
56
|
-
i.replace(svgmap_rewrite1(svgmap, i, namespace))
|
56
|
+
i.replace(svgmap_rewrite1(svgmap, i, namespace, idx))
|
57
57
|
else
|
58
58
|
return false
|
59
59
|
end
|
@@ -68,15 +68,20 @@ module Metanorma
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
def svgmap_rewrite1(svgmap, svg, namespace)
|
71
|
+
def svgmap_rewrite1(svgmap, svg, namespace, idx)
|
72
|
+
svg_update_href(svgmap, svg, namespace)
|
73
|
+
svg_update_ids(svg, idx)
|
74
|
+
svg.xpath("processing-instruction()|.//processing-instruction()").remove
|
75
|
+
svg.to_xml
|
76
|
+
end
|
77
|
+
|
78
|
+
def svg_update_href(svgmap, svg, namespace)
|
72
79
|
targ = svgmap_rewrite1_targets(svgmap, namespace)
|
73
80
|
svg.xpath(".//m:a", "m" => SVG_NS).each do |a|
|
74
81
|
["xlink:href", "href"].each do |p|
|
75
82
|
a[p] and x = targ[File.expand_path(a[p])] and a[p] = x
|
76
83
|
end
|
77
84
|
end
|
78
|
-
svg.xpath("processing-instruction()|.//processing-instruction()").remove
|
79
|
-
svg.to_xml
|
80
85
|
end
|
81
86
|
|
82
87
|
def svgmap_rewrite1_targets(svgmap, namespace)
|
@@ -90,6 +95,34 @@ module Metanorma
|
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
98
|
+
def svg_update_ids(svg, idx)
|
99
|
+
ids = svg.xpath("./@id | .//@id")
|
100
|
+
.each_with_object([]) { |i, m| m << i.value }
|
101
|
+
return if ids.empty?
|
102
|
+
|
103
|
+
svg_update_ids_attrs(svg, ids, idx)
|
104
|
+
svg_update_ids_css(svg, ids, idx)
|
105
|
+
end
|
106
|
+
|
107
|
+
def svg_update_ids_attrs(svg, ids, idx)
|
108
|
+
svg.xpath(". | .//*[@*]").each do |a|
|
109
|
+
a.attribute_nodes.each do |x|
|
110
|
+
ids.include?(x.value) and x.value += sprintf("_%09d", idx)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def svg_update_ids_css(svg, ids, idx)
|
116
|
+
svg.xpath("//m:style", "m" => SVG_NS).each do |s|
|
117
|
+
c = s.children.to_xml
|
118
|
+
ids.each do |i|
|
119
|
+
c = c.gsub(%r[##{i}\b], sprintf("#%s_%09d", i, idx))
|
120
|
+
.gsub(%r(\[id\s*=\s*['"]?#{i}['"]?\]), sprintf("[id='%s_%09d']", i, idx))
|
121
|
+
end
|
122
|
+
s.children = c
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
93
126
|
# sources/plantuml/plantuml20200524-90467-1iqek5i.png
|
94
127
|
# already includes localdir
|
95
128
|
def datauri(uri, localdirectory = ".")
|
data/lib/utils/version.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
4
4
|
viewBox="0 0 595.28 841.89" style="enable-background:new 0 0 595.28 841.89;" xml:space="preserve">
|
5
5
|
<style type="text/css">
|
6
|
+
#Layer_1 { fill:none }
|
7
|
+
svg[id = 'Layer_1'] { fill:none }
|
6
8
|
.st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
|
7
9
|
</style>
|
8
10
|
<image style="overflow:visible;" width="368" height="315" xlink:href="data:image/gif;base64,R0lGODlhcAE7Aff/AAAAAAAAMwAAZgAAmQAAzAAA/wAzAAAzMwAzZgAzmQAzzAAz/wBmAABmMwBm
|
@@ -110,7 +112,7 @@ vsuOvuXr7OfLveML7c0u7c9u7dEevt+77cwuvteu7d2uvuzb2ORe7u97ZvV7v8UevBLGv/4LwHi+
|
|
110
112
|
ZARswAgc77C27vqba/guwMe27x997/Z+av6O3QC/5co28BQs8AFfaAgv0gWf3Apv8P2+8GfW8CJ8
|
111
113
|
8BS/ZBYP2fqe8TK28Xmdaydj7iRfFvIpo8qEnfIqv/Is3/Iu//IwH/OhERAAOw==" transform="matrix(1 0 0 1 114 263.8898)">
|
112
114
|
</image>
|
113
|
-
<a xlink:href="mn://action_schema" >
|
115
|
+
<a xlink:href="mn://action_schema" xlink:dummy="Layer_1">
|
114
116
|
<rect x="123.28" y="273.93" class="st0" width="88.05" height="41.84"/>
|
115
117
|
</a>
|
116
118
|
<a xlink:href="mn://basic_attribute_schema" >
|
data/spec/utils_spec.rb
CHANGED
@@ -158,10 +158,10 @@ RSpec.describe Metanorma::Utils do
|
|
158
158
|
</target>
|
159
159
|
</svgmap>
|
160
160
|
<figure>
|
161
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
161
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000001' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
162
162
|
<style/>
|
163
163
|
<image/>
|
164
|
-
<a xlink:href='#ref1'>
|
164
|
+
<a xlink:href='#ref1' xlink:dummy='Layer_1_000000001'>
|
165
165
|
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
166
166
|
</a>
|
167
167
|
<a xlink:href='mn://basic_attribute_schema'>
|
@@ -174,10 +174,10 @@ RSpec.describe Metanorma::Utils do
|
|
174
174
|
</figure>
|
175
175
|
<svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
|
176
176
|
<figure>
|
177
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
177
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000002' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
178
178
|
<style/>
|
179
179
|
<image/>
|
180
|
-
<a xlink:href='mn://action_schema'>
|
180
|
+
<a xlink:href='mn://action_schema' xlink:dummy='Layer_1_000000002'>
|
181
181
|
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
182
182
|
</a>
|
183
183
|
<a xlink:href='http://www.example.com'>
|
@@ -200,7 +200,7 @@ RSpec.describe Metanorma::Utils do
|
|
200
200
|
</target>
|
201
201
|
</svgmap>
|
202
202
|
<figure>
|
203
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
203
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000003' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
204
204
|
<a href='#ref1'>
|
205
205
|
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
206
206
|
</a>
|
@@ -214,7 +214,7 @@ RSpec.describe Metanorma::Utils do
|
|
214
214
|
</figure>
|
215
215
|
<svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
|
216
216
|
<figure>
|
217
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
217
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000004' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
218
218
|
<style/>
|
219
219
|
<image/>
|
220
220
|
<a xlink:href='mn://action_schema'>
|
@@ -280,7 +280,7 @@ RSpec.describe Metanorma::Utils do
|
|
280
280
|
</standard-document>
|
281
281
|
INPUT
|
282
282
|
Metanorma::Utils.svgmap_rewrite(xmldoc)
|
283
|
-
expect(xmlpp(xmldoc.to_xml.gsub(%r{<image.*?</image>}m, "<image/>")
|
283
|
+
expect(xmlpp(xmldoc.to_xml.gsub(%r{<image.*?</image>}m, "<image/>"))).to be_equivalent_to xmlpp(<<~OUTPUT)
|
284
284
|
<?xml version='1.0'?>
|
285
285
|
<standard-document type="semantic" version="1.8.2" xmlns="http://www.example.com">
|
286
286
|
<bibdata type="standard">
|
@@ -302,10 +302,13 @@ RSpec.describe Metanorma::Utils do
|
|
302
302
|
</bibdata>
|
303
303
|
<sections><svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
|
304
304
|
<figure>
|
305
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
306
|
-
|
305
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000001' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
306
|
+
<style type='text/css'>
|
307
|
+
#Layer_1_000000001 { fill:none } svg[id='Layer_1_000000001'] {
|
308
|
+
fill:none } .st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
|
309
|
+
</style>
|
307
310
|
<image/>
|
308
|
-
<a xlink:href='#ref1'>
|
311
|
+
<a xlink:href='#ref1' xlink:dummy='Layer_1_000000001'>
|
309
312
|
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
310
313
|
</a>
|
311
314
|
<a xlink:href='mn://basic_attribute_schema'>
|
@@ -318,10 +321,13 @@ RSpec.describe Metanorma::Utils do
|
|
318
321
|
</figure>
|
319
322
|
<svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
|
320
323
|
<figure>
|
321
|
-
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='
|
322
|
-
|
324
|
+
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' id='Layer_1_000000002' x='0px' y='0px' viewBox='0 0 595.28 841.89' style='enable-background:new 0 0 595.28 841.89;' xml:space='preserve'>
|
325
|
+
<style type='text/css'>
|
326
|
+
#Layer_1_000000002 { fill:none } svg[id='Layer_1_000000002'] {
|
327
|
+
fill:none } .st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
|
328
|
+
</style>
|
323
329
|
<image/>
|
324
|
-
<a xlink:href='mn://action_schema'>
|
330
|
+
<a xlink:href='mn://action_schema' xlink:dummy='Layer_1_000000002'>
|
325
331
|
<rect x='123.28' y='273.93' class='st0' width='88.05' height='41.84'/>
|
326
332
|
</a>
|
327
333
|
<a xlink:href='http://www.example.com'>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sterile
|