metanorma 2.0.5 → 2.0.7
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 +32 -12
- data/lib/metanorma/collection/config/manifest.rb +2 -2
- data/lib/metanorma/collection/document/document.rb +12 -10
- data/lib/metanorma/collection/filelookup/filelookup.rb +19 -7
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +46 -20
- data/lib/metanorma/collection/manifest/manifest.rb +13 -8
- data/lib/metanorma/collection/multilingual/multilingual.rb +2 -2
- data/lib/metanorma/collection/renderer/fileparse.rb +98 -97
- data/lib/metanorma/collection/renderer/fileprocess.rb +1 -0
- data/lib/metanorma/collection/renderer/render_word.rb +6 -6
- data/lib/metanorma/collection/renderer/renderer.rb +9 -12
- data/lib/metanorma/collection/renderer/svg.rb +44 -0
- data/lib/metanorma/collection/renderer/utils.rb +22 -6
- data/lib/metanorma/collection/sectionsplit/collection.rb +100 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +73 -101
- data/lib/metanorma/collection/util/util.rb +3 -4
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +3 -3
- data/lib/metanorma/compile/compile.rb +9 -0
- data/lib/metanorma/compile/compile_validate.rb +4 -4
- data/lib/metanorma/compile/extract.rb +2 -4
- data/lib/metanorma/input/asciidoc.rb +11 -30
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +2 -1
- metadata +20 -4
@@ -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,46 +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|
|
130
|
+
add_suffix = doc_suffix && doc_type && doc_type != schema
|
160
131
|
ids.each do |id, file|
|
161
|
-
|
162
|
-
|
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)
|
163
137
|
end
|
164
138
|
end
|
165
139
|
end
|
166
140
|
|
167
|
-
def
|
141
|
+
def update_indirect_refs_prep(docxml)
|
168
142
|
@updated_anchors = {}
|
169
|
-
|
143
|
+
@indirect_keys = {}
|
144
|
+
[Util::gather_bibitems(docxml), Util::gather_bibitemids(docxml),
|
145
|
+
docxml.root["document_suffix"], docxml.root["type"], {}]
|
170
146
|
end
|
171
147
|
|
172
|
-
def indirect_ref_key(schema, id,
|
148
|
+
def indirect_ref_key(schema, id, doc_suffix, doc_type)
|
173
149
|
/^#{schema}_/.match?(id) and return id
|
150
|
+
key = [schema, id, doc_suffix, doc_type].join("::")
|
151
|
+
x = @indirect_keys[key] and return x
|
174
152
|
ret = "#{schema}_#{id}"
|
175
|
-
|
176
|
-
|
177
|
-
|
153
|
+
doc_suffix && doc_type && doc_type != schema and
|
154
|
+
ret = "#{ret}_#{doc_suffix}"
|
155
|
+
@indirect_keys[key] = ret
|
178
156
|
ret
|
179
157
|
end
|
180
158
|
|
181
|
-
def
|
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
|
169
|
+
end
|
170
|
+
|
171
|
+
def indirect_ref_keyx(schema, id, doc_suffix, doc_type)
|
172
|
+
/^#{schema}_/.match?(id) and return id
|
173
|
+
ret = "#{schema}_#{id}"
|
174
|
+
doc_suffix && doc_type && doc_type != schema and
|
175
|
+
ret = "#{ret}_#{doc_suffix}"
|
176
|
+
ret
|
177
|
+
end
|
178
|
+
|
179
|
+
def update_indirect_refs_to_docs1(filec, key, file, bibitems, erefs)
|
182
180
|
erefs[key]&.each do |e|
|
183
181
|
e["citeas"] = file
|
184
|
-
update_indirect_refs_to_docs_anchor(e, file
|
182
|
+
update_indirect_refs_to_docs_anchor(e, file, filec[:url],
|
183
|
+
filec[:parentid])
|
185
184
|
end
|
186
185
|
update_indirect_refs_to_docs_docid(bibitems[key], file)
|
187
186
|
end
|
188
187
|
|
189
|
-
def update_indirect_refs_to_docs_anchor(eref, file)
|
190
|
-
a = eref.at(
|
191
|
-
|
192
|
-
@files.get(file) && p = @files.get(file, :parentid) and
|
193
|
-
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}"
|
194
191
|
existing = a.text
|
195
|
-
anchor = existing
|
196
|
-
|
197
|
-
|
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
|
198
200
|
@updated_anchors[existing] or a.children = anchor
|
199
201
|
@updated_anchors[anchor] = true
|
200
202
|
end
|
@@ -206,37 +208,36 @@ module Metanorma
|
|
206
208
|
"<docidentifier type='metanorma-collection'>#{file}</docidentifier>"
|
207
209
|
end
|
208
210
|
|
209
|
-
#
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
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]
|
221
228
|
end
|
222
229
|
end
|
223
230
|
|
224
|
-
def
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
anchor = suffix_anchor(ref, docid)
|
229
|
-
a = @files.get(docid, :anchors) or return
|
230
|
-
a.inject([]) { |m, (_, x)| m + x.values }
|
231
|
-
.include?(anchor) or return
|
232
|
-
ref.content = anchor
|
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)]
|
233
235
|
end
|
234
236
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
@
|
239
|
-
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)
|
240
241
|
end
|
241
242
|
|
242
243
|
# if there is a crossref to another document, with no anchor, retrieve the
|
@@ -248,7 +249,7 @@ module Metanorma
|
|
248
249
|
ref = ins.at(ns("./locality/referenceFrom"))&.text
|
249
250
|
a = @files.get(docid, :anchors).dig(type, ref) or return
|
250
251
|
ins << "<locality type='anchor'><referenceFrom>#{a.sub(/^_/, '')}" \
|
251
|
-
|
252
|
+
"</referenceFrom></locality>"
|
252
253
|
end
|
253
254
|
end
|
254
255
|
end
|
@@ -85,6 +85,7 @@ module Metanorma
|
|
85
85
|
def gather_internal_refs
|
86
86
|
@files.keys.each_with_object({}) do |i, refs|
|
87
87
|
@files.get(i, :attachment) and next
|
88
|
+
@files.get(i, :sectionsplit) and next
|
88
89
|
file, = @files.targetfile_id(i, read: true)
|
89
90
|
gather_internal_refs1(file, i, refs)
|
90
91
|
end
|
@@ -3,8 +3,8 @@ module Metanorma
|
|
3
3
|
class Renderer
|
4
4
|
def docconv
|
5
5
|
@tempfile_cache ||= []
|
6
|
-
|
7
|
-
x = Asciidoctor.load nil, backend:
|
6
|
+
flavor = @flavor.to_sym
|
7
|
+
x = Asciidoctor.load nil, backend: flavor
|
8
8
|
x.converter.doc_converter(DocOptionsNode.new(@directives, @dirname))
|
9
9
|
end
|
10
10
|
|
@@ -51,8 +51,8 @@ module Metanorma
|
|
51
51
|
doc
|
52
52
|
end
|
53
53
|
|
54
|
-
SECTION_BREAK =
|
55
|
-
.freeze
|
54
|
+
SECTION_BREAK =
|
55
|
+
'<p class="MsoNormal"><br clear="all" class="section"/></p>'.freeze
|
56
56
|
DIV1 = '<div class="WordSection1"> </div>'.freeze
|
57
57
|
DIV2 = '<div class="WordSection2"> </div>'.freeze
|
58
58
|
|
@@ -70,10 +70,10 @@ module Metanorma
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def collection_coverpages(conv, docs)
|
73
|
-
conv.wordintropage and [DIV2, SECTION_BREAK].
|
73
|
+
conv.wordintropage and [DIV2, SECTION_BREAK].reverse_each do |s|
|
74
74
|
docs.unshift(Nokogiri::XML(s).root)
|
75
75
|
end
|
76
|
-
conv.wordcoverpage and [DIV1, SECTION_BREAK].
|
76
|
+
conv.wordcoverpage and [DIV1, SECTION_BREAK].reverse_each do |s|
|
77
77
|
docs.unshift(Nokogiri::XML(s).root)
|
78
78
|
end
|
79
79
|
docs
|
@@ -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
|
@@ -38,9 +39,9 @@ module Metanorma
|
|
38
39
|
@script = collection.bibdata.script.first || "Latn"
|
39
40
|
@locale = @xml.at("//xmlns:bibdata/xmlns:locale")&.text
|
40
41
|
@registry = Metanorma::Registry.instance
|
41
|
-
@
|
42
|
+
@flavor = options[:flavor] || flavor
|
42
43
|
@compile = Compile.new
|
43
|
-
@compile.load_flavor(@
|
44
|
+
@compile.load_flavor(@flavor)
|
44
45
|
|
45
46
|
@isodoc = isodoc_create # output processor for flavour
|
46
47
|
@outdir = dir_name_cleanse(options[:output_folder])
|
@@ -74,6 +75,7 @@ module Metanorma
|
|
74
75
|
|
75
76
|
def flush_files
|
76
77
|
warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
|
78
|
+
warn "\nFiles to delete:\n"
|
77
79
|
warn @files.files_to_delete
|
78
80
|
@files.files_to_delete.each { |f| FileUtils.rm_f(f) }
|
79
81
|
@files_to_delete.each { |f| FileUtils.rm_f(f) }
|
@@ -136,8 +138,8 @@ module Metanorma
|
|
136
138
|
@directives.detect { |d| d.key == "bilingual" } &&
|
137
139
|
options[:format].include?(:html) and
|
138
140
|
Metanorma::Collection::Multilingual.new(
|
139
|
-
{
|
140
|
-
converter_options: PdfOptionsNode.new(
|
141
|
+
{ flavor: flavor.to_sym,
|
142
|
+
converter_options: PdfOptionsNode.new(flavor, @compile_options),
|
141
143
|
outdir: @outdir },
|
142
144
|
).to_html(pres)
|
143
145
|
end
|
@@ -155,14 +157,9 @@ module Metanorma
|
|
155
157
|
out
|
156
158
|
end
|
157
159
|
|
158
|
-
# infer
|
159
|
-
def
|
160
|
-
|
161
|
-
dt = docid.downcase
|
162
|
-
elsif (docid = @xml.at("//bibdata/docidentifier")&.text)
|
163
|
-
dt = docid.sub(/\s.*$/, "").lowercase
|
164
|
-
else return "standoc"
|
165
|
-
end
|
160
|
+
# TODO: infer flavor from publisher when available
|
161
|
+
def flavor
|
162
|
+
dt = @xml.at("//bibdata/ext/flavor")&.text or return "standoc"
|
166
163
|
@registry.alias(dt.to_sym)&.to_s || dt
|
167
164
|
end
|
168
165
|
|
@@ -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
|
@@ -111,9 +111,9 @@ module Metanorma
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def pdfconv
|
114
|
-
|
115
|
-
x = Asciidoctor.load nil, backend:
|
116
|
-
x.converter.pdf_converter(PdfOptionsNode.new(
|
114
|
+
flavor = @flavor.to_sym
|
115
|
+
x = Asciidoctor.load nil, backend: flavor
|
116
|
+
x.converter.pdf_converter(PdfOptionsNode.new(flavor,
|
117
117
|
@compile_options))
|
118
118
|
end
|
119
119
|
|
@@ -153,8 +153,8 @@ module Metanorma
|
|
153
153
|
end
|
154
154
|
|
155
155
|
class PdfOptionsNode
|
156
|
-
def initialize(
|
157
|
-
p = Metanorma::Registry.instance.find_processor(
|
156
|
+
def initialize(flavor, options)
|
157
|
+
p = Metanorma::Registry.instance.find_processor(flavor)
|
158
158
|
if ::Metanorma::Util::FontistHelper.has_custom_fonts?(p, options, {})
|
159
159
|
@fonts_manifest =
|
160
160
|
::Metanorma::Util::FontistHelper.location_manifest(p, options)
|
@@ -169,7 +169,7 @@ module Metanorma
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def isodoc_create
|
172
|
-
isodoc = Util::load_isodoc(@
|
172
|
+
isodoc = Util::load_isodoc(@flavor)
|
173
173
|
isodoc.i18n_init(@lang, @script, @locale) # read in internationalisation
|
174
174
|
isodoc.metadata_init(@lang, @script, @locale, isodoc.i18n)
|
175
175
|
isodoc.info(@xml, nil)
|
@@ -203,6 +203,22 @@ module Metanorma
|
|
203
203
|
end.doc.root.to_html
|
204
204
|
end
|
205
205
|
|
206
|
+
def eref2link(docxml)
|
207
|
+
isodoc = IsoDoc::PresentationXMLConvert.new({})
|
208
|
+
isodoc.bibitem_lookup(docxml)
|
209
|
+
isodoc.eref2link(docxml)
|
210
|
+
end
|
211
|
+
|
212
|
+
def error_anchor(erefs, docid)
|
213
|
+
erefs.each do |e|
|
214
|
+
msg = "<strong>** Unresolved reference to document #{docid} " \
|
215
|
+
"from eref</strong>"
|
216
|
+
e << msg
|
217
|
+
strip_eref(e)
|
218
|
+
@log&.add("Cross-References", e, msg)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
206
222
|
def ns(xpath)
|
207
223
|
@isodoc.ns(xpath)
|
208
224
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Metanorma
|
2
|
+
class Collection
|
3
|
+
class Sectionsplit
|
4
|
+
def build_collection
|
5
|
+
collection_setup(@base, @dir)
|
6
|
+
files = sectionsplit
|
7
|
+
input_xml = Nokogiri::XML(File.read(@input_filename,
|
8
|
+
encoding: "UTF-8"), &:huge)
|
9
|
+
collection_manifest(@base, files, input_xml, @xml, @dir).render(
|
10
|
+
{ format: %i(html), output_folder: "#{@output_filename}_collection",
|
11
|
+
coverpage: File.join(@dir, "cover.html") }.merge(@compile_opts),
|
12
|
+
)
|
13
|
+
section_split_attachments(out: "#{@output_filename}_collection")
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_setup(filename, dir)
|
17
|
+
FileUtils.mkdir_p "#{filename}_collection" if filename
|
18
|
+
FileUtils.mkdir_p dir
|
19
|
+
File.open(File.join(dir, "cover.html"), "w:UTF-8") do |f|
|
20
|
+
f.write(coll_cover)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def coll_cover
|
25
|
+
<<~COVER
|
26
|
+
<html><head><meta charset="UTF-8"/></head><body>
|
27
|
+
<h1>{{ doctitle }}</h1>
|
28
|
+
<h2>{{ docnumber }}</h2>
|
29
|
+
<nav>{{ navigation }}</nav>
|
30
|
+
</body></html>
|
31
|
+
COVER
|
32
|
+
end
|
33
|
+
|
34
|
+
def collection_manifest(filename, files, origxml, _presxml, dir)
|
35
|
+
File.open(File.join(dir, "#{filename}.html.yaml"), "w:UTF-8") do |f|
|
36
|
+
f.write(collectionyaml(files, origxml))
|
37
|
+
end
|
38
|
+
Metanorma::Collection.parse File.join(dir, "#{filename}.html.yaml")
|
39
|
+
end
|
40
|
+
|
41
|
+
def collectionyaml(files, xml)
|
42
|
+
ret = {
|
43
|
+
directives: ["presentation-xml", "bare-after-first"],
|
44
|
+
bibdata: {
|
45
|
+
title: {
|
46
|
+
type: "title-main", language: @lang,
|
47
|
+
content: xml.at(ns("//bibdata/title")).text
|
48
|
+
},
|
49
|
+
type: "collection",
|
50
|
+
docid: {
|
51
|
+
type: xml.at(ns("//bibdata/docidentifier/@type")).text,
|
52
|
+
id: xml.at(ns("//bibdata/docidentifier")).text,
|
53
|
+
},
|
54
|
+
},
|
55
|
+
manifest: {
|
56
|
+
level: "collection", title: "Collection",
|
57
|
+
docref: files.sort_by { |f| f[:order] }.each.map do |f|
|
58
|
+
{ fileref: f[:url], identifier: f[:title] }
|
59
|
+
end
|
60
|
+
},
|
61
|
+
}
|
62
|
+
::Metanorma::Util::recursive_string_keys(ret).to_yaml
|
63
|
+
end
|
64
|
+
|
65
|
+
def att_dir(file)
|
66
|
+
"_#{File.basename(file, '.*')}_attachments"
|
67
|
+
end
|
68
|
+
|
69
|
+
def section_split_attachments(out: nil)
|
70
|
+
attachments = att_dir(@tmp_filename)
|
71
|
+
File.directory?(attachments) or return
|
72
|
+
dir = out || File.dirname(@input_filename)
|
73
|
+
ret = File.join(dir, att_dir(@output_filename))
|
74
|
+
FileUtils.rm_rf ret
|
75
|
+
FileUtils.mv attachments, ret
|
76
|
+
File.basename(ret)
|
77
|
+
end
|
78
|
+
|
79
|
+
def section_split_cover(col, ident, one_doc_coll)
|
80
|
+
dir = File.dirname(col.file)
|
81
|
+
collection_setup(nil, dir)
|
82
|
+
r = ::Metanorma::Collection::Renderer
|
83
|
+
.new(col, dir, output_folder: "#{ident}_collection",
|
84
|
+
format: %i(html),
|
85
|
+
coverpage: File.join(dir, "cover.html"))
|
86
|
+
r.coverpage
|
87
|
+
section_split_cover1(ident, r, dir, one_doc_coll)
|
88
|
+
end
|
89
|
+
|
90
|
+
def section_split_cover1(ident, renderer, dir, _one_doc_coll)
|
91
|
+
filename = File.basename("#{ident}_index.html")
|
92
|
+
# ident can be a directory with YAML indirection
|
93
|
+
dest = File.join(dir, filename)
|
94
|
+
FileUtils.mv File.join(renderer.outdir, "index.html"), dest
|
95
|
+
FileUtils.rm_rf renderer.outdir
|
96
|
+
filename
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|