metanorma 2.0.6 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metanorma/collection/collection.rb +19 -6
- data/lib/metanorma/collection/config/bibdata.rb +2 -2
- data/lib/metanorma/collection/config/compile_options.rb +4 -5
- data/lib/metanorma/collection/config/config.rb +42 -73
- data/lib/metanorma/collection/config/converters.rb +27 -1
- data/lib/metanorma/collection/config/directive.rb +9 -3
- data/lib/metanorma/collection/config/manifest.rb +33 -26
- data/lib/metanorma/collection/filelookup/filelookup.rb +20 -8
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +40 -16
- data/lib/metanorma/collection/manifest/manifest.rb +1 -1
- data/lib/metanorma/collection/renderer/fileparse.rb +94 -121
- data/lib/metanorma/collection/renderer/navigation.rb +1 -1
- data/lib/metanorma/collection/renderer/renderer.rb +4 -1
- data/lib/metanorma/collection/renderer/svg.rb +44 -0
- data/lib/metanorma/collection/renderer/utils.rb +18 -10
- data/lib/metanorma/collection/sectionsplit/collection.rb +6 -6
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +52 -13
- data/lib/metanorma/collection/util/util.rb +17 -3
- data/lib/metanorma/compile/compile.rb +8 -0
- data/lib/metanorma/compile/extract.rb +2 -4
- data/lib/metanorma/input/asciidoc.rb +11 -10
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +3 -3
- metadata +21 -21
- data/lib/metanorma/shale_monkeypatch.rb +0 -15
@@ -19,6 +19,7 @@ module Metanorma
|
|
19
19
|
@nested || sso or
|
20
20
|
Metanorma::Collection::XrefProcess::xref_process(xml, xml, nil, docid,
|
21
21
|
@isodoc)
|
22
|
+
@ncnames = {}
|
22
23
|
@nested or update_indirect_refs_to_docs(xml, docid, internal_refs)
|
23
24
|
@files.add_document_suffix(docid, xml)
|
24
25
|
@nested or update_sectionsplit_refs_to_docs(xml, internal_refs)
|
@@ -49,9 +50,11 @@ module Metanorma
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
53
|
+
ANCHOR_XPATH = "xmlns:locality[@type = 'anchor']/xmlns:referenceFrom"
|
54
|
+
.freeze
|
55
|
+
|
52
56
|
def update_sectionsplit_eref_to_doc(eref, internal_refs, doclist, opts)
|
53
|
-
a = eref.at(
|
54
|
-
"referenceFrom")) or return
|
57
|
+
a = eref.at("./xmlns:localityStack/#{ANCHOR_XPATH}") or return
|
55
58
|
doc = internal_refs[opts[:key]]["#{a.text}_#{opts[:target_suffix]}"]
|
56
59
|
bibitemid = Metanorma::Utils::to_ncname("#{doc}_#{opts[:source_suffix]}")
|
57
60
|
eref["bibitemid"] = bibitemid
|
@@ -59,12 +62,6 @@ module Metanorma
|
|
59
62
|
doclist
|
60
63
|
end
|
61
64
|
|
62
|
-
def eref2link(docxml)
|
63
|
-
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
64
|
-
isodoc.bibitem_lookup(docxml)
|
65
|
-
isodoc.eref2link(docxml)
|
66
|
-
end
|
67
|
-
|
68
65
|
BIBITEM_NOT_REPO_XPATH = "//bibitem[not(ancestor::bibitem)]" \
|
69
66
|
"[not(./docidentifier[@type = 'repository'])]".freeze
|
70
67
|
|
@@ -79,64 +76,37 @@ module Metanorma
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
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
|
-
|
91
|
-
def svgmap_resolve(docxml, docid)
|
92
|
-
ids = @files.get(docid, :ids)
|
93
|
-
docxml = svg_unnest(svg_datauri(docxml, docid))
|
94
|
-
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
95
|
-
isodoc.bibitem_lookup(docxml)
|
96
|
-
docxml.xpath(ns("//svgmap//eref")).each do |e|
|
97
|
-
svgmap_resolve_eref(e, isodoc, docxml, ids)
|
98
|
-
end
|
99
|
-
Vectory::SvgMapping.new(docxml, "").call
|
100
|
-
docxml.xpath(ns("//svgmap")).each { |s| isodoc.svgmap_extract(s) }
|
101
|
-
end
|
102
|
-
|
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)
|
112
|
-
href = isodoc.eref_target(eref) or return
|
113
|
-
href = href[:link]
|
114
|
-
href == "##{eref['bibitemid']}" ||
|
115
|
-
(href =~ /^#/ && !ids[href.sub(/^#/, "")]) and return
|
116
|
-
eref["target"] = href.strip
|
117
|
-
eref.name = "link"
|
118
|
-
eref.elements&.remove
|
119
|
-
end
|
120
|
-
|
121
79
|
# repo(current-metanorma-collection/ISO 17301-1:2016)
|
122
80
|
# replaced by bibdata of "ISO 17301-1:2016" in situ as bibitem.
|
123
81
|
# Any erefs to that bibitem id are replaced with relative URL
|
124
82
|
# Preferably with anchor, and is a job to realise dynamic lookup
|
125
83
|
# of localities.
|
126
84
|
def update_direct_refs_to_docs(docxml, identifier)
|
127
|
-
erefs, erefs1 =
|
85
|
+
erefs, erefs_no_anchor, anchors, erefs1 =
|
86
|
+
update_direct_refs_to_docs_prep(docxml)
|
128
87
|
docxml.xpath(ns("//bibitem")).each do |b|
|
129
88
|
docid = b.at(ns("./docidentifier[@type = 'repository']")) or next
|
130
89
|
strip_unresolved_repo_erefs(identifier, docid, erefs1, b) or next
|
131
90
|
update_bibitem(b, identifier)
|
132
91
|
docid = docid_to_citeas(b) or next
|
133
|
-
erefs[docid] and
|
92
|
+
erefs[docid] and
|
93
|
+
update_anchors(b, docid, erefs[docid], erefs_no_anchor[docid],
|
94
|
+
anchors[docid])
|
134
95
|
end
|
135
96
|
end
|
136
97
|
|
98
|
+
# Hash(docid) of arrays
|
137
99
|
def update_direct_refs_to_docs_prep(docxml)
|
138
|
-
|
139
|
-
|
100
|
+
erefs = Util::gather_citeases(docxml)
|
101
|
+
no_anchor = erefs.keys.each_with_object({}) { |k, m| m[k] = [] }
|
102
|
+
anchors = erefs.keys.each_with_object({}) { |k, m| m[k] = [] }
|
103
|
+
erefs.each do |k, v|
|
104
|
+
v.each do |e|
|
105
|
+
if loc = e.at(".//#{ANCHOR_XPATH}") then anchors[k] << loc
|
106
|
+
else no_anchor[k] << e end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
[erefs, no_anchor, anchors, Util::gather_bibitemids(docxml)]
|
140
110
|
end
|
141
111
|
|
142
112
|
# strip erefs if they are repository erefs, but do not point to a document
|
@@ -155,56 +125,78 @@ module Metanorma
|
|
155
125
|
# Resolve erefs to a container of ids in another doc,
|
156
126
|
# to an anchor eref (direct link)
|
157
127
|
def update_indirect_refs_to_docs(docxml, _docidentifier, internal_refs)
|
158
|
-
|
128
|
+
bib, erefs, doc_suffix, doc_type, f = update_indirect_refs_prep(docxml)
|
159
129
|
internal_refs.each do |schema, ids|
|
160
|
-
|
130
|
+
add_suffix = doc_suffix && doc_type && doc_type != schema
|
161
131
|
ids.each do |id, file|
|
162
|
-
|
163
|
-
|
132
|
+
f[file] ||= { url: @files.url?(file),
|
133
|
+
parentid: @files.get(file) && @files.get(file,
|
134
|
+
:parentid) }
|
135
|
+
k = indirect_ref_key(schema, id, doc_suffix, add_suffix)
|
136
|
+
update_indirect_refs_to_docs1(f[file], k, file, bib, erefs)
|
164
137
|
end
|
165
138
|
end
|
166
139
|
end
|
167
140
|
|
168
|
-
def
|
141
|
+
def update_indirect_refs_prep(docxml)
|
169
142
|
@updated_anchors = {}
|
170
|
-
|
143
|
+
@indirect_keys = {}
|
144
|
+
[Util::gather_bibitems(docxml), Util::gather_bibitemids(docxml),
|
145
|
+
docxml.root["document_suffix"], docxml.root["type"], {}]
|
146
|
+
end
|
147
|
+
|
148
|
+
def indirect_ref_key(schema, id, doc_suffix, doc_type)
|
149
|
+
/^#{schema}_/.match?(id) and return id
|
150
|
+
key = [schema, id, doc_suffix, doc_type].join("::")
|
151
|
+
x = @indirect_keys[key] and return x
|
152
|
+
ret = "#{schema}_#{id}"
|
153
|
+
doc_suffix && doc_type && doc_type != schema and
|
154
|
+
ret = "#{ret}_#{doc_suffix}"
|
155
|
+
@indirect_keys[key] = ret
|
156
|
+
ret
|
171
157
|
end
|
172
158
|
|
173
|
-
def indirect_ref_key(
|
174
|
-
/^#{
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
159
|
+
def indirect_ref_key(schema, id, doc_suffix, add_suffix)
|
160
|
+
/^#{schema}_/.match?(id) and return id
|
161
|
+
#key = "#{schema}_#{id}"
|
162
|
+
x = @indirect_keys.dig(schema, id) and return x
|
163
|
+
@indirect_keys[schema] ||= {}
|
164
|
+
@indirect_keys[schema][id] = if add_suffix
|
165
|
+
"#{schema}_#{id}_#{doc_suffix}"
|
166
|
+
else
|
167
|
+
"#{schema}_#{id}"
|
168
|
+
end
|
179
169
|
end
|
180
170
|
|
181
|
-
|
182
|
-
def indirect_ref_key1(schema, id, docxml)
|
171
|
+
def indirect_ref_keyx(schema, id, doc_suffix, doc_type)
|
183
172
|
/^#{schema}_/.match?(id) and return id
|
184
173
|
ret = "#{schema}_#{id}"
|
185
|
-
|
186
|
-
|
187
|
-
ret = "#{ret}_#{suffix}"
|
174
|
+
doc_suffix && doc_type && doc_type != schema and
|
175
|
+
ret = "#{ret}_#{doc_suffix}"
|
188
176
|
ret
|
189
177
|
end
|
190
178
|
|
191
|
-
def update_indirect_refs_to_docs1(
|
179
|
+
def update_indirect_refs_to_docs1(filec, key, file, bibitems, erefs)
|
192
180
|
erefs[key]&.each do |e|
|
193
181
|
e["citeas"] = file
|
194
|
-
update_indirect_refs_to_docs_anchor(e, file
|
182
|
+
update_indirect_refs_to_docs_anchor(e, file, filec[:url],
|
183
|
+
filec[:parentid])
|
195
184
|
end
|
196
185
|
update_indirect_refs_to_docs_docid(bibitems[key], file)
|
197
186
|
end
|
198
187
|
|
199
|
-
def update_indirect_refs_to_docs_anchor(eref, file)
|
200
|
-
a = eref.at(
|
201
|
-
|
202
|
-
@files.get(file) && p = @files.get(file, :parentid) and
|
203
|
-
suffix = "#{p}_#{suffix}"
|
188
|
+
def update_indirect_refs_to_docs_anchor(eref, file, url, parentid)
|
189
|
+
a = eref.at(".//#{ANCHOR_XPATH}") or return
|
190
|
+
parentid and file = "#{parentid}_#{file}"
|
204
191
|
existing = a.text
|
205
|
-
anchor = existing
|
206
|
-
|
207
|
-
|
192
|
+
anchor = if url then existing
|
193
|
+
else
|
194
|
+
#suffix_anchor_indirect(existing, suffix)
|
195
|
+
#k = "#{existing}_#{file}"
|
196
|
+
#@ncnames[k] ||= Metanorma::Utils::to_ncname(k)
|
197
|
+
@indirect_keys[existing] ||= {}
|
198
|
+
@indirect_keys[existing][file] ||= Metanorma::Utils::to_ncname("#{existing}_#{file}")
|
199
|
+
end
|
208
200
|
@updated_anchors[existing] or a.children = anchor
|
209
201
|
@updated_anchors[anchor] = true
|
210
202
|
end
|
@@ -216,55 +208,36 @@ module Metanorma
|
|
216
208
|
"<docidentifier type='metanorma-collection'>#{file}</docidentifier>"
|
217
209
|
end
|
218
210
|
|
219
|
-
#
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
@log&.add("Cross-References", e, msg)
|
230
|
-
end
|
211
|
+
# bottleneck
|
212
|
+
def update_anchors(bib, docid, erefs, erefs_no_anchor, erefs_anchors)
|
213
|
+
@files.get(docid) or error_anchor(erefs, docid)
|
214
|
+
has_anchors, url, ncn_docid = update_anchors_prep(docid)
|
215
|
+
erefs_no_anchor.each do |e|
|
216
|
+
update_anchor_create_loc(bib, e, docid)
|
217
|
+
end
|
218
|
+
!url && has_anchors or return
|
219
|
+
erefs_anchors.each do |e|
|
220
|
+
update_anchors1(docid, ncn_docid, e)
|
231
221
|
end
|
232
222
|
end
|
233
223
|
|
234
|
-
def
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
anchor = suffix_anchor(ref.text, docid)
|
240
|
-
a.values.detect { |x| x.value?(anchor) } or return
|
241
|
-
ref.content = anchor
|
242
|
-
end
|
243
|
-
|
244
|
-
#OLD
|
245
|
-
def update_anchor_loc1(bib, eref, docid)
|
246
|
-
loc = eref.at(".//xmlns:locality[@type = 'anchor']") or
|
247
|
-
return update_anchor_create_loc(bib, eref, docid)
|
248
|
-
ref = loc.at("./xmlns:referenceFrom") or return
|
249
|
-
anchor = suffix_anchor(ref, docid)
|
250
|
-
a = @files.get(docid, :anchors) or return
|
251
|
-
a.inject([]) { |m, (_, x)| m + x.values }
|
252
|
-
.include?(anchor) or return
|
253
|
-
ref.content = anchor
|
224
|
+
def update_anchors1(docid, ncn_docid, anchor)
|
225
|
+
@concat_anchors[anchor.text] ||= "#{ncn_docid}_#{anchor.text}"
|
226
|
+
if @files.get(docid).dig(:anchors_lookup, @concat_anchors[anchor.text])
|
227
|
+
anchor.content = @concat_anchors[anchor.text]
|
228
|
+
end
|
254
229
|
end
|
255
230
|
|
256
|
-
def
|
257
|
-
@
|
258
|
-
@files.url?(docid)
|
259
|
-
|
231
|
+
def update_anchors_prep(docid)
|
232
|
+
@concat_anchors = {}
|
233
|
+
[@files.get(docid)&.key?(:anchors_lookup), @files.url?(docid),
|
234
|
+
Metanorma::Utils::to_ncname(docid)]
|
260
235
|
end
|
261
236
|
|
262
|
-
#
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
@files.url?(docid) or anchor = "#{@ncnames[docid]}_#{anchor}"
|
267
|
-
anchor
|
237
|
+
# encode both prefix and suffix to NCName
|
238
|
+
def suffix_anchor_indirect(prefix, suffix)
|
239
|
+
k = "#{prefix}_#{suffix}"
|
240
|
+
@ncnames[k] ||= Metanorma::Utils::to_ncname(k)
|
268
241
|
end
|
269
242
|
|
270
243
|
# if there is a crossref to another document, with no anchor, retrieve the
|
@@ -276,7 +249,7 @@ module Metanorma
|
|
276
249
|
ref = ins.at(ns("./locality/referenceFrom"))&.text
|
277
250
|
a = @files.get(docid, :anchors).dig(type, ref) or return
|
278
251
|
ins << "<locality type='anchor'><referenceFrom>#{a.sub(/^_/, '')}" \
|
279
|
-
|
252
|
+
"</referenceFrom></locality>"
|
280
253
|
end
|
281
254
|
end
|
282
255
|
end
|
@@ -8,6 +8,7 @@ require_relative "../multilingual/multilingual"
|
|
8
8
|
require_relative "utils"
|
9
9
|
require_relative "render_word"
|
10
10
|
require_relative "navigation"
|
11
|
+
require_relative "svg"
|
11
12
|
|
12
13
|
module Metanorma
|
13
14
|
class Collection
|
@@ -42,7 +43,8 @@ module Metanorma
|
|
42
43
|
@compile = Compile.new
|
43
44
|
@compile.load_flavor(@flavor)
|
44
45
|
|
45
|
-
|
46
|
+
# output processor for flavour
|
47
|
+
@isodoc = Util::isodoc_create(@flavor, @lang, @scropt, @xml)
|
46
48
|
@outdir = dir_name_cleanse(options[:output_folder])
|
47
49
|
@coverpage = options[:coverpage] || collection.coverpage
|
48
50
|
@format = ::Metanorma::Util.sort_extensions_execution(options[:format])
|
@@ -74,6 +76,7 @@ module Metanorma
|
|
74
76
|
|
75
77
|
def flush_files
|
76
78
|
warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
|
79
|
+
warn "\nFiles to delete:\n"
|
77
80
|
warn @files.files_to_delete
|
78
81
|
@files.files_to_delete.each { |f| FileUtils.rm_f(f) }
|
79
82
|
@files_to_delete.each { |f| FileUtils.rm_f(f) }
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Metanorma
|
2
|
+
class Collection
|
3
|
+
class Renderer
|
4
|
+
def svg_datauri(docxml, docid)
|
5
|
+
rel = @files.get(docid, :rel_path)
|
6
|
+
parent = @files.get(docid, :parentid) and
|
7
|
+
rel = @files.get(parent, :rel_path)
|
8
|
+
# if sectionsplit, use orig file dir
|
9
|
+
dir = File.join(@dirname, File.dirname(rel))
|
10
|
+
datauri_encode(docxml, dir)
|
11
|
+
end
|
12
|
+
|
13
|
+
def svgmap_resolve(docxml, docid)
|
14
|
+
ids = @files.get(docid, :ids)
|
15
|
+
docxml = svg_unnest(svg_datauri(docxml, docid))
|
16
|
+
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
17
|
+
isodoc.bibitem_lookup(docxml)
|
18
|
+
docxml.xpath(ns("//svgmap//eref")).each do |e|
|
19
|
+
svgmap_resolve_eref(e, isodoc, docxml, ids)
|
20
|
+
end
|
21
|
+
Vectory::SvgMapping.new(docxml, "").call
|
22
|
+
docxml.xpath(ns("//svgmap")).each { |s| isodoc.svgmap_extract(s) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def svg_unnest(docxml)
|
26
|
+
docxml.xpath(ns("//svgmap//image[.//*[name() = 'image']]")).each do |i|
|
27
|
+
s = i.elements.detect { |e| e.name == "svg" } and
|
28
|
+
i.replace(s)
|
29
|
+
end
|
30
|
+
docxml
|
31
|
+
end
|
32
|
+
|
33
|
+
def svgmap_resolve_eref(eref, isodoc, _docxml, ids)
|
34
|
+
href = isodoc.eref_target(eref) or return
|
35
|
+
href = href[:link]
|
36
|
+
href == "##{eref['bibitemid']}" ||
|
37
|
+
(href =~ /^#/ && !ids[href.sub(/^#/, "")]) and return
|
38
|
+
eref["target"] = href.strip
|
39
|
+
eref.name = "link"
|
40
|
+
eref.elements&.remove
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -55,7 +55,7 @@ module Metanorma
|
|
55
55
|
def docid_to_citeas(bib)
|
56
56
|
docid = bib.at(ns("./docidentifier[@primary = 'true']")) ||
|
57
57
|
bib.at(ns("./docidentifier")) or return
|
58
|
-
docid_prefix(docid)
|
58
|
+
::Metanorma::Collection::Util::key(docid_prefix(docid))
|
59
59
|
end
|
60
60
|
|
61
61
|
def collect_erefs(docxml)
|
@@ -168,21 +168,13 @@ module Metanorma
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
-
def isodoc_create
|
172
|
-
isodoc = Util::load_isodoc(@flavor)
|
173
|
-
isodoc.i18n_init(@lang, @script, @locale) # read in internationalisation
|
174
|
-
isodoc.metadata_init(@lang, @script, @locale, isodoc.i18n)
|
175
|
-
isodoc.info(@xml, nil)
|
176
|
-
isodoc
|
177
|
-
end
|
178
|
-
|
179
171
|
# create the @meta class of isodoc, for populating Liquid,
|
180
172
|
# with "navigation" set to the index bar.
|
181
173
|
# extracted from the manifest
|
182
174
|
def isodoc_populate
|
183
175
|
@isodoc.info(@xml, nil)
|
184
176
|
{ navigation: indexfile(@manifest), nav_object: index_object(@manifest),
|
185
|
-
docrefs: liquid_docrefs(@manifest),
|
177
|
+
bibdata: @bibdata.to_hash, docrefs: liquid_docrefs(@manifest),
|
186
178
|
"prefatory-content": isodoc_builder(@xml.at("//prefatory-content")),
|
187
179
|
"final-content": isodoc_builder(@xml.at("//final-content")),
|
188
180
|
doctitle: @bibdata.title.first.title.content,
|
@@ -203,6 +195,22 @@ module Metanorma
|
|
203
195
|
end.doc.root.to_html
|
204
196
|
end
|
205
197
|
|
198
|
+
def eref2link(docxml)
|
199
|
+
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
200
|
+
isodoc.bibitem_lookup(docxml)
|
201
|
+
isodoc.eref2link(docxml)
|
202
|
+
end
|
203
|
+
|
204
|
+
def error_anchor(erefs, docid)
|
205
|
+
erefs.each do |e|
|
206
|
+
msg = "<strong>** Unresolved reference to document #{docid} " \
|
207
|
+
"from eref</strong>"
|
208
|
+
e << msg
|
209
|
+
strip_eref(e)
|
210
|
+
@log&.add("Cross-References", e, msg)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
206
214
|
def ns(xpath)
|
207
215
|
@isodoc.ns(xpath)
|
208
216
|
end
|
@@ -76,22 +76,22 @@ module Metanorma
|
|
76
76
|
File.basename(ret)
|
77
77
|
end
|
78
78
|
|
79
|
-
def section_split_cover(col, ident,
|
79
|
+
def section_split_cover(col, ident, one_doc_coll)
|
80
80
|
dir = File.dirname(col.file)
|
81
81
|
collection_setup(nil, dir)
|
82
82
|
r = ::Metanorma::Collection::Renderer
|
83
83
|
.new(col, dir, output_folder: "#{ident}_collection",
|
84
|
-
format: %i(html),
|
84
|
+
format: %i(html),
|
85
|
+
coverpage: File.join(dir, "cover.html"))
|
85
86
|
r.coverpage
|
86
|
-
section_split_cover1(ident, r, dir,
|
87
|
+
section_split_cover1(ident, r, dir, one_doc_coll)
|
87
88
|
end
|
88
89
|
|
89
90
|
def section_split_cover1(ident, renderer, dir, _one_doc_coll)
|
90
|
-
# filename = one_doc_coll ? "#{ident}_index.html" : "index.html"
|
91
91
|
filename = File.basename("#{ident}_index.html")
|
92
92
|
# ident can be a directory with YAML indirection
|
93
|
-
|
94
|
-
|
93
|
+
dest = File.join(dir, filename)
|
94
|
+
FileUtils.mv File.join(renderer.outdir, "index.html"), dest
|
95
95
|
FileUtils.rm_rf renderer.outdir
|
96
96
|
filename
|
97
97
|
end
|
@@ -2,6 +2,7 @@ require "yaml"
|
|
2
2
|
require_relative "../../util/util"
|
3
3
|
require_relative "../xrefprocess/xrefprocess"
|
4
4
|
require_relative "collection"
|
5
|
+
require "concurrent-ruby"
|
5
6
|
|
6
7
|
module Metanorma
|
7
8
|
class Collection
|
@@ -35,12 +36,32 @@ module Metanorma
|
|
35
36
|
def sectionsplit
|
36
37
|
xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
|
37
38
|
@key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
|
38
|
-
|
39
|
+
empty = empty_doc(xml)
|
40
|
+
empty1 = empty_attachments(empty)
|
41
|
+
@mutex = Mutex.new
|
42
|
+
@pool = Concurrent::FixedThreadPool.new(4)
|
43
|
+
sectionsplit1(xml, empty, empty1, 0)
|
44
|
+
end
|
45
|
+
|
46
|
+
def sectionsplit1(xml, empty, empty1, idx)
|
47
|
+
ret = SPLITSECTIONS.each_with_object([]) do |n, m|
|
39
48
|
conflate_floatingtitles(xml.xpath(ns(n[0]))).each do |s|
|
40
|
-
|
41
|
-
|
49
|
+
sectionsplit2(xml, idx.zero? ? empty : empty1, s, n[1],
|
50
|
+
{ acc: m, idx: idx })
|
51
|
+
idx += 1
|
42
52
|
end
|
43
53
|
end
|
54
|
+
@pool.shutdown
|
55
|
+
@pool.wait_for_termination
|
56
|
+
ret
|
57
|
+
end
|
58
|
+
|
59
|
+
def sectionsplit2(xml, empty, chunks, parentnode, opt)
|
60
|
+
@pool.post do
|
61
|
+
a = sectionfile(xml, empty, "#{@base}.#{opt[:idx]}", chunks,
|
62
|
+
parentnode)
|
63
|
+
@mutex.synchronize { opt[:acc] << a }
|
64
|
+
end
|
44
65
|
end
|
45
66
|
|
46
67
|
def block?(node)
|
@@ -61,13 +82,13 @@ module Metanorma
|
|
61
82
|
|
62
83
|
def sectionsplit_prep(file, filename, dir)
|
63
84
|
@splitdir = dir
|
64
|
-
|
85
|
+
xml, type = sectionsplit_preprocess_semxml(file, filename)
|
65
86
|
flags = { format: :asciidoc, extension_keys: [:presentation],
|
66
87
|
type: type }.merge(@compile_opts)
|
67
|
-
Compile.new.compile(
|
68
|
-
f = File.open(
|
69
|
-
encoding: "utf-8")
|
88
|
+
Compile.new.compile(xml, flags)
|
89
|
+
f = File.open(xml.sub(/\.xml$/, ".presentation.xml"), encoding: "utf-8")
|
70
90
|
r = Nokogiri::XML(f, &:huge)
|
91
|
+
f.close
|
71
92
|
r.xpath("//xmlns:svgmap1").each { |x| x.name = "svgmap" }
|
72
93
|
r
|
73
94
|
end
|
@@ -108,7 +129,25 @@ module Metanorma
|
|
108
129
|
"//indexsect | //colophon"),
|
109
130
|
).each(&:remove)
|
110
131
|
ordinal.zero? or out.xpath(ns("//metanorma-ext//attachment | " \
|
111
|
-
|
132
|
+
"//semantic__metanorma-ext//semantic__attachment"))
|
133
|
+
.each(&:remove) # keep only one copy of attachments
|
134
|
+
out
|
135
|
+
end
|
136
|
+
|
137
|
+
def empty_doc(xml)
|
138
|
+
out = xml.dup
|
139
|
+
out.xpath(
|
140
|
+
ns("//preface | //sections | //annex | //bibliography/clause | " \
|
141
|
+
"//bibliography/references[not(@hidden = 'true')] | " \
|
142
|
+
"//indexsect | //colophon"),
|
143
|
+
).each(&:remove)
|
144
|
+
out
|
145
|
+
end
|
146
|
+
|
147
|
+
def empty_attachments(xml)
|
148
|
+
out = xml.dup
|
149
|
+
out.xpath(ns("//metanorma-ext//attachment | " \
|
150
|
+
"//semantic__metanorma-ext//semantic__attachment"))
|
112
151
|
.each(&:remove) # keep only one copy of attachments
|
113
152
|
out
|
114
153
|
end
|
@@ -126,7 +165,9 @@ module Metanorma
|
|
126
165
|
@ident, @isodoc)
|
127
166
|
truncate_semxml(out, chunks)
|
128
167
|
outname = "#{file}.xml"
|
129
|
-
File.open(File.join(@splitdir, outname), "w:UTF-8")
|
168
|
+
File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
|
169
|
+
f.write(out)
|
170
|
+
end
|
130
171
|
outname
|
131
172
|
end
|
132
173
|
|
@@ -161,13 +202,11 @@ module Metanorma
|
|
161
202
|
end
|
162
203
|
|
163
204
|
def titlerender(section)
|
164
|
-
title = section.at(ns("./title")) or return "[Untitled]"
|
205
|
+
title = section.at(ns("./fmt-title")) or return "[Untitled]"
|
165
206
|
t = title.dup
|
166
207
|
t.xpath(ns(".//tab | .//br")).each { |x| x.replace(" ") }
|
167
208
|
t.xpath(ns(".//bookmark")).each(&:remove)
|
168
|
-
t.xpath(
|
169
|
-
.each { |x| x.replace(x.children) }
|
170
|
-
t.children.to_xml
|
209
|
+
t.xpath('.//text()').map(&:text).join
|
171
210
|
end
|
172
211
|
end
|
173
212
|
end
|
@@ -25,8 +25,9 @@ module Metanorma
|
|
25
25
|
def gather_citeases(xml)
|
26
26
|
xml.xpath("//*[@citeas]").each_with_object({}) do |e, m|
|
27
27
|
/^semantic__/.match?(e.name) and next
|
28
|
-
|
29
|
-
m[
|
28
|
+
k = key(e["citeas"])
|
29
|
+
m[k] ||= []
|
30
|
+
m[k] << e
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
@@ -61,10 +62,23 @@ module Metanorma
|
|
61
62
|
def attr(_key); end
|
62
63
|
end
|
63
64
|
|
64
|
-
def load_isodoc(flavor)
|
65
|
+
def load_isodoc(flavor, presxml: false)
|
65
66
|
x = Asciidoctor.load nil, backend: flavor.to_sym
|
67
|
+
if presxml
|
68
|
+
x.converter.presentation_xml_converter(Dummy.new)
|
69
|
+
else
|
66
70
|
x.converter.html_converter(Dummy.new) # to obtain Isodoc class
|
71
|
+
end
|
67
72
|
end
|
73
|
+
|
74
|
+
def isodoc_create(flavor, lang, script, xml, presxml: false)
|
75
|
+
isodoc = Util::load_isodoc(flavor, presxml: presxml)
|
76
|
+
isodoc.i18n_init(lang, script, nil) # read in internationalisation
|
77
|
+
# TODO locale?
|
78
|
+
isodoc.metadata_init(lang, script, nil, isodoc.i18n)
|
79
|
+
isodoc.info(xml, nil)
|
80
|
+
isodoc
|
81
|
+
end
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
@@ -114,6 +114,14 @@ module Metanorma
|
|
114
114
|
fnames = { xml: f.sub(/\.[^.]+$/, ".xml"), f: f,
|
115
115
|
orig_filename: File.expand_path(filename),
|
116
116
|
presentationxml: f.sub(/\.[^.]+$/, ".presentation.xml") }
|
117
|
+
if extensions == %i(presentation)
|
118
|
+
process_ext(:presentation, file, isodoc, fnames, options)
|
119
|
+
else
|
120
|
+
process_exts_queue(fnames, extensions, file, isodoc, options)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def process_exts_queue(fnames, extensions, file, isodoc, options)
|
117
125
|
@queue = ::Metanorma::Util::WorkersPool
|
118
126
|
.new(ENV["METANORMA_PARALLEL"]&.to_i || 3)
|
119
127
|
gather_and_install_fonts(file, options.dup, extensions)
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Metanorma
|
2
2
|
class Compile
|
3
3
|
def relaton_export(isodoc, options)
|
4
|
-
|
5
|
-
|
4
|
+
options[:relaton] or return
|
6
5
|
xml = Nokogiri::XML(isodoc, &:huge)
|
7
6
|
bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
|
8
7
|
# docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
|
@@ -18,8 +17,7 @@ module Metanorma
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def extract(isodoc, dirname, extract_types)
|
21
|
-
|
22
|
-
|
20
|
+
dirname or return
|
23
21
|
extract_types.nil? || extract_types.empty? and
|
24
22
|
extract_types = %i[sourcecode image requirement]
|
25
23
|
FileUtils.rm_rf dirname
|