metanorma-utils 1.0.2 → 1.0.3
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/main.rb +5 -13
- data/lib/utils/version.rb +1 -1
- data/spec/utils_spec.rb +18 -6
- 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: b8316c849024c1d50c4187236c02c021c6ee1dae96d977e4634a4092f6143545
|
4
|
+
data.tar.gz: caf0a5aca6847cb91a43334f61eda55dd371ef205e175e88caf85433b47c7799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e87d1d6028e5ecd8f4518f8d02c43ca16f8aca81dc3a74b814631372e52b32a2df72313f5eb2304632faaf1248f65653cb4296366183e9e54b2c327f8abf17a
|
7
|
+
data.tar.gz: 98cc1f5cdaf5206072b7726fdd9771382aa754a03b7e1310113ea1ea6f80f082bb8596b700d620406ee24a6fc345de58d646291174fd0ba79549259393169547
|
data/lib/utils/main.rb
CHANGED
@@ -78,26 +78,18 @@ module Metanorma
|
|
78
78
|
hash
|
79
79
|
end
|
80
80
|
|
81
|
-
def svgmap_rewrite(xmldoc)
|
81
|
+
def svgmap_rewrite(xmldoc, localdir = "")
|
82
82
|
xmldoc.xpath("//svgmap").each do |s|
|
83
|
-
next unless s
|
84
|
-
path = File.file?(
|
83
|
+
next unless src = s.at(".//image/@src")
|
84
|
+
path = File.file?(src) ? src : localdir + src
|
85
85
|
File.file?(path) or next
|
86
86
|
svg = Nokogiri::XML(File.read(path, encoding: "utf-8"))
|
87
87
|
svgmap_rewrite1(s, svg, path)
|
88
|
-
next if s.at("
|
89
|
-
|
88
|
+
next if s.at("./target/eref")
|
89
|
+
s.replace(s.at("./figure"))
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
def svgmap_to_image(s, height, width)
|
94
|
-
s.children.remove
|
95
|
-
s.name = "img"
|
96
|
-
s["mimetype"] = "image/svg+xml"
|
97
|
-
s["height"] = height || "auto"
|
98
|
-
s["width"] = width || "auto"
|
99
|
-
end
|
100
|
-
|
101
93
|
def svgmap_rewrite1(s, svg, path)
|
102
94
|
targets = s.xpath("./target").each_with_object({}) do |t, m|
|
103
95
|
x = t.at("./xref") and m[t["href"]] = "##{x['target']}"
|
data/lib/utils/version.rb
CHANGED
data/spec/utils_spec.rb
CHANGED
@@ -94,13 +94,19 @@ RSpec.describe Metanorma::Utils do
|
|
94
94
|
<doctype>article</doctype>
|
95
95
|
</ext>
|
96
96
|
</bibdata>
|
97
|
-
<sections
|
98
|
-
<svgmap id="
|
99
|
-
<svgmap id="
|
97
|
+
<sections>
|
98
|
+
<svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
|
99
|
+
<svgmap id="_4072bdcb-5895-4821-b636-5795b96787cb">
|
100
|
+
<figure><image src="action_schemaexpg1.svg"/></figure>
|
101
|
+
<target href="mn://action_schema"><xref target="ref1">Computer</xref></target><target href="http://www.example.com"><link target="http://www.example.com">Phone</link></target>
|
102
|
+
</svgmap>
|
103
|
+
<svgmap id="_60dadf08-48d4-4164-845c-b4e293e00abd">
|
104
|
+
<figure><image src="action_schemaexpg2.svg" alt="Workmap"/></figure>
|
105
|
+
<target href="href1.htm"><xref target="ref1">Computer</xref></target><target href="mn://basic_attribute_schema"><link target="http://www.example.com">Phone</link></target><target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
|
100
106
|
</standard-document>
|
101
107
|
INPUT
|
102
108
|
Metanorma::Utils.svgmap_rewrite(xmldoc)
|
103
|
-
expect(xmldoc.to_xml).to be_equivalent_to <<~OUTPUT
|
109
|
+
expect(xmlpp(xmldoc.to_xml)).to be_equivalent_to xmlpp(<<~OUTPUT)
|
104
110
|
<standard-document type="semantic" version="1.8.2">
|
105
111
|
<bibdata type="standard">
|
106
112
|
<title language="en" format="text/plain">Document title</title>
|
@@ -120,8 +126,14 @@ RSpec.describe Metanorma::Utils do
|
|
120
126
|
</ext>
|
121
127
|
</bibdata>
|
122
128
|
<sections><svgmap id="_d5b5049a-dd53-4ea0-bc6f-e8773bd59052"><target href="mn://action_schema"><xref target="ref1">Computer</xref></target></svgmap>
|
123
|
-
<
|
124
|
-
|
129
|
+
<figure>
|
130
|
+
<image src='action_schemaexpg1.svg'/>
|
131
|
+
</figure>
|
132
|
+
<svgmap id='_60dadf08-48d4-4164-845c-b4e293e00abd'>
|
133
|
+
<figure>
|
134
|
+
<image src='action_schemaexpg2.svg' alt='Workmap'/>
|
135
|
+
</figure>
|
136
|
+
<target href="mn://support_resource_schema"><eref type="express" bibitemid="express_action_schema" citeas=""><localityStack><locality type="anchor"><referenceFrom>action_schema.basic</referenceFrom></locality></localityStack>Coffee</eref></target></svgmap></sections>
|
125
137
|
</standard-document>
|
126
138
|
OUTPUT
|
127
139
|
expect(xmlpp(File.read("action_schemaexpg1.svg", encoding: "utf-8").sub(%r{<image .*</image>}m, ""))).to be_equivalent_to <<~OUTPUT
|
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.0.
|
4
|
+
version: 1.0.3
|
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-01
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sterile
|