metanorma 2.1.4 → 2.2.0
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/.rubocop.yml +4 -1
- data/lib/metanorma/collection/collection.rb +10 -4
- data/lib/metanorma/collection/config/config.rb +21 -0
- data/lib/metanorma/collection/config/manifest.rb +4 -1
- data/lib/metanorma/collection/document/document.rb +2 -0
- data/lib/metanorma/collection/filelookup/filelookup.rb +15 -6
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +4 -3
- data/lib/metanorma/collection/manifest/manifest.rb +7 -11
- data/lib/metanorma/collection/renderer/fileparse.rb +12 -39
- data/lib/metanorma/collection/renderer/fileprocess.rb +26 -10
- data/lib/metanorma/collection/renderer/navigation.rb +1 -1
- data/lib/metanorma/collection/renderer/renderer.rb +14 -1
- data/lib/metanorma/collection/renderer/utils.rb +8 -10
- 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/compile/assets/icc-boilerplate.adoc +41 -0
- data/lib/metanorma/compile/compile.rb +148 -172
- data/lib/metanorma/compile/compile_options.rb +108 -82
- data/lib/metanorma/compile/extract.rb +76 -56
- data/lib/metanorma/compile/flavor.rb +54 -0
- data/lib/metanorma/compile/output_filename.rb +75 -0
- data/lib/metanorma/compile/output_filename_config.rb +27 -0
- data/lib/metanorma/compile/relaton_drop.rb +56 -0
- data/lib/metanorma/compile/render.rb +178 -0
- data/lib/metanorma/compile/validator.rb +26 -0
- data/lib/metanorma/compile/writeable.rb +12 -0
- data/lib/metanorma/input/asciidoc.rb +13 -6
- data/lib/metanorma/registry/registry.rb +11 -8
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +2 -1
- metadata +24 -3
- data/lib/metanorma/compile/compile_validate.rb +0 -68
|
@@ -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
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
== copyright-statement
|
|
2
|
+
=== Copyright notice
|
|
3
|
+
|
|
4
|
+
Copyright © 1994-{{docyear}} International Color Consortium®
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
the Specification and associated documentation files (the “Specification”) to
|
|
8
|
+
deal in the Specification without restriction, including without limitation the
|
|
9
|
+
rights to use, copy, modify, merge, publish, distribute, and/or sublicense
|
|
10
|
+
copies of the Specification, and to permit persons to whom the Specification is
|
|
11
|
+
furnished to do so, subject to the following conditions.
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Specification.
|
|
15
|
+
|
|
16
|
+
The Specification is provided "as is", without warranty of any kind, express,
|
|
17
|
+
implied, or otherwise, including but not limited to the warranties of
|
|
18
|
+
merchantability, fitness for a particular purpose and noninfringement. In no
|
|
19
|
+
event shall the International Color Consortium be liable for any claim, damages
|
|
20
|
+
or other liability, whether in an action of contract, tort or otherwise, arising
|
|
21
|
+
from, out of, or in connection with the Specification or the use or other
|
|
22
|
+
dealings in the Specification.
|
|
23
|
+
|
|
24
|
+
Except as contained in this notice, the name of the International Color
|
|
25
|
+
Consortium shall not be used in advertising or otherwise to promote the use or
|
|
26
|
+
other dealings in this Specification without prior written authorization from
|
|
27
|
+
the International Color Consortium.
|
|
28
|
+
|
|
29
|
+
== license-statement
|
|
30
|
+
=== Licenses and trademarks
|
|
31
|
+
|
|
32
|
+
International Color Consortium and the ICC logo are registered trademarks of the
|
|
33
|
+
International Color Consortium. Rather than put a trademark symbol in every
|
|
34
|
+
occurrence of other trademarked names, we state that we are using the names only
|
|
35
|
+
in an editorial fashion, and to the benefit of the trademark owner, with no
|
|
36
|
+
intention of infringement of the trademark.
|
|
37
|
+
|
|
38
|
+
== feedback-statement
|
|
39
|
+
=== For additional information on the ICC
|
|
40
|
+
|
|
41
|
+
Visit the ICC Web site: http://www.color.org
|