metanorma 2.1.8 → 2.1.9
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/document/document.rb +2 -0
- data/lib/metanorma/collection/filelookup/filelookup.rb +2 -2
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +3 -2
- data/lib/metanorma/collection/renderer/fileparse.rb +12 -39
- data/lib/metanorma/collection/renderer/renderer.rb +3 -1
- data/lib/metanorma/collection/renderer/utils.rb +3 -9
- data/lib/metanorma/collection/sectionsplit/collection.rb +1 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +84 -49
- data/lib/metanorma/collection/util/util.rb +24 -11
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +2 -3
- data/lib/metanorma/version.rb +1 -1
- 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: b6f662b6213511d30fb8f16f0bc51bb4209959a4f17ac385d81bdd02f1135088
|
4
|
+
data.tar.gz: 4021db66267ad5cbc213058d7b2252d6a2f9572e6efd686df2f84ba1f1965cbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ba138f8fd28e6e4ee1d0fcc786f49b17b816483c39a6d2dda89643b9611bed93068ac8f3e700ba199a01f0f0446ce2c46be97d4a7e705a67df04e6b1d898432
|
7
|
+
data.tar.gz: 45a50ed06452ff4e598bc95ce07412eeca39b33afe7158a48f17080381417cda79ba4ed4286901652a6e4f6311d0ad70e083388aba4e3150c22f543f56825dde
|
@@ -18,6 +18,7 @@ module Metanorma
|
|
18
18
|
@parent = parent
|
19
19
|
@xml = parent.xml
|
20
20
|
@isodoc = parent.isodoc
|
21
|
+
@isodoc_presxml = parent.isodoc_presxml
|
21
22
|
@path = path
|
22
23
|
@compile = parent.compile
|
23
24
|
@documents = parent.documents
|
@@ -131,7 +132,7 @@ module Metanorma
|
|
131
132
|
|
132
133
|
def add_document_suffix(identifier, doc)
|
133
134
|
document_suffix = Metanorma::Utils::to_ncname(identifier)
|
134
|
-
|
135
|
+
Util::anchor_id_attributes.each do |(tag_name, attr_name)|
|
135
136
|
Util::add_suffix_to_attrs(doc, document_suffix, tag_name, attr_name,
|
136
137
|
@isodoc)
|
137
138
|
end
|
@@ -230,7 +231,6 @@ module Metanorma
|
|
230
231
|
ret = {}
|
231
232
|
xml.traverse do |x|
|
232
233
|
x.text? and next
|
233
|
-
/^semantic__/.match?(x.name) and next
|
234
234
|
x["id"] and ret[x["id"]] = true
|
235
235
|
end
|
236
236
|
ret
|
@@ -110,8 +110,9 @@ module Metanorma
|
|
110
110
|
@sectionsplit = ::Metanorma::Collection::Sectionsplit
|
111
111
|
.new(input: file, base: @files[ident][:out_path],
|
112
112
|
dir: File.dirname(file), output: @files[ident][:out_path],
|
113
|
-
compile_opts: @parent.compile_options,
|
114
|
-
fileslookup: self,
|
113
|
+
compile_opts: @parent.compile_options, ident: ident,
|
114
|
+
fileslookup: self, isodoc: @isodoc,
|
115
|
+
isodoc_presxml: @isodoc_presxml,
|
115
116
|
document_suffix: @files[ident][:document_suffix])
|
116
117
|
coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
|
117
118
|
xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
|
@@ -16,8 +16,6 @@ module Metanorma
|
|
16
16
|
# @return [String] XML content
|
17
17
|
def update_xrefs(file, docid, internal_refs)
|
18
18
|
xml, sso = update_xrefs_prep(file, docid)
|
19
|
-
#require "debug"; binding.b if /This document is also unrelated/.match?(xml.to_xml)
|
20
|
-
#warn (/fmt-title/.match?(xml.to_xml) ? "*** PRESENTATION" : "*** SEMANTIC")
|
21
19
|
@nested || sso or
|
22
20
|
Metanorma::Collection::XrefProcess::xref_process(xml, xml, nil, docid,
|
23
21
|
@isodoc, sso)
|
@@ -26,7 +24,7 @@ module Metanorma
|
|
26
24
|
@files.add_document_suffix(docid, xml)
|
27
25
|
@nested or update_sectionsplit_refs_to_docs(xml, internal_refs, sso)
|
28
26
|
update_direct_refs_to_docs(xml, docid, sso)
|
29
|
-
hide_refs(xml)
|
27
|
+
::Metanorma::Collection::Util::hide_refs(xml)
|
30
28
|
sso and eref2link(xml, sso)
|
31
29
|
@nested or svgmap_resolve(xml, docid, sso)
|
32
30
|
xml.to_xml
|
@@ -109,7 +107,6 @@ module Metanorma
|
|
109
107
|
else no_anchor[k] << e end
|
110
108
|
end
|
111
109
|
end
|
112
|
-
#require "debug"; binding.b
|
113
110
|
[erefs, no_anchor, anchors, Util::gather_bibitemids(docxml, presxml)]
|
114
111
|
end
|
115
112
|
|
@@ -128,8 +125,9 @@ module Metanorma
|
|
128
125
|
|
129
126
|
# Resolve erefs to a container of ids in another doc,
|
130
127
|
# to an anchor eref (direct link)
|
131
|
-
def update_indirect_refs_to_docs(docxml,
|
132
|
-
bib, erefs, doc_suffix, doc_type, f = update_indirect_refs_prep(docxml,
|
128
|
+
def update_indirect_refs_to_docs(docxml, _docid, internal_refs, presxml)
|
129
|
+
bib, erefs, doc_suffix, doc_type, f = update_indirect_refs_prep(docxml,
|
130
|
+
presxml)
|
133
131
|
internal_refs.each do |schema, ids|
|
134
132
|
add_suffix = doc_suffix && doc_type && doc_type != schema
|
135
133
|
ids.each do |id, file|
|
@@ -149,37 +147,15 @@ module Metanorma
|
|
149
147
|
docxml.root["document_suffix"], docxml.root["type"], {}]
|
150
148
|
end
|
151
149
|
|
152
|
-
# KILL
|
153
|
-
def indirect_ref_key(schema, id, doc_suffix, doc_type)
|
154
|
-
/^#{schema}_/.match?(id) and return id
|
155
|
-
key = [schema, id, doc_suffix, doc_type].join("::")
|
156
|
-
x = @indirect_keys[key] and return x
|
157
|
-
ret = "#{schema}_#{id}"
|
158
|
-
doc_suffix && doc_type && doc_type != schema and
|
159
|
-
ret = "#{ret}_#{doc_suffix}"
|
160
|
-
@indirect_keys[key] = ret
|
161
|
-
ret
|
162
|
-
end
|
163
|
-
|
164
150
|
def indirect_ref_key(schema, id, doc_suffix, add_suffix)
|
165
151
|
/^#{schema}_/.match?(id) and return id
|
166
|
-
#key = "#{schema}_#{id}"
|
167
152
|
x = @indirect_keys.dig(schema, id) and return x
|
168
153
|
@indirect_keys[schema] ||= {}
|
169
154
|
@indirect_keys[schema][id] = if add_suffix
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
# KILL
|
177
|
-
def indirect_ref_keyx(schema, id, doc_suffix, doc_type)
|
178
|
-
/^#{schema}_/.match?(id) and return id
|
179
|
-
ret = "#{schema}_#{id}"
|
180
|
-
doc_suffix && doc_type && doc_type != schema and
|
181
|
-
ret = "#{ret}_#{doc_suffix}"
|
182
|
-
ret
|
155
|
+
"#{schema}_#{id}_#{doc_suffix}"
|
156
|
+
else
|
157
|
+
"#{schema}_#{id}"
|
158
|
+
end
|
183
159
|
end
|
184
160
|
|
185
161
|
def update_indirect_refs_to_docs1(filec, key, file, bibitems, erefs)
|
@@ -196,13 +172,10 @@ module Metanorma
|
|
196
172
|
parentid and file = "#{parentid}_#{file}"
|
197
173
|
existing = a.text
|
198
174
|
anchor = if url then existing
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
@indirect_keys[existing] ||= {}
|
204
|
-
@indirect_keys[existing][file] ||= Metanorma::Utils::to_ncname("#{existing}_#{file}")
|
205
|
-
end
|
175
|
+
else
|
176
|
+
@indirect_keys[existing] ||= {}
|
177
|
+
@indirect_keys[existing][file] ||= Metanorma::Utils::to_ncname("#{existing}_#{file}")
|
178
|
+
end
|
206
179
|
@updated_anchors[existing] or a.children = anchor
|
207
180
|
@updated_anchors[anchor] = true
|
208
181
|
end
|
@@ -15,7 +15,7 @@ module Metanorma
|
|
15
15
|
class Renderer
|
16
16
|
FORMATS = %i[html xml doc pdf].freeze
|
17
17
|
|
18
|
-
attr_accessor :isodoc, :nested
|
18
|
+
attr_accessor :isodoc, :isodoc_presxml, :nested
|
19
19
|
attr_reader :xml, :compile, :compile_options, :documents, :outdir,
|
20
20
|
:manifest
|
21
21
|
|
@@ -45,6 +45,8 @@ module Metanorma
|
|
45
45
|
|
46
46
|
# output processor for flavour
|
47
47
|
@isodoc = Util::isodoc_create(@flavor, @lang, @script, @xml)
|
48
|
+
@isodoc_presxml = Util::isodoc_create(@flavor, @lang, @script, @xml,
|
49
|
+
presxml: true)
|
48
50
|
@outdir = dir_name_cleanse(options[:output_folder])
|
49
51
|
@coverpage = options[:coverpage] || collection.coverpage
|
50
52
|
@format = ::Metanorma::Util.sort_extensions_execution(options[:format])
|
@@ -17,6 +17,7 @@ module Metanorma
|
|
17
17
|
newbib["hidden"] = "true"
|
18
18
|
newbib&.at("./*[local-name() = 'ext']")&.remove
|
19
19
|
newbib["id"] = bib["id"]
|
20
|
+
bib["anchor"] and newbib["anchor"] = bib["anchor"]
|
20
21
|
newbib
|
21
22
|
end
|
22
23
|
|
@@ -37,17 +38,10 @@ module Metanorma
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
def hide_refs(docxml)
|
41
|
-
docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or " \
|
42
|
-
"@hidden = 'false'])]")).each do |f|
|
43
|
-
f["hidden"] = "true"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
41
|
def new_hidden_ref(xmldoc)
|
48
42
|
ins = xmldoc.at(ns("bibliography")) or
|
49
43
|
xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
|
50
|
-
ins.at(ns("./
|
44
|
+
ins.at(ns("./references[@hidden = 'true']")) or
|
51
45
|
ins.add_child("<references hidden='true' normative='false'/>").first
|
52
46
|
end
|
53
47
|
|
@@ -81,7 +75,7 @@ module Metanorma
|
|
81
75
|
refs.each do |k, v|
|
82
76
|
url = @files.url(v, {})
|
83
77
|
ins << <<~XML
|
84
|
-
<bibitem id="#{k}">#{docid_xml(v)}<uri type='citation'>#{url}</uri></bibitem>
|
78
|
+
<bibitem id="#{k}" anchor="#{k}">#{docid_xml(v)}<uri type='citation'>#{url}</uri></bibitem>
|
85
79
|
XML
|
86
80
|
end
|
87
81
|
end
|
@@ -19,6 +19,7 @@ module Metanorma
|
|
19
19
|
@fileslookup = opts[:fileslookup]
|
20
20
|
@ident = opts[:ident]
|
21
21
|
@isodoc = opts[:isodoc]
|
22
|
+
@isodoc_presxml = opts[:isodoc_presxml]
|
22
23
|
@document_suffix = opts[:document_suffix]
|
23
24
|
end
|
24
25
|
|
@@ -32,18 +33,19 @@ module Metanorma
|
|
32
33
|
["//bibliography/*[not(@hidden = 'true')]", "bibliography"],
|
33
34
|
["//indexsect", nil], ["//colophon", nil]].freeze
|
34
35
|
|
35
|
-
# Input XML is Semantic
|
36
|
+
# Input XML is Semantic XML
|
36
37
|
def sectionsplit
|
37
38
|
xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
|
38
39
|
@key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
|
39
40
|
empty = empty_doc(xml)
|
40
41
|
empty1 = empty_attachments(empty)
|
41
42
|
@mutex = Mutex.new
|
42
|
-
|
43
|
+
# @pool = Concurrent::FixedThreadPool.new(4)
|
43
44
|
@pool = Concurrent::FixedThreadPool.new(1)
|
44
45
|
sectionsplit1(xml, empty, empty1, 0)
|
45
46
|
end
|
46
47
|
|
48
|
+
# xml is Presentation XML
|
47
49
|
def sectionsplit1(xml, empty, empty1, idx)
|
48
50
|
ret = SPLITSECTIONS.each_with_object([]) do |n, m|
|
49
51
|
conflate_floatingtitles(xml.xpath(ns(n[0]))).each do |s|
|
@@ -59,12 +61,14 @@ module Metanorma
|
|
59
61
|
|
60
62
|
def sectionsplit2(xml, empty, chunks, parentnode, opt)
|
61
63
|
@pool.post do
|
64
|
+
warn "#{@base}.#{opt[:idx]}"
|
62
65
|
a = sectionfile(xml, empty, "#{@base}.#{opt[:idx]}", chunks,
|
63
66
|
parentnode)
|
64
67
|
@mutex.synchronize { opt[:acc] << a }
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
71
|
+
# TODO move to metanorma-utils
|
68
72
|
def block?(node)
|
69
73
|
%w(p table formula admonition ol ul dl figure quote sourcecode example
|
70
74
|
pre note pagebreak hr bookmark requirement recommendation permission
|
@@ -86,7 +90,6 @@ module Metanorma
|
|
86
90
|
xml, type = sectionsplit_preprocess_semxml(file, filename)
|
87
91
|
flags = { format: :asciidoc, extension_keys: [:presentation],
|
88
92
|
type: type }.merge(@compile_opts)
|
89
|
-
#require "debug"; binding.b
|
90
93
|
Compile.new.compile(xml, flags)
|
91
94
|
f = File.open(xml.sub(/\.xml$/, ".presentation.xml"), encoding: "utf-8")
|
92
95
|
r = Nokogiri::XML(f, &:huge)
|
@@ -109,7 +112,6 @@ module Metanorma
|
|
109
112
|
if c = @fileslookup&.parent
|
110
113
|
n = c.nested
|
111
114
|
c.nested = true # so unresolved erefs are not deleted
|
112
|
-
#require "debug"; binding.b
|
113
115
|
c.update_xrefs(xml, @ident, {})
|
114
116
|
c.nested = n
|
115
117
|
xml.xpath("//xmlns:svgmap").each { |x| x.name = "svgmap1" }
|
@@ -125,35 +127,19 @@ module Metanorma
|
|
125
127
|
outname
|
126
128
|
end
|
127
129
|
|
128
|
-
def emptydoc(xml, ordinal)
|
129
|
-
out = xml.dup
|
130
|
-
out.xpath(
|
131
|
-
ns("//preface | //sections | //annex | //bibliography/clause | " \
|
132
|
-
"//bibliography/references[not(@hidden = 'true')] | " \
|
133
|
-
"//indexsect | //colophon"),
|
134
|
-
).each(&:remove)
|
135
|
-
ordinal.zero? or out.xpath(ns("//metanorma-ext//attachment | " \
|
136
|
-
"//semantic__metanorma-ext//semantic__attachment"))
|
137
|
-
.each(&:remove) # keep only one copy of attachments
|
138
|
-
out
|
139
|
-
end
|
140
|
-
|
141
130
|
def empty_doc(xml)
|
142
131
|
out = xml.dup
|
143
132
|
out.xpath(
|
144
|
-
ns("//preface | //sections | //annex |
|
145
|
-
|
146
|
-
|
133
|
+
ns("//preface | //sections | //annex | " \
|
134
|
+
"//references/bibitem[not(@hidden = 'true')] | " \
|
135
|
+
"//indexsect | //colophon"),
|
147
136
|
).each(&:remove)
|
137
|
+
::Metanorma::Collection::Util::hide_refs(out)
|
148
138
|
out
|
149
139
|
end
|
150
140
|
|
151
141
|
def empty_attachments(xml)
|
152
|
-
|
153
|
-
out.xpath(ns("//metanorma-ext//attachment | " \
|
154
|
-
"//semantic__metanorma-ext//semantic__attachment"))
|
155
|
-
.each(&:remove) # keep only one copy of attachments
|
156
|
-
out
|
142
|
+
xml.dup
|
157
143
|
end
|
158
144
|
|
159
145
|
def sectionfile(fulldoc, xml, file, chunks, parentnode)
|
@@ -164,11 +150,10 @@ module Metanorma
|
|
164
150
|
|
165
151
|
def create_sectionfile(xml, out, file, chunks, parentnode)
|
166
152
|
ins = out.at(ns("//metanorma-extension")) || out.at(ns("//bibdata"))
|
167
|
-
#require "debug"; binding.b
|
168
153
|
sectionfile_insert(ins, chunks, parentnode)
|
154
|
+
sectionfile_fn_filter(sectionfile_review_filter(out))
|
169
155
|
Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
|
170
156
|
@ident, @isodoc, true)
|
171
|
-
#truncate_semxml(out, chunks)
|
172
157
|
outname = "#{file}.xml"
|
173
158
|
File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
|
174
159
|
f.write(out)
|
@@ -176,36 +161,86 @@ module Metanorma
|
|
176
161
|
outname
|
177
162
|
end
|
178
163
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
164
|
+
def sectionfile_insert(ins, chunks, parentnode)
|
165
|
+
if parentnode
|
166
|
+
ins.next = "<#{parentnode}/>"
|
167
|
+
chunks.each { |c| ins.next.add_child(c.dup) }
|
168
|
+
else chunks.each { |c| ins.next = c.dup }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def sectionfile_fn_filter(xml)
|
173
|
+
ids = sectionfile_fn_filter_prep(xml)
|
174
|
+
xml.root.xpath(ns("./fmt-footnote-container/fmt-fn-body")).each do |f|
|
175
|
+
ids.has_key?(f["id"]) or f.remove
|
176
|
+
end
|
177
|
+
seen = {}
|
178
|
+
xml.root.xpath(ns("/fmt-footnote-container/fmt-fn-body"))
|
179
|
+
.each_with_index do |fnbody, i|
|
180
|
+
sectionfile_fn_filter_renumber(fnbody, i, ids, seen)
|
186
181
|
end
|
182
|
+
xml
|
183
|
+
end
|
184
|
+
|
185
|
+
# map fmt-fn-body/@id = fn/@target to fn
|
186
|
+
def sectionfile_fn_filter_prep(xml)
|
187
|
+
xml.xpath(ns("//fn")).each_with_object({}) do |f, m|
|
188
|
+
m[f["target"]] ||= []
|
189
|
+
m[f["target"]] << f
|
187
190
|
end
|
188
191
|
end
|
189
192
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
193
|
+
FN_CAPTIONS = ".//fmt-fn-label/span[@class = 'fmt-caption-label']".freeze
|
194
|
+
|
195
|
+
def sectionfile_fn_filter_renumber(fnbody, idx, ids, seen)
|
196
|
+
sectionfile_fn_filter_fn_renumber(fnbody, idx, ids, seen)
|
197
|
+
sectionfile_fn_filter_fnbody_renumber(fnbody, idx, ids)
|
198
|
+
end
|
199
|
+
|
200
|
+
def sectionfile_fn_filter_fn_renumber(fnbody, idx, ids, seen)
|
201
|
+
ids[fnbody["id"]].each do |f|
|
202
|
+
@isodoc_presxml.renumber_document_footnote(f, idx, seen)
|
203
|
+
fnlabel = f.at(ns(FN_CAPTIONS)) and
|
204
|
+
fnlabel.children = @isodoc_presxml.fn_ref_label(f)
|
194
205
|
end
|
195
206
|
end
|
196
207
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
nodes.each_value(&:remove)
|
208
|
+
def sectionfile_fn_filter_fnbody_renumber(fnbody, _idx, ids)
|
209
|
+
fnlabel = fnbody.at(ns(FN_CAPTIONS)) or return
|
210
|
+
fnbody["reference"] = ids[fnbody["id"]].first["reference"]
|
211
|
+
fnlabel.children = @isodoc_presxml.fn_body_label(fnbody)
|
202
212
|
end
|
203
213
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
214
|
+
# map fmt-review-body/@id = fmt-review-{start/end}/@target
|
215
|
+
# to fmt-review-{stary/end}
|
216
|
+
def sectionfile_review_filter_prep(xml)
|
217
|
+
xml.xpath(ns("//fmt-review-start | //fmt-review-end"))
|
218
|
+
.each_with_object({}) do |f, m|
|
219
|
+
m[f["target"]] ||= []
|
220
|
+
m[f["target"]] << f
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def sectionfile_review_filter(xml)
|
225
|
+
ids = sectionfile_review_filter_prep(xml)
|
226
|
+
xml.root.xpath(ns("./review-container/fmt-review-body")).each do |f|
|
227
|
+
ids.has_key?(f["id"]) or f.remove
|
228
|
+
end
|
229
|
+
xml.root.xpath(ns("./review-container/fmt-review-body"))
|
230
|
+
.each_with_index do |fnbody, i|
|
231
|
+
sectionfile_review_filter_renumber(fnbody, i, ids)
|
232
|
+
end
|
233
|
+
xml
|
234
|
+
end
|
235
|
+
|
236
|
+
def sectionfile_review_filter_renumber(fnbody, _idx, ids)
|
237
|
+
ids[fnbody["id"]].each do |f|
|
238
|
+
case f.name
|
239
|
+
when "fmt-review-start"
|
240
|
+
f.children = @isodoc_presxml.comment_bookmark_start_label(f)
|
241
|
+
when "fmt-review-end"
|
242
|
+
f.children = @isodoc_presxml.comment_bookmark_end_label(f)
|
243
|
+
end
|
209
244
|
end
|
210
245
|
end
|
211
246
|
|
@@ -214,7 +249,7 @@ module Metanorma
|
|
214
249
|
t = title.dup
|
215
250
|
t.xpath(ns(".//tab | .//br")).each { |x| x.replace(" ") }
|
216
251
|
t.xpath(ns(".//bookmark")).each(&:remove)
|
217
|
-
t.xpath(
|
252
|
+
t.xpath(".//text()").map(&:text).join
|
218
253
|
end
|
219
254
|
end
|
220
255
|
end
|
@@ -2,6 +2,11 @@ module Metanorma
|
|
2
2
|
class Collection
|
3
3
|
module Util
|
4
4
|
class << self
|
5
|
+
def anchor_id_attributes
|
6
|
+
Metanorma::Utils::anchor_attributes(presxml: true) +
|
7
|
+
[%w(* id), %w(* anchor), %w(link bibitemid), %w(fmt-link bibitemid)]
|
8
|
+
end
|
9
|
+
|
5
10
|
def gather_bibitems(xml)
|
6
11
|
xml.xpath("//xmlns:bibitem[@id]").each_with_object({}) do |b, m|
|
7
12
|
if m[b["id"]]
|
@@ -16,7 +21,6 @@ module Metanorma
|
|
16
21
|
|
17
22
|
def gather_bibitemids(xml, presxml)
|
18
23
|
xml.xpath("//*[@bibitemid]").each_with_object({}) do |e, m|
|
19
|
-
#/^semantic__/.match?(e.name) and next
|
20
24
|
presxml && %w(xref eref link).include?(e.name) and next
|
21
25
|
m[e["bibitemid"]] ||= []
|
22
26
|
m[e["bibitemid"]] << e
|
@@ -25,7 +29,6 @@ module Metanorma
|
|
25
29
|
|
26
30
|
def gather_citeases(xml, presxml)
|
27
31
|
xml.xpath("//*[@citeas]").each_with_object({}) do |e, m|
|
28
|
-
#/^semantic__/.match?(e.name) and next
|
29
32
|
presxml && %w(xref eref link).include?(e.name) and next
|
30
33
|
k = key(e["citeas"])
|
31
34
|
m[k] ||= []
|
@@ -36,6 +39,8 @@ module Metanorma
|
|
36
39
|
def add_suffix_to_attrs(doc, suffix, tag_name, attr_name, isodoc)
|
37
40
|
(suffix.nil? || suffix.empty?) and return
|
38
41
|
doc.xpath(isodoc.ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
|
42
|
+
#warn "#{tag_name} : #{elem.name}" if attr_name == "bibitemid"
|
43
|
+
#require 'debug'; binding.b if attr_name == "bibitemid" && #!%w(eref fmt-eref link fmt-link).include?(elem.name)
|
39
44
|
a = elem.attributes[attr_name].value
|
40
45
|
/_#{suffix}$/.match?(a) or
|
41
46
|
elem.attributes[attr_name].value = "#{a}_#{suffix}"
|
@@ -55,6 +60,14 @@ module Metanorma
|
|
55
60
|
p.absolute? ? path : File.join(dir, path)
|
56
61
|
end
|
57
62
|
|
63
|
+
def hide_refs(docxml)
|
64
|
+
p = "//xmlns:references[xmlns:bibitem]"\
|
65
|
+
"[not(./xmlns:bibitem[not(@hidden) or @hidden = 'false'])]"
|
66
|
+
docxml.xpath(p).each do |f|
|
67
|
+
f["hidden"] = "true"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
58
71
|
def key(ident)
|
59
72
|
@c ||= HTMLEntities.new
|
60
73
|
@c.decode(ident).gsub(/(\p{Zs})+/, " ")
|
@@ -67,20 +80,20 @@ module Metanorma
|
|
67
80
|
def load_isodoc(flavor, presxml: false)
|
68
81
|
x = Asciidoctor.load nil, backend: flavor.to_sym
|
69
82
|
if presxml
|
70
|
-
|
83
|
+
x.converter.presentation_xml_converter(Dummy.new)
|
71
84
|
else
|
72
|
-
|
85
|
+
x.converter.html_converter(Dummy.new) # to obtain Isodoc class
|
73
86
|
end
|
74
87
|
end
|
75
88
|
|
76
89
|
def isodoc_create(flavor, lang, script, xml, presxml: false)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
90
|
+
isodoc = Util::load_isodoc(flavor, presxml: presxml)
|
91
|
+
isodoc.i18n_init(lang, script, nil) # read in internationalisation
|
92
|
+
# TODO locale?
|
93
|
+
isodoc.metadata_init(lang, script, nil, isodoc.i18n)
|
94
|
+
isodoc.info(xml, nil)
|
95
|
+
isodoc
|
96
|
+
end
|
84
97
|
end
|
85
98
|
end
|
86
99
|
end
|
@@ -10,8 +10,7 @@ module Metanorma
|
|
10
10
|
@isodoc = isodoc
|
11
11
|
key = (0...8).map { rand(65..90).chr }.join # random string
|
12
12
|
xml.root["type"] = key
|
13
|
-
|
14
|
-
.each do |(tag_name, attr_name)|
|
13
|
+
Util::anchor_id_attributes.each do |(tag_name, attr_name)|
|
15
14
|
#tag_name == "xref" and tag_name = "fmt-xref"
|
16
15
|
::Metanorma::Collection::Util::add_suffix_to_attrs(
|
17
16
|
xml, xml.root["document_suffix"], tag_name, attr_name, isodoc
|
@@ -225,7 +224,7 @@ module Metanorma
|
|
225
224
|
|
226
225
|
def new_indirect_bibitem(ident, prefix)
|
227
226
|
<<~BIBENTRY
|
228
|
-
<bibitem id="#{ident}" type="internal">
|
227
|
+
<bibitem id="#{ident}" anchor="#{ident}" type="internal">
|
229
228
|
<docidentifier type="repository">#{ident.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
|
230
229
|
</bibitem>
|
231
230
|
BIBENTRY
|
data/lib/metanorma/version.rb
CHANGED
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.1.
|
4
|
+
version: 2.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|