metanorma 2.0.0 → 2.0.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/metanorma/collection/collection.rb +1 -0
- data/lib/metanorma/collection/config/compile_options.rb +2 -2
- data/lib/metanorma/collection/manifest/manifest.rb +1 -1
- data/lib/metanorma/collection/renderer/fileparse.rb +25 -18
- data/lib/metanorma/collection/renderer/fileprocess.rb +2 -1
- data/lib/metanorma/collection/renderer/utils.rb +29 -1
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +17 -16
- data/lib/metanorma/compile/compile.rb +2 -1
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e431712d7f4227aebd3fd2b42f3d50be8eb628d98c053402af5cb5d030a5e758
|
4
|
+
data.tar.gz: 52b93e29ad9c7d2e6ac7f67f83640a8fb7ea9f18427054cbdfe6439ff9fd1f01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ccada56674d3debae40e4231226f0220b04f340331458bdc834b7c964e0dc69f1a0bf52c021637930f34de00d2b618e110310bf63fc35d4387666cd57cf701
|
7
|
+
data.tar.gz: 6ed7ec2eb5cf57dc74f679666cd710c5e8ecc90ee2ffedc79951fc0cbfe31e1aa48c82b2772aac6b9fefe55142ed0e5ebe95f7b5cd2a57e7c7c08afdc3348f4e
|
@@ -4,8 +4,8 @@ module Metanorma
|
|
4
4
|
class Collection
|
5
5
|
module Config
|
6
6
|
class CompileOptions < ::Shale::Mapper
|
7
|
-
attribute :
|
8
|
-
default: -> {
|
7
|
+
attribute :install_fonts, ::Shale::Type::Boolean,
|
8
|
+
default: -> { false }
|
9
9
|
attribute :agree_to_terms, ::Shale::Type::Boolean, default: -> { true }
|
10
10
|
end
|
11
11
|
end
|
@@ -167,7 +167,7 @@ module Metanorma
|
|
167
167
|
|
168
168
|
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...", :info)
|
169
169
|
::Metanorma::Compile.new
|
170
|
-
.compile(f, agree_to_terms: true,
|
170
|
+
.compile(f, agree_to_terms: true, install_fonts: false,
|
171
171
|
extension_keys: [:xml])
|
172
172
|
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...done!", :info)
|
173
173
|
end
|
@@ -25,7 +25,7 @@ module Metanorma
|
|
25
25
|
update_direct_refs_to_docs(xml, docid)
|
26
26
|
hide_refs(xml)
|
27
27
|
sso and eref2link(xml)
|
28
|
-
svgmap_resolve(xml, docid)
|
28
|
+
@nested or svgmap_resolve(xml, docid)
|
29
29
|
xml.to_xml
|
30
30
|
end
|
31
31
|
|
@@ -59,13 +59,6 @@ module Metanorma
|
|
59
59
|
doclist
|
60
60
|
end
|
61
61
|
|
62
|
-
def new_hidden_ref(xmldoc)
|
63
|
-
ins = xmldoc.at(ns("bibliography")) or
|
64
|
-
xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
|
65
|
-
ins.at(ns("./referenced[@hidden = 'true']")) or
|
66
|
-
ins.add_child("<references hidden='true' normative='false'/>").first
|
67
|
-
end
|
68
|
-
|
69
62
|
def eref2link(docxml)
|
70
63
|
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
71
64
|
isodoc.bibitem_lookup(docxml)
|
@@ -86,20 +79,36 @@ module Metanorma
|
|
86
79
|
end
|
87
80
|
end
|
88
81
|
|
82
|
+
def svg_datauri(docxml, docid)
|
83
|
+
rel = @files.get(docid, :rel_path)
|
84
|
+
parent = @files.get(docid, :parentid) and
|
85
|
+
rel = @files.get(parent, :rel_path)
|
86
|
+
# if sectionsplit, use orig file dir
|
87
|
+
dir = File.join(@dirname, File.dirname(rel))
|
88
|
+
datauri_encode(docxml, dir)
|
89
|
+
end
|
90
|
+
|
89
91
|
def svgmap_resolve(docxml, docid)
|
90
92
|
ids = @files.get(docid, :ids)
|
91
|
-
|
92
|
-
docxml = datauri_encode(docxml, dir)
|
93
|
+
docxml = svg_unnest(svg_datauri(docxml, docid))
|
93
94
|
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
94
95
|
isodoc.bibitem_lookup(docxml)
|
95
96
|
docxml.xpath(ns("//svgmap//eref")).each do |e|
|
96
|
-
|
97
|
+
svgmap_resolve_eref(e, isodoc, docxml, ids)
|
97
98
|
end
|
98
99
|
Vectory::SvgMapping.new(docxml, "").call
|
99
100
|
docxml.xpath(ns("//svgmap")).each { |s| isodoc.svgmap_extract(s) }
|
100
101
|
end
|
101
102
|
|
102
|
-
def
|
103
|
+
def svg_unnest(docxml)
|
104
|
+
docxml.xpath(ns("//svgmap//image[.//*[name() = 'image']]")).each do |i|
|
105
|
+
s = i.elements.detect { |e| e.name == "svg" } and
|
106
|
+
i.replace(s)
|
107
|
+
end
|
108
|
+
docxml
|
109
|
+
end
|
110
|
+
|
111
|
+
def svgmap_resolve_eref(eref, isodoc, _docxml, ids)
|
103
112
|
href = isodoc.eref_target(eref) or return
|
104
113
|
href == "##{eref['bibitemid']}" ||
|
105
114
|
(href =~ /^#/ && !ids[href.sub(/^#/, "")]) and return
|
@@ -189,9 +198,8 @@ module Metanorma
|
|
189
198
|
@updated_anchors[anchor] = true
|
190
199
|
end
|
191
200
|
|
192
|
-
def update_indirect_refs_to_docs_docid(
|
193
|
-
docid =
|
194
|
-
return
|
201
|
+
def update_indirect_refs_to_docs_docid(bib, file)
|
202
|
+
docid = bib&.at(ns("./docidentifier[@type = 'repository']")) or return
|
195
203
|
docid.children = "current-metanorma-collection/#{file}"
|
196
204
|
docid.previous =
|
197
205
|
"<docidentifier type='metanorma-collection'>#{file}</docidentifier>"
|
@@ -237,9 +245,8 @@ module Metanorma
|
|
237
245
|
type = ins.at(ns("./locality/@type"))&.text
|
238
246
|
type = "clause" if type == "annex"
|
239
247
|
ref = ins.at(ns("./locality/referenceFrom"))&.text
|
240
|
-
|
241
|
-
ins << "<locality type='anchor'><referenceFrom>#{
|
242
|
-
'')}" \
|
248
|
+
a = @files.get(docid, :anchors).dig(type, ref) or return
|
249
|
+
ins << "<locality type='anchor'><referenceFrom>#{a.sub(/^_/, '')}" \
|
243
250
|
"</referenceFrom></locality>"
|
244
251
|
end
|
245
252
|
end
|
@@ -51,7 +51,8 @@ module Metanorma
|
|
51
51
|
out = out.relative_path_from(File.expand_path(FileUtils.pwd))
|
52
52
|
dest = File.join(@outdir, @disambig.source2dest_filename(out.to_s))
|
53
53
|
FileUtils.mkdir_p(File.dirname(dest))
|
54
|
-
|
54
|
+
source = @files.get(identifier, :ref)
|
55
|
+
source != dest and FileUtils.cp source, dest
|
55
56
|
end
|
56
57
|
|
57
58
|
# process each file in the collection
|
@@ -3,7 +3,7 @@ module Metanorma
|
|
3
3
|
class Renderer
|
4
4
|
def dir_name_cleanse(name)
|
5
5
|
path = Pathname.new(name)
|
6
|
-
clean_regex = /[<>:"
|
6
|
+
clean_regex = /[<>:"|?*\p{Zs}]/
|
7
7
|
fallback_sym = "_"
|
8
8
|
return name.gsub(clean_regex, fallback_sym) unless path.absolute?
|
9
9
|
|
@@ -40,6 +40,13 @@ module Metanorma
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def new_hidden_ref(xmldoc)
|
44
|
+
ins = xmldoc.at(ns("bibliography")) or
|
45
|
+
xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
|
46
|
+
ins.at(ns("./referenced[@hidden = 'true']")) or
|
47
|
+
ins.add_child("<references hidden='true' normative='false'/>").first
|
48
|
+
end
|
49
|
+
|
43
50
|
def strip_eref(eref)
|
44
51
|
eref.xpath(ns("./locality | ./localityStack")).each(&:remove)
|
45
52
|
eref.replace(eref.children)
|
@@ -119,11 +126,32 @@ module Metanorma
|
|
119
126
|
|
120
127
|
def datauri_encode(docxml, directory)
|
121
128
|
docxml.xpath(ns("//image")).each do |i|
|
129
|
+
read_in_if_svg(i, directory.sub(%r{(?<!=/)$}, "/")) and i["src"] = nil
|
130
|
+
end
|
131
|
+
docxml.xpath(ns("//image")).each do |i| # rubocop:disable Style/CombinableLoops
|
132
|
+
i["src"] && !i["src"].empty? or next
|
122
133
|
i["src"] = Vectory::Utils::datauri(i["src"], directory)
|
123
134
|
end
|
124
135
|
docxml
|
125
136
|
end
|
126
137
|
|
138
|
+
def read_in_if_svg(img, localdir)
|
139
|
+
img["src"] or return false
|
140
|
+
img.elements.map(&:name).include?("svg") and return true
|
141
|
+
path = Vectory::Utils.svgmap_rewrite0_path(img["src"], localdir)
|
142
|
+
svg = svg_in_path?(path) or return false
|
143
|
+
img.children = (Nokogiri::XML(svg).root)
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
147
|
+
def svg_in_path?(path)
|
148
|
+
File.file?(path) or return false
|
149
|
+
types = MIME::Types.type_for(path) or return false
|
150
|
+
types.first == "image/svg+xml" or return false
|
151
|
+
svg = File.read(path, encoding: "utf-8") or return false
|
152
|
+
svg
|
153
|
+
end
|
154
|
+
|
127
155
|
class PdfOptionsNode
|
128
156
|
def initialize(doctype, options)
|
129
157
|
p = Metanorma::Registry.instance.find_processor(doctype)
|
@@ -66,7 +66,6 @@ module Metanorma
|
|
66
66
|
["//indexsect", nil], ["//colophon", nil]].freeze
|
67
67
|
|
68
68
|
# Input XML is Semantic
|
69
|
-
# def sectionsplit(filename, basename, dir, compile_options, fileslookup = nil, ident = nil)
|
70
69
|
def sectionsplit
|
71
70
|
xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
|
72
71
|
@key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
|
@@ -96,14 +95,15 @@ module Metanorma
|
|
96
95
|
|
97
96
|
def sectionsplit_prep(file, filename, dir)
|
98
97
|
@splitdir = dir
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
Nokogiri::XML(
|
106
|
-
|
98
|
+
xml1, type = sectionsplit_preprocess_semxml(file, filename)
|
99
|
+
flags = { format: :asciidoc, extension_keys: [:presentation],
|
100
|
+
type: type }.merge(@compile_opts)
|
101
|
+
Compile.new.compile(xml1, flags)
|
102
|
+
f = File.open(xml1.sub(/\.xml$/, ".presentation.xml"),
|
103
|
+
encoding: "utf-8")
|
104
|
+
r = Nokogiri::XML(f, &:huge)
|
105
|
+
r.xpath("//xmlns:svgmap1").each { |x| x.name = "svgmap" }
|
106
|
+
r
|
107
107
|
end
|
108
108
|
|
109
109
|
def sectionsplit_preprocess_semxml(file, filename)
|
@@ -111,9 +111,7 @@ module Metanorma
|
|
111
111
|
type = xml.root.name.sub("-standard", "").to_sym
|
112
112
|
sectionsplit_update_xrefs(xml)
|
113
113
|
xml1 = sectionsplit_write_semxml(filename, xml)
|
114
|
-
|
115
|
-
@filecache << xml1
|
116
|
-
[xml1.path, type]
|
114
|
+
[xml1, type]
|
117
115
|
end
|
118
116
|
|
119
117
|
def sectionsplit_update_xrefs(xml)
|
@@ -122,15 +120,17 @@ module Metanorma
|
|
122
120
|
c.nested = true # so unresolved erefs are not deleted
|
123
121
|
c.update_xrefs(xml, @ident, {})
|
124
122
|
c.nested = n
|
123
|
+
xml.xpath("//xmlns:svgmap").each { |x| x.name = "svgmap1" }
|
124
|
+
# do not process svgmap until after files are split
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
def sectionsplit_write_semxml(filename, xml)
|
129
|
-
|
130
|
-
|
129
|
+
outname = Pathname.new("tmp_#{filename}").sub_ext(".xml").to_s
|
130
|
+
File.open(outname, "w:UTF-8") do |f|
|
131
131
|
f.write(@isodoc.to_xml(xml))
|
132
|
-
f
|
133
132
|
end
|
133
|
+
outname
|
134
134
|
end
|
135
135
|
|
136
136
|
def emptydoc(xml)
|
@@ -152,7 +152,8 @@ module Metanorma
|
|
152
152
|
def create_sectionfile(xml, out, file, chunks, parentnode)
|
153
153
|
ins = out.at(ns("//metanorma-extension")) || out.at(ns("//bibdata"))
|
154
154
|
sectionfile_insert(ins, chunks, parentnode)
|
155
|
-
Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
|
155
|
+
Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
|
156
|
+
@ident, @isodoc)
|
156
157
|
outname = "#{file}.xml"
|
157
158
|
File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
|
158
159
|
f.write(out)
|
@@ -149,7 +149,8 @@ module Metanorma
|
|
149
149
|
if ext == :rxl
|
150
150
|
relaton_export(isodoc, options.merge(relaton: fnames[:out]))
|
151
151
|
elsif options[:passthrough_presentation_xml] && ext == :presentation
|
152
|
-
f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
|
152
|
+
#f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
|
153
|
+
f = File.exist?(fnames[:orig_filename]) ? fnames[:orig_filename] : fnames[:f]
|
153
154
|
FileUtils.cp f, fnames[:presentationxml]
|
154
155
|
elsif ext == :html && options[:sectionsplit]
|
155
156
|
sectionsplit_convert(fnames[:xml], isodoc, fnames[:out],
|
data/lib/metanorma/version.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.bindir = "bin"
|
22
22
|
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
|
-
spec.required_ruby_version = ">=
|
24
|
+
spec.required_ruby_version = ">= 3.1.0"
|
25
25
|
|
26
26
|
spec.add_runtime_dependency "asciidoctor"
|
27
27
|
spec.add_runtime_dependency "fontist", ">= 1.14.3"
|
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.0.
|
4
|
+
version: 2.0.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: 2024-
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -335,7 +335,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
335
335
|
requirements:
|
336
336
|
- - ">="
|
337
337
|
- !ruby/object:Gem::Version
|
338
|
-
version:
|
338
|
+
version: 3.1.0
|
339
339
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
340
340
|
requirements:
|
341
341
|
- - ">="
|