metanorma 1.3.3 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -11
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -2
- data/lib/metanorma/collection.rb +7 -1
- data/lib/metanorma/collection_fileparse.rb +65 -47
- data/lib/metanorma/collection_fileprocess.rb +88 -22
- data/lib/metanorma/collection_manifest.rb +27 -8
- data/lib/metanorma/collection_renderer.rb +38 -10
- data/lib/metanorma/compile.rb +41 -36
- data/lib/metanorma/document.rb +6 -2
- data/lib/metanorma/input/asciidoc.rb +27 -30
- data/lib/metanorma/util.rb +43 -2
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +4 -3
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16196ab7719ac294eb22120afeb64ebceee75e83469bf0a4ae1abd2221952139
|
4
|
+
data.tar.gz: d1ed0d591efa82eb1e40b09f6598f98f6d7738435c85b6146e2ec7ada41a3413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4618e5ebe7f688ae9eec5680d0f17aa2795391e1485e749f975052952378742a0c29be722e46aef10c34432a658294bb06c5eac945c56a27c65c8ab7aedc944b
|
7
|
+
data.tar.gz: e0b3b3ac8846b3d6ecd1fb75691d525f3763c126d2c1db3469c1192c93a14f9a168ec75f2a851f92260334c514704072cc9a59c360034d8de578ca37a2bebf24
|
data/.github/workflows/rake.yml
CHANGED
@@ -16,19 +16,9 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: [ '
|
19
|
+
ruby: [ '3.0', '2.7', '2.6', '2.5' ]
|
20
20
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
21
|
experimental: [ false ]
|
22
|
-
include:
|
23
|
-
- ruby: '3.0'
|
24
|
-
os: 'ubuntu-latest'
|
25
|
-
experimental: true
|
26
|
-
- ruby: '3.0'
|
27
|
-
os: 'windows-latest'
|
28
|
-
experimental: true
|
29
|
-
- ruby: '3.0'
|
30
|
-
os: 'macos-latest'
|
31
|
-
experimental: true
|
32
22
|
steps:
|
33
23
|
- uses: actions/checkout@v2
|
34
24
|
with:
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,6 +6,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}" }
|
|
6
6
|
|
7
7
|
gemspec
|
8
8
|
|
9
|
-
if File.exist?
|
10
|
-
eval File.read(
|
9
|
+
if File.exist? "Gemfile.devel"
|
10
|
+
eval File.read("Gemfile.devel"), nil, "Gemfile.devel" # rubocop:disable Security/Eval
|
11
11
|
end
|
data/lib/metanorma/collection.rb
CHANGED
@@ -4,6 +4,7 @@ require "relaton"
|
|
4
4
|
require "relaton/cli"
|
5
5
|
require "metanorma/collection_manifest"
|
6
6
|
require "metanorma-utils"
|
7
|
+
require_relative "util"
|
7
8
|
|
8
9
|
module Metanorma
|
9
10
|
# Metanorma collection of documents
|
@@ -18,6 +19,8 @@ module Metanorma
|
|
18
19
|
# @return [Hash<String, Metanorma::Document>]
|
19
20
|
attr_accessor :documents
|
20
21
|
|
22
|
+
attr_accessor :disambig
|
23
|
+
|
21
24
|
# @param file [String] path to source file
|
22
25
|
# @param directives [Array<String>] documents-inline to inject the XML into
|
23
26
|
# the collection manifest; documents-external to keeps them outside
|
@@ -41,6 +44,7 @@ module Metanorma
|
|
41
44
|
@prefatory = args[:prefatory]
|
42
45
|
@final = args[:final]
|
43
46
|
@log = Metanorma::Utils::Log.new
|
47
|
+
@disambig = Util::DisambigFiles.new
|
44
48
|
end
|
45
49
|
|
46
50
|
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
@@ -87,7 +91,9 @@ module Metanorma
|
|
87
91
|
private
|
88
92
|
|
89
93
|
def parse_xml(file)
|
90
|
-
xml = Nokogiri::XML File.read(file, encoding: "UTF-8")
|
94
|
+
xml = Nokogiri::XML File.read(file, encoding: "UTF-8") do |config|
|
95
|
+
config.huge
|
96
|
+
end
|
91
97
|
if (b = xml.at("/xmlns:metanorma-collection/xmlns:bibdata"))
|
92
98
|
bd = Relaton::Cli.parse_xml b
|
93
99
|
end
|
@@ -11,15 +11,21 @@ module Metanorma
|
|
11
11
|
xrefs = @isodoc.xref_init(@lang, @script, @isodoc, @isodoc.i18n, {})
|
12
12
|
xrefs.parse xml
|
13
13
|
xrefs.get.each_with_object({}) do |(k, v), ret|
|
14
|
-
|
15
|
-
index = if v[:container] || v[:label].nil? || v[:label].empty?
|
16
|
-
UUIDTools::UUID.random_create.to_s
|
17
|
-
else v[:label]
|
18
|
-
end
|
19
|
-
ret[v[:type]][index] = k
|
14
|
+
read_anchors1(k, v, ret)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
18
|
+
def read_anchors1(key, val, ret)
|
19
|
+
val[:type] ||= "clause"
|
20
|
+
ret[val[:type]] ||= {}
|
21
|
+
index = if val[:container] || val[:label].nil? || val[:label].empty?
|
22
|
+
UUIDTools::UUID.random_create.to_s
|
23
|
+
else val[:label]
|
24
|
+
end
|
25
|
+
ret[val[:type]][index] = key
|
26
|
+
ret[val[:type]][val[:value]] = key if val[:value]
|
27
|
+
end
|
28
|
+
|
23
29
|
# @param id [String]
|
24
30
|
# @param read [Boolean]
|
25
31
|
# @return [Array<String, nil>]
|
@@ -31,29 +37,36 @@ module Metanorma
|
|
31
37
|
|
32
38
|
# @param bib [Nokogiri::XML::Element]
|
33
39
|
# @param identifier [String]
|
34
|
-
def update_bibitem(bib, identifier) # rubocop:disable Metrics/AbcSize
|
35
|
-
docid = bib&.at(ns("./docidentifier"))&.
|
36
|
-
unless @files[docid]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Util.log(error, :warning)
|
41
|
-
return
|
42
|
-
end
|
43
|
-
id = bib["id"]
|
44
|
-
newbib = bib.replace(@files[docid][:bibdata])
|
45
|
-
newbib.name = "bibitem"
|
46
|
-
newbib["id"] = id
|
47
|
-
newbib["hidden"] = "true"
|
48
|
-
newbib&.at(ns("./ext"))&.remove
|
40
|
+
def update_bibitem(bib, identifier) # rubocop:disable Metrics/AbcSize
|
41
|
+
docid = bib&.at(ns("./docidentifier"))&.children&.to_xml
|
42
|
+
return fail_update_bibitem(docid, identifier) unless @files[docid]
|
43
|
+
|
44
|
+
newbib = dup_bibitem(docid, bib)
|
45
|
+
bib.replace(newbib)
|
49
46
|
_file, url = targetfile(@files[docid], relative: true, read: false,
|
50
|
-
|
47
|
+
doc: !@files[docid][:attachment])
|
51
48
|
uri_node = Nokogiri::XML::Node.new "uri", newbib
|
52
49
|
uri_node[:type] = "citation"
|
53
50
|
uri_node.content = url
|
54
51
|
newbib.at(ns("./docidentifier")).previous = uri_node
|
55
52
|
end
|
56
53
|
|
54
|
+
def fail_update_bibitem(docid, identifier)
|
55
|
+
error = "[metanorma] Cannot find crossreference to document #{docid} "\
|
56
|
+
"in document #{identifier}."
|
57
|
+
@log.add("Cross-References", nil, error)
|
58
|
+
Util.log(error, :warning)
|
59
|
+
end
|
60
|
+
|
61
|
+
def dup_bibitem(docid, bib)
|
62
|
+
newbib = @files[docid][:bibdata].dup
|
63
|
+
newbib.name = "bibitem"
|
64
|
+
newbib["hidden"] = "true"
|
65
|
+
newbib&.at("./*[local-name() = 'ext']")&.remove
|
66
|
+
newbib["id"] = bib["id"]
|
67
|
+
newbib
|
68
|
+
end
|
69
|
+
|
57
70
|
# Resolves direct links to other files in collection
|
58
71
|
# (repo(current-metanorma-collection/x),
|
59
72
|
# and indirect links to other files in collection
|
@@ -64,12 +77,12 @@ module Metanorma
|
|
64
77
|
# @param internal_refs [Hash{String=>Hash{String=>String}] schema name to anchor to filename
|
65
78
|
# @return [String] XML content
|
66
79
|
def update_xrefs(file, identifier, internal_refs)
|
67
|
-
docxml = Nokogiri::XML(file)
|
80
|
+
docxml = Nokogiri::XML(file) { |config| config.huge }
|
68
81
|
update_indirect_refs_to_docs(docxml, internal_refs)
|
69
82
|
add_document_suffix(identifier, docxml)
|
70
83
|
update_direct_refs_to_docs(docxml, identifier)
|
71
84
|
svgmap_resolve(datauri_encode(docxml))
|
72
|
-
docxml.xpath(ns("//references[not(./bibitem[not(@hidden) or "\
|
85
|
+
docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or "\
|
73
86
|
"@hidden = 'false'])]")).each do |f|
|
74
87
|
f["hidden"] = "true"
|
75
88
|
end
|
@@ -103,12 +116,18 @@ module Metanorma
|
|
103
116
|
# Preferably with anchor, and is a job to realise dynamic lookup
|
104
117
|
# of localities.
|
105
118
|
def update_direct_refs_to_docs(docxml, identifier)
|
119
|
+
erefs = docxml.xpath(ns("//eref"))
|
120
|
+
.each_with_object({ citeas: {}, bibitemid: {} }) do |i, m|
|
121
|
+
m[:citeas][i["citeas"]] = true
|
122
|
+
m[:bibitemid][i["bibitemid"]] = true
|
123
|
+
end
|
106
124
|
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
|
107
125
|
docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
|
108
126
|
next unless docid && %r{^current-metanorma-collection/}.match(docid)
|
109
127
|
|
110
128
|
update_bibitem(b, identifier)
|
111
|
-
|
129
|
+
docid = b&.at(ns("./docidentifier"))&.children&.to_xml or next
|
130
|
+
erefs[:citeas][docid] and update_anchors(b, docxml, docid)
|
112
131
|
end
|
113
132
|
end
|
114
133
|
|
@@ -125,6 +144,9 @@ module Metanorma
|
|
125
144
|
def update_indirect_refs_to_docs1(docxml, schema, id, file)
|
126
145
|
docxml.xpath(ns("//eref[@bibitemid = '#{schema}_#{id}']")).each do |e|
|
127
146
|
e["citeas"] = file
|
147
|
+
if a = e.at(ns(".//locality[@type = 'anchor']/referenceFrom"))
|
148
|
+
a.children = "#{a.text}_#{Metanorma::Utils::to_ncname(file)}"
|
149
|
+
end
|
128
150
|
end
|
129
151
|
docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/"\
|
130
152
|
"docidentifier[@type = 'repository']")) or return
|
@@ -134,21 +156,19 @@ module Metanorma
|
|
134
156
|
|
135
157
|
# update crossrefences to other documents, to include
|
136
158
|
# disambiguating document suffix on id
|
137
|
-
def update_anchors(bib, docxml,
|
138
|
-
docid = bib&.at(ns("./docidentifier"))&.text
|
159
|
+
def update_anchors(bib, docxml, docid) # rubocop:disable Metrics/AbcSize
|
139
160
|
docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
|
140
|
-
if @files[docid]
|
141
|
-
update_anchor_loc(bib, e, docid)
|
161
|
+
if @files[docid] then update_anchor_loc(bib, e, docid)
|
142
162
|
else
|
143
|
-
e << "<strong>** Unresolved reference to document #{docid}
|
144
|
-
"
|
163
|
+
e << "<strong>** Unresolved reference to document #{docid} "\
|
164
|
+
"from eref</strong>"
|
145
165
|
end
|
146
166
|
end
|
147
167
|
end
|
148
168
|
|
149
|
-
def update_anchor_loc(bib,
|
150
|
-
loc =
|
151
|
-
return update_anchor_create_loc(bib,
|
169
|
+
def update_anchor_loc(bib, eref, docid)
|
170
|
+
loc = eref.at(ns(".//locality[@type = 'anchor']")) or
|
171
|
+
return update_anchor_create_loc(bib, eref, docid)
|
152
172
|
document_suffix = Metanorma::Utils::to_ncname(docid)
|
153
173
|
ref = loc.at(ns("./referenceFrom")) || return
|
154
174
|
anchor = "#{ref.text}_#{document_suffix}"
|
@@ -161,17 +181,14 @@ module Metanorma
|
|
161
181
|
|
162
182
|
# if there is a crossref to another document, with no anchor, retrieve the
|
163
183
|
# anchor given the locality, and insert it into the crossref
|
164
|
-
def update_anchor_create_loc(
|
165
|
-
ins =
|
184
|
+
def update_anchor_create_loc(_bib, eref, docid)
|
185
|
+
ins = eref.at(ns("./localityStack")) or return
|
166
186
|
type = ins&.at(ns("./locality/@type"))&.text
|
187
|
+
type = "clause" if type == "annex"
|
167
188
|
ref = ins&.at(ns("./locality/referenceFrom"))&.text
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
locality = Nokogiri::XML::Node.new "locality", bib
|
172
|
-
locality[:type] = "anchor"
|
173
|
-
locality.add_child ref_from
|
174
|
-
ins << locality
|
189
|
+
anchor = @files[docid][:anchors].dig(type, ref) or return
|
190
|
+
ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}"\
|
191
|
+
"</referenceFrom></locality>"
|
175
192
|
end
|
176
193
|
|
177
194
|
# gather internal bibitem references
|
@@ -182,7 +199,7 @@ module Metanorma
|
|
182
199
|
file, = targetfile(x, read: true)
|
183
200
|
Nokogiri::XML(file)
|
184
201
|
.xpath(ns("//bibitem[@type = 'internal']/"\
|
185
|
-
|
202
|
+
"docidentifier[@type = 'repository']")).each do |d|
|
186
203
|
a = d.text.split(%r{/}, 2)
|
187
204
|
a.size > 1 or next
|
188
205
|
refs[a[0]] ||= {}
|
@@ -207,10 +224,11 @@ module Metanorma
|
|
207
224
|
|
208
225
|
def locate_internal_refs1(refs, identifier, filedesc)
|
209
226
|
file, _filename = targetfile(filedesc, read: true)
|
210
|
-
|
227
|
+
xml = Nokogiri::XML(file) { |config| config.huge }
|
228
|
+
t = xml.xpath("//*/@id").each_with_object({}) { |i, x| x[i.text] = true }
|
211
229
|
refs.each do |schema, ids|
|
212
|
-
ids.
|
213
|
-
n =
|
230
|
+
ids.keys.select { |id| t[id] }.each do |id|
|
231
|
+
n = xml.at("//*[@id = '#{id}']") and
|
214
232
|
n.at("./ancestor-or-self::*[@type = '#{schema}']") and
|
215
233
|
refs[schema][id] = identifier
|
216
234
|
end
|
@@ -15,7 +15,7 @@ module Metanorma
|
|
15
15
|
def read_files(path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
16
16
|
files = {}
|
17
17
|
@xml.xpath(ns("//docref")).each do |d|
|
18
|
-
identifier = d.at(ns("./identifier")).
|
18
|
+
identifier = d.at(ns("./identifier")).children.to_xml
|
19
19
|
files[identifier] = file_entry(d, identifier, path)
|
20
20
|
if files[identifier][:attachment]
|
21
21
|
files[identifier][:bibdata] = Metanorma::Document
|
@@ -27,22 +27,57 @@ module Metanorma
|
|
27
27
|
files[identifier][:anchors] = read_anchors(xml)
|
28
28
|
files[identifier][:bibdata] = xml.at(ns("//bibdata"))
|
29
29
|
end
|
30
|
+
files[identifier][:bibitem] = files[identifier][:bibdata].dup
|
31
|
+
files[identifier][:bibitem].name = "bibitem"
|
32
|
+
files[identifier][:bibitem]["hidden"] = "true"
|
33
|
+
files[identifier][:bibitem]&.at("./*[local-name() = 'ext']")&.remove
|
30
34
|
end
|
31
|
-
files
|
35
|
+
add_section_split(files)
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_section_split(files)
|
39
|
+
files.keys.each_with_object({}) do |k, m|
|
40
|
+
if files[k][:sectionsplit] == "true" && !files[k]["attachment"]
|
41
|
+
sectionsplit(files[k][:rel_path]).each_with_index do |f1, i|
|
42
|
+
m[k + f1[:title]] =
|
43
|
+
{ parentid: k, presentationxml: true, type: "fileref",
|
44
|
+
rel_path: f1[:url], out_path: File.basename(f1[:url]),
|
45
|
+
anchors: read_anchors(Nokogiri::XML(File.read(f1[:url]))),
|
46
|
+
bibdata: files[k][:bibdata], ref: f1[:url] }
|
47
|
+
m[k + f1[:title]][:bare] = true unless i.zero?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
m[k] = files[k]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sectionsplit(file)
|
55
|
+
Compile.new.compile(
|
56
|
+
file, { format: :asciidoc, extension_keys: [:presentation] }
|
57
|
+
.merge(@compile_options)
|
58
|
+
)
|
59
|
+
r = file.sub(/\.xml$/, ".presentation.xml")
|
60
|
+
@isodoc.sectionsplit(
|
61
|
+
Nokogiri::XML(File.read(r)), File.basename(r), File.dirname(r)
|
62
|
+
).sort_by { |f| f[:order] }
|
32
63
|
end
|
33
64
|
|
34
65
|
# rel_path is the source file address, determined relative to the YAML.
|
35
66
|
# out_path is the destination file address, with any references outside
|
36
67
|
# the working directory (../../...) truncated
|
37
|
-
def file_entry(
|
38
|
-
|
68
|
+
def file_entry(ref, identifier, _path)
|
69
|
+
out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
|
70
|
+
ret = if ref["fileref"]
|
39
71
|
{ type: "fileref", ref: @documents[identifier].file,
|
40
|
-
rel_path:
|
41
|
-
out_path:
|
72
|
+
rel_path: ref["fileref"],
|
73
|
+
out_path: out }
|
42
74
|
else
|
43
|
-
{ type: "id", ref:
|
75
|
+
{ type: "id", ref: ref["id"] }
|
44
76
|
end
|
45
|
-
ret[:attachment] =
|
77
|
+
ret[:attachment] = ref["attachment"] if ref["attachment"]
|
78
|
+
ret[:sectionsplit] = ref["sectionsplit"] if ref["sectionsplit"]
|
79
|
+
ret[:presentationxml] = ref["presentation-xml"] if ref["presentation-xml"]
|
80
|
+
ret[:bareafterfirst] = ref["bare-after-first"] if ref["bare-after-first"]
|
46
81
|
ret
|
47
82
|
end
|
48
83
|
|
@@ -74,9 +109,9 @@ module Metanorma
|
|
74
109
|
# @return [Array<String, nil>]
|
75
110
|
def targetfile(data, options)
|
76
111
|
options = { read: false, doc: true, relative: false }.merge(options)
|
77
|
-
path = options[:relative] ? data[:
|
112
|
+
path = options[:relative] ? data[:rel_path] : data[:ref]
|
78
113
|
if data[:type] == "fileref"
|
79
|
-
ref_file path, options[:read], options[:doc]
|
114
|
+
ref_file path, data[:out_path], options[:read], options[:doc]
|
80
115
|
else
|
81
116
|
xml_file data[:id], options[:read]
|
82
117
|
end
|
@@ -86,40 +121,71 @@ module Metanorma
|
|
86
121
|
# @param read [Boolean]
|
87
122
|
# @param doc [Boolean]
|
88
123
|
# @return [Array<String, nil>]
|
89
|
-
def ref_file(ref, read, doc)
|
124
|
+
def ref_file(ref, out, read, doc)
|
90
125
|
file = File.read(ref, encoding: "utf-8") if read
|
91
|
-
filename =
|
126
|
+
filename = out.dup
|
92
127
|
filename.sub!(/\.xml$/, ".html") if doc
|
93
128
|
[file, filename]
|
94
129
|
end
|
95
130
|
|
96
131
|
# compile and output individual file in collection
|
132
|
+
# warn "metanorma compile -x html #{f.path}"
|
97
133
|
def file_compile(file, filename, identifier)
|
98
|
-
# warn "metanorma compile -x html #{f.path}"
|
99
134
|
c = Compile.new
|
100
|
-
c.compile file.path, { format: :asciidoc,
|
101
|
-
|
135
|
+
c.compile file.path, { format: :asciidoc, extension_keys: @format }
|
136
|
+
.merge(compile_options(identifier))
|
102
137
|
@files[identifier][:outputs] = {}
|
138
|
+
file_compile_formats(file, filename, identifier, c)
|
139
|
+
end
|
140
|
+
|
141
|
+
def compile_options(identifier)
|
142
|
+
ret = @compile_options.dup
|
143
|
+
Array(@directives).include?("presentation-xml") ||
|
144
|
+
@files[identifier][:presentationxml] and
|
145
|
+
ret.merge!(passthrough_presentation_xml: true)
|
146
|
+
@files[identifier][:sectionsplit] == "true" and
|
147
|
+
ret.merge!(sectionsplit: "true")
|
148
|
+
@files[identifier][:bare] == true and
|
149
|
+
ret.merge!(bare: true)
|
150
|
+
ret
|
151
|
+
end
|
152
|
+
|
153
|
+
def file_compile_formats(file, filename, identifier, compile)
|
103
154
|
@format.each do |e|
|
104
|
-
ext =
|
105
|
-
fn = File.basename(filename).sub(/(?<=\.)[
|
106
|
-
|
107
|
-
|
155
|
+
ext = compile.processor.output_formats[e]
|
156
|
+
fn = File.basename(filename).sub(/(?<=\.)[^.]+$/, ext.to_s)
|
157
|
+
if /html$/.match?(ext) && @files[identifier][:sectionsplit]
|
158
|
+
# file_sectionsplit_copy(file, fn, identifier, ext, e)
|
159
|
+
else
|
160
|
+
FileUtils.cp file.path.sub(/\.xml$/, ".#{ext}"),
|
161
|
+
File.join(@outdir, fn)
|
162
|
+
@files[identifier][:outputs][e] = File.join(@outdir, fn)
|
163
|
+
end
|
108
164
|
end
|
109
165
|
end
|
110
166
|
|
167
|
+
def file_sectionsplit_copy(file, base, identifier, ext, format)
|
168
|
+
dir = file.path.sub(/\.xml$/, ".#{ext}_collection")
|
169
|
+
files = Dir.glob("#{dir}/*.#{ext}")
|
170
|
+
FileUtils.cp files, @outdir
|
171
|
+
cover = File.join(@outdir, base.sub(/\.html$/, ".index.html"))
|
172
|
+
FileUtils.cp File.join(dir, "index.html"), cover
|
173
|
+
@files[identifier][:outputs][format] = cover
|
174
|
+
end
|
175
|
+
|
111
176
|
def copy_file_to_dest(fileref)
|
112
|
-
_file, filename = targetfile(fileref, read: true, doc: false)
|
113
177
|
dest = File.join(@outdir, fileref[:out_path])
|
114
178
|
FileUtils.mkdir_p(File.dirname(dest))
|
115
|
-
FileUtils.cp
|
179
|
+
FileUtils.cp fileref[:ref], dest
|
116
180
|
end
|
117
181
|
|
118
182
|
# process each file in the collection
|
119
183
|
# files are held in memory, and altered as postprocessing
|
120
184
|
def files # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
121
185
|
internal_refs = locate_internal_refs
|
122
|
-
@files.
|
186
|
+
@files.each_with_index do |(identifier, x), i|
|
187
|
+
i.positive? && Array(@directives).include?("bare-after-first") and
|
188
|
+
@compile_options.merge!(bare: true)
|
123
189
|
if x[:attachment] then copy_file_to_dest(x)
|
124
190
|
else
|
125
191
|
file, filename = targetfile(x, read: true)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "util"
|
4
|
+
|
3
5
|
module Metanorma
|
4
6
|
# Metanorma collection's manifest
|
5
7
|
class CollectionManifest
|
@@ -15,6 +17,7 @@ module Metanorma
|
|
15
17
|
@title = title
|
16
18
|
@docref = docref
|
17
19
|
@manifest = manifest
|
20
|
+
@disambig = Util::DisambigFiles.new
|
18
21
|
end
|
19
22
|
|
20
23
|
class << self
|
@@ -43,9 +46,11 @@ module Metanorma
|
|
43
46
|
# @return [Hash{String=>String}]
|
44
47
|
def parse_docref(mnf)
|
45
48
|
mnf.xpath("xmlns:docref").map do |dr|
|
46
|
-
h = { "identifier" => dr.at("identifier").
|
49
|
+
h = { "identifier" => dr.at("identifier").children.to_xml }
|
47
50
|
dr[:fileref] and h["fileref"] = dr[:fileref]
|
48
51
|
h["attachment"] = dr[:attachment] if dr[:attachment]
|
52
|
+
h["sectionsplit"] = dr[:sectionsplit] if dr[:sectionsplit]
|
53
|
+
h["presentation-xml"] = dr[:presentationxml] if dr[:presentationxml]
|
49
54
|
h
|
50
55
|
end
|
51
56
|
end
|
@@ -57,7 +62,7 @@ module Metanorma
|
|
57
62
|
@manifest.each { |mnf| mnf.collection = col }
|
58
63
|
end
|
59
64
|
|
60
|
-
# @param dir [String] path to
|
65
|
+
# @param dir [String] path to collection
|
61
66
|
# @return [Hash<String, Metanorma::Document>]
|
62
67
|
def documents(dir = "")
|
63
68
|
docs = @docref.each_with_object({}) do |dr, m|
|
@@ -100,14 +105,28 @@ module Metanorma
|
|
100
105
|
|
101
106
|
# @param builder [Nokogiri::XML::Builder]
|
102
107
|
def docref_to_xml(builder)
|
108
|
+
@disambig = Util::DisambigFiles.new
|
103
109
|
@docref.each do |dr|
|
104
|
-
drf = builder.docref
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
+
drf = builder.docref do |b|
|
111
|
+
b.identifier do |i|
|
112
|
+
i << dr["identifier"]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
docref_to_xml_attrs(drf, dr)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def docref_to_xml_attrs(elem, docref)
|
120
|
+
elem[:fileref] = @disambig.source2dest_filename(docref["fileref"])
|
121
|
+
elem[:attachment] = docref["attachment"] if docref["attachment"]
|
122
|
+
elem[:sectionsplit] = docref["sectionsplit"] if docref["sectionsplit"]
|
123
|
+
elem[:presentationxml] = "true" if docref["presentation-xml"] &&
|
124
|
+
docref["presentation-xml"] == "true" || docref["presentation-xml"] == true
|
125
|
+
if collection.directives.include?("documents-inline")
|
126
|
+
id = collection.documents.find_index do |k, _|
|
127
|
+
k == docref["identifier"]
|
110
128
|
end
|
129
|
+
elem[:id] = format("doc%<index>09d", index: id)
|
111
130
|
end
|
112
131
|
end
|
113
132
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require "isodoc"
|
4
4
|
require_relative "collection_fileprocess"
|
5
5
|
require_relative "fontist_utils"
|
6
|
+
require_relative "util"
|
6
7
|
|
7
8
|
module Metanorma
|
8
9
|
# XML collection renderer
|
@@ -34,13 +35,16 @@ module Metanorma
|
|
34
35
|
|
35
36
|
@outdir = options[:output_folder]
|
36
37
|
@coverpage = options[:coverpage]
|
37
|
-
@format = options[:format]
|
38
|
+
@format = Util.sort_extensions_execution(options[:format])
|
38
39
|
@compile_options = options[:compile] || {}
|
39
40
|
@log = options[:log]
|
40
41
|
@documents = collection.documents
|
42
|
+
@directives = collection.directives
|
43
|
+
@disambig = Util::DisambigFiles.new
|
41
44
|
|
42
45
|
# list of files in the collection
|
43
46
|
@files = read_files folder
|
47
|
+
isodoc_populate(@isodoc)
|
44
48
|
FileUtils.rm_rf @outdir
|
45
49
|
FileUtils.mkdir_p @outdir
|
46
50
|
end
|
@@ -66,13 +70,15 @@ module Metanorma
|
|
66
70
|
ext = e == :presentation ? "presentation.xml" : e.to_s
|
67
71
|
out = col.clone
|
68
72
|
out.directives << "documents-inline"
|
69
|
-
out.documents.
|
73
|
+
out.documents.each_key do |id|
|
70
74
|
next if @files[id][:attachment]
|
71
75
|
|
72
76
|
filename = @files[id][:outputs][e]
|
73
77
|
out.documents[id] = Metanorma::Document.raw_file(filename)
|
74
78
|
end
|
75
|
-
File.open(File.join(@outdir, "collection.#{ext}"), "w:UTF-8")
|
79
|
+
File.open(File.join(@outdir, "collection.#{ext}"), "w:UTF-8") do |f|
|
80
|
+
f.write(out.to_xml)
|
81
|
+
end
|
76
82
|
end
|
77
83
|
options[:format].include?(:pdf) and
|
78
84
|
pdfconv.convert(File.join(@outdir, "collection.presentation.xml"))
|
@@ -103,15 +109,21 @@ module Metanorma
|
|
103
109
|
end
|
104
110
|
|
105
111
|
# The isodoc class for the metanorma flavour we are using
|
106
|
-
def isodoc
|
112
|
+
def isodoc
|
107
113
|
x = Asciidoctor.load nil, backend: @doctype.to_sym
|
108
114
|
isodoc = x.converter.html_converter(Dummy.new)
|
109
115
|
isodoc.i18n_init(@lang, @script) # read in internationalisation
|
116
|
+
isodoc.metadata_init(@lang, @script, isodoc.i18n)
|
117
|
+
isodoc.info(@xml, nil)
|
118
|
+
isodoc
|
119
|
+
end
|
120
|
+
|
121
|
+
def isodoc_populate(isodoc)
|
110
122
|
# create the @meta class of isodoc, with "navigation" set to the index bar
|
111
123
|
# extracted from the manifest
|
112
124
|
nav = indexfile(@xml.at(ns("//manifest")))
|
113
125
|
i18n = isodoc.i18n
|
114
|
-
i18n.set(
|
126
|
+
i18n.set("navigation", nav)
|
115
127
|
isodoc.metadata_init(@lang, @script, i18n)
|
116
128
|
# populate the @meta class of isodoc with the various metadata fields
|
117
129
|
# native to the flavour; used to populate Liquid
|
@@ -168,11 +180,19 @@ module Metanorma
|
|
168
180
|
# @param builder [Nokogiri::XML::Builder]
|
169
181
|
def docrefs(elm, builder)
|
170
182
|
elm.xpath(ns("./docref")).each do |d|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
183
|
+
ident = d.at(ns("./identifier")).children.to_xml
|
184
|
+
builder.li do |li|
|
185
|
+
li.a **{ href: index_link(d, ident) } do |a|
|
186
|
+
a << ident
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def index_link(docref, ident)
|
193
|
+
if docref["fileref"]
|
194
|
+
@files[ident][:out_path].sub(/\.xml$/, ".html")
|
195
|
+
else "#{docref['id']}.html"
|
176
196
|
end
|
177
197
|
end
|
178
198
|
|
@@ -198,6 +218,14 @@ module Metanorma
|
|
198
218
|
|
199
219
|
private
|
200
220
|
|
221
|
+
def format_sort(formats)
|
222
|
+
ret = []
|
223
|
+
formats.include?(:xml) and ret << :xml
|
224
|
+
formats.include?(:presentation) and ret << :presentation
|
225
|
+
a = %i(presentation xml)
|
226
|
+
ret + formats.reject { |i| a.include? i }
|
227
|
+
end
|
228
|
+
|
201
229
|
# @param options [Hash]
|
202
230
|
# @raise [ArgumentError]
|
203
231
|
def check_options(options)
|
data/lib/metanorma/compile.rb
CHANGED
@@ -6,6 +6,7 @@ require "fontist"
|
|
6
6
|
require "fontist/manifest/install"
|
7
7
|
require_relative "compile_validate"
|
8
8
|
require_relative "fontist_utils"
|
9
|
+
require_relative "util"
|
9
10
|
|
10
11
|
module Metanorma
|
11
12
|
class Compile
|
@@ -35,7 +36,7 @@ module Metanorma
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def xml_options_extract(file)
|
38
|
-
xml = Nokogiri::XML(file)
|
39
|
+
xml = Nokogiri::XML(file) { |config| config.huge }
|
39
40
|
if xml.root
|
40
41
|
@registry.root_tags.each do |k, v|
|
41
42
|
return { type: k } if v == xml.root.name
|
@@ -74,7 +75,9 @@ module Metanorma
|
|
74
75
|
memo
|
75
76
|
end
|
76
77
|
end
|
77
|
-
if !extensions.include?(:presentation)
|
78
|
+
if !extensions.include?(:presentation) && extensions.any? do |e|
|
79
|
+
@processor.use_presentation_xml(e)
|
80
|
+
end
|
78
81
|
extensions << :presentation
|
79
82
|
end
|
80
83
|
extensions
|
@@ -88,7 +91,7 @@ module Metanorma
|
|
88
91
|
options[:asciimath] and
|
89
92
|
file.sub!(/^(=[^\n]+\n)/, "\\1:mn-keep-asciimath:\n")
|
90
93
|
dir = File.dirname(filename)
|
91
|
-
dir !=
|
94
|
+
dir != "." and
|
92
95
|
file.gsub!(/^include::/, "include::#{dir}/")
|
93
96
|
[file, @processor.input_to_isodoc(file, filename, options)]
|
94
97
|
when ".xml"
|
@@ -108,15 +111,17 @@ module Metanorma
|
|
108
111
|
|
109
112
|
def relaton_export(isodoc, options)
|
110
113
|
return unless options[:relaton]
|
111
|
-
|
114
|
+
|
115
|
+
xml = Nokogiri::XML(isodoc) { |config| config.huge }
|
112
116
|
bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
|
113
|
-
#docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
|
114
|
-
#outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
|
117
|
+
# docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
|
118
|
+
# outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
|
115
119
|
File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
|
116
120
|
end
|
117
121
|
|
118
122
|
def clean_sourcecode(xml)
|
119
|
-
xml.xpath(".//callout | .//annotation | .//xmlns:callout |
|
123
|
+
xml.xpath(".//callout | .//annotation | .//xmlns:callout | "\
|
124
|
+
".//xmlns:annotation").each do |x|
|
120
125
|
x.remove
|
121
126
|
end
|
122
127
|
xml.xpath(".//br | .//xmlns:br").each { |x| x.replace("\n") }
|
@@ -125,12 +130,13 @@ module Metanorma
|
|
125
130
|
|
126
131
|
def extract(isodoc, dirname, extract_types)
|
127
132
|
return unless dirname
|
133
|
+
|
128
134
|
if extract_types.nil? || extract_types.empty?
|
129
135
|
extract_types = [:sourcecode, :image, :requirement]
|
130
136
|
end
|
131
137
|
FileUtils.rm_rf dirname
|
132
138
|
FileUtils.mkdir_p dirname
|
133
|
-
xml = Nokogiri::XML(isodoc)
|
139
|
+
xml = Nokogiri::XML(isodoc) { |config| config.huge }
|
134
140
|
sourcecode_export(xml, dirname) if extract_types.include? :sourcecode
|
135
141
|
image_export(xml, dirname) if extract_types.include? :image
|
136
142
|
requirement_export(xml, dirname) if extract_types.include? :requirement
|
@@ -176,17 +182,6 @@ module Metanorma
|
|
176
182
|
end
|
177
183
|
end
|
178
184
|
|
179
|
-
# dependency ordering
|
180
|
-
def sort_extensions_execution(ext)
|
181
|
-
case ext
|
182
|
-
when :xml then 0
|
183
|
-
when :rxl then 1
|
184
|
-
when :presentation then 2
|
185
|
-
else
|
186
|
-
99
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
185
|
def wrap_html(options, file_extension, outfilename)
|
191
186
|
if options[:wrapper] && /html$/.match(file_extension)
|
192
187
|
outfilename = outfilename.sub(/\.html$/, "")
|
@@ -201,34 +196,22 @@ module Metanorma
|
|
201
196
|
f = change_output_dir options
|
202
197
|
xml_name = f.sub(/\.[^.]+$/, ".xml")
|
203
198
|
presentationxml_name = f.sub(/\.[^.]+$/, ".presentation.xml")
|
204
|
-
extensions.
|
205
|
-
sort_extensions_execution(a) <=> sort_extensions_execution(b)
|
206
|
-
end.each do |ext|
|
207
|
-
isodoc_options = @processor.extract_options(file)
|
208
|
-
isodoc_options[:datauriimage] = true if options[:datauriimage]
|
209
|
-
isodoc_options[:sourcefilename] = options[:filename]
|
199
|
+
Util.sort_extensions_execution(extensions).each do |ext|
|
210
200
|
file_extension = @processor.output_formats[ext]
|
211
201
|
outfilename = f.sub(/\.[^.]+$/, ".#{file_extension}")
|
212
|
-
|
213
|
-
font_locations = FontistUtils.fontist_font_locations(@processor, options)
|
214
|
-
font_locations and
|
215
|
-
isodoc_options[:mn2pdf] = { font_manifest_file: font_locations.path }
|
216
|
-
end
|
202
|
+
isodoc_options = get_isodoc_options(file, options, ext)
|
217
203
|
if ext == :rxl
|
218
204
|
options[:relaton] = outfilename
|
219
205
|
relaton_export(isodoc, options)
|
206
|
+
elsif options[:passthrough_presentation_xml] && ext == :presentation
|
207
|
+
FileUtils.cp f, presentationxml_name
|
220
208
|
else
|
221
209
|
begin
|
222
210
|
@processor.use_presentation_xml(ext) ?
|
223
211
|
@processor.output(nil, presentationxml_name, outfilename, ext, isodoc_options) :
|
224
212
|
@processor.output(isodoc, xml_name, outfilename, ext, isodoc_options)
|
225
213
|
rescue StandardError => e
|
226
|
-
|
227
|
-
@errors << e.message
|
228
|
-
else
|
229
|
-
puts e.message
|
230
|
-
puts e.backtrace.join("\n")
|
231
|
-
end
|
214
|
+
isodoc_error_process(e)
|
232
215
|
end
|
233
216
|
end
|
234
217
|
wrap_html(options, file_extension, outfilename)
|
@@ -237,6 +220,28 @@ module Metanorma
|
|
237
220
|
|
238
221
|
private
|
239
222
|
|
223
|
+
def isodoc_error_process(err)
|
224
|
+
if err.message.include? "Fatal:"
|
225
|
+
@errors << err.message
|
226
|
+
else
|
227
|
+
puts err.message
|
228
|
+
puts err.backtrace.join("\n")
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def get_isodoc_options(file, options, ext)
|
233
|
+
isodoc_options = @processor.extract_options(file)
|
234
|
+
isodoc_options[:datauriimage] = true if options[:datauriimage]
|
235
|
+
isodoc_options[:sourcefilename] = options[:filename]
|
236
|
+
isodoc_options[:bare] ||= options[:bare]
|
237
|
+
isodoc_options[:sectionsplit] ||= options[:sectionsplit]
|
238
|
+
if ext == :pdf
|
239
|
+
floc = FontistUtils.fontist_font_locations(@processor, options) and
|
240
|
+
isodoc_options[:mn2pdf] = { font_manifest_file: floc.path }
|
241
|
+
end
|
242
|
+
isodoc_options
|
243
|
+
end
|
244
|
+
|
240
245
|
# @param options [Hash]
|
241
246
|
# @return [String]
|
242
247
|
def change_output_dir(options)
|
data/lib/metanorma/document.rb
CHANGED
@@ -30,7 +30,9 @@ module Metanorma
|
|
30
30
|
|
31
31
|
# raw XML file, can be used to put in entire file instead of just bibitem
|
32
32
|
def raw_file(filename)
|
33
|
-
doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8"))
|
33
|
+
doc = Nokogiri::XML(File.read(filename, encoding: "UTF-8")) do |config|
|
34
|
+
config.huge
|
35
|
+
end
|
34
36
|
new(doc, filename, raw: true)
|
35
37
|
end
|
36
38
|
|
@@ -100,7 +102,9 @@ module Metanorma
|
|
100
102
|
if @raw
|
101
103
|
builder << @bibitem.root.to_xml
|
102
104
|
else
|
103
|
-
builder.send(type
|
105
|
+
builder.send("#{type}-standard") do |b|
|
106
|
+
b << @bibitem.to_xml(bibdata: true)
|
107
|
+
end
|
104
108
|
end
|
105
109
|
end
|
106
110
|
end
|
@@ -2,20 +2,14 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
module Metanorma
|
4
4
|
module Input
|
5
|
-
|
6
5
|
class Asciidoc < Base
|
7
|
-
|
8
6
|
def process(file, filename, type, options = {})
|
9
7
|
require "asciidoctor"
|
10
8
|
out_opts = {
|
11
|
-
to_file: false,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
attributes: [
|
16
|
-
"nodoc", "stem", "xrefstyle=short", "docfile=#{filename}",
|
17
|
-
"output_dir=#{options[:output_dir]}"
|
18
|
-
]
|
9
|
+
to_file: false, safe: :safe, backend: type, header_footer: true,
|
10
|
+
attributes: ["nodoc", "stem", "xrefstyle=short",
|
11
|
+
"docfile=#{filename}",
|
12
|
+
"output_dir=#{options[:output_dir]}"]
|
19
13
|
}
|
20
14
|
unless asciidoctor_validate(file, filename, out_opts)
|
21
15
|
warn "Cannot continue compiling Asciidoctor document"
|
@@ -27,11 +21,12 @@ module Metanorma
|
|
27
21
|
def asciidoctor_validate(file, filename, options)
|
28
22
|
err = nil
|
29
23
|
begin
|
30
|
-
previous_stderr
|
24
|
+
previous_stderr = $stderr
|
25
|
+
$stderr = StringIO.new
|
31
26
|
::Asciidoctor.load(file, options)
|
32
|
-
%r{(\n|^)asciidoctor: ERROR: ['"]?#{Regexp.escape(filename ||
|
33
|
-
"<empty>")}['"]?: line \d+: include file not found: }
|
34
|
-
|
27
|
+
%r{(\n|^)asciidoctor: ERROR: ['"]?#{Regexp.escape(filename ||
|
28
|
+
"<empty>")}['"]?: line \d+: include file not found: }
|
29
|
+
.match($stderr.string) and err = $stderr.string
|
35
30
|
ensure
|
36
31
|
$stderr = previous_stderr
|
37
32
|
end
|
@@ -45,8 +40,9 @@ module Metanorma
|
|
45
40
|
/\n:mn-output-extensions: (?<extensions>[^\n]+)\n/ =~ headerextract
|
46
41
|
/\n:mn-relaton-output-file: (?<relaton>[^\n]+)\n/ =~ headerextract
|
47
42
|
/\n(?<asciimath>:mn-keep-asciimath:[^\n]*)\n/ =~ headerextract
|
48
|
-
asciimath = defined?(asciimath)
|
49
|
-
|
43
|
+
asciimath = if defined?(asciimath)
|
44
|
+
(!asciimath.nil? && asciimath != ":mn-keep-asciimath: false")
|
45
|
+
end
|
50
46
|
asciimath = nil if asciimath == false
|
51
47
|
{
|
52
48
|
type: defined?(type) ? type : nil,
|
@@ -60,38 +56,39 @@ module Metanorma
|
|
60
56
|
attr&.sub(/^#{name}:\s*$/, "#{name}: true")&.sub(/^#{name}:\s+/, "")
|
61
57
|
end
|
62
58
|
|
59
|
+
ADOC_OPTIONS = %w(htmlstylesheet htmlcoverpage htmlintropage scripts
|
60
|
+
scripts-override scripts-pdf wordstylesheet i18nyaml
|
61
|
+
standardstylesheet header wordcoverpage wordintropage
|
62
|
+
ulstyle olstyle htmlstylesheet-override bare
|
63
|
+
htmltoclevels doctoclevels sectionsplit
|
64
|
+
body-font header-font monospace-font title-font
|
65
|
+
wordstylesheet-override).freeze
|
66
|
+
|
63
67
|
def extract_options(file)
|
64
68
|
header = file.sub(/\n\n.*$/m, "\n")
|
65
|
-
ret =
|
66
|
-
scripts-pdf wordstylesheet
|
67
|
-
standardstylesheet header wordcoverpage wordintropage i18nyaml
|
68
|
-
ulstyle olstyle htmlstylesheet-override
|
69
|
-
htmltoclevels doctoclevels sectionsplit
|
70
|
-
body-font header-font monospace-font title-font
|
71
|
-
wordstylesheet-override).each_with_object({}) do |w, acc|
|
69
|
+
ret = ADOC_OPTIONS.each_with_object({}) do |w, acc|
|
72
70
|
m = /\n:#{w}: ([^\n]+)\n/.match(header) or next
|
73
71
|
acc[w.gsub(/-/, "").sub(/override$/, "_override")
|
74
72
|
.sub(/pdf$/, "_pdf").to_sym] = m[1]
|
75
73
|
end
|
76
74
|
/\n:data-uri-image: (?<datauriimage>[^\n]+)\n/ =~ header
|
77
|
-
/\n:(?<
|
75
|
+
/\n:(?<hier_assets>hierarchical-assets:[^\n]*)\n/ =~ header
|
78
76
|
/\n:(?<use_xinclude>use-xinclude:[^\n]*)\n/ =~ header
|
79
77
|
/\n:(?<break_up>break-up-urls-in-tables:[^\n]*)\n/ =~ header
|
80
78
|
|
81
|
-
defined?(
|
82
|
-
|
79
|
+
defined?(hier_assets) and
|
80
|
+
hier_assets = empty_attr(hier_assets, "hierarchical-assets")
|
83
81
|
defined?(use_xinclude) and
|
84
82
|
use_xinclude = empty_attr(use_xinclude, "use-xinclude")
|
85
83
|
defined?(break_up) and
|
86
84
|
break_up = empty_attr(break_up, "break-up-urls-in-tables")
|
87
|
-
ret.merge(
|
85
|
+
ret.merge(
|
88
86
|
datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
|
89
|
-
hierarchical_assets: defined?(
|
87
|
+
hierarchical_assets: defined?(hier_assets) ? hier_assets : nil,
|
90
88
|
use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
|
91
89
|
break_up_urls_in_tables: defined?(break_up) ? break_up : nil,
|
92
|
-
|
90
|
+
).reject { |_, val| val.nil? }
|
93
91
|
end
|
94
|
-
|
95
92
|
end
|
96
93
|
end
|
97
94
|
end
|
data/lib/metanorma/util.rb
CHANGED
@@ -12,8 +12,49 @@ module Metanorma
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
# dependency ordering
|
16
|
+
def self.sort_extensions_execution_ord(ext)
|
17
|
+
case ext
|
18
|
+
when :xml then 0
|
19
|
+
when :rxl then 1
|
20
|
+
when :presentation then 2
|
21
|
+
else
|
22
|
+
99
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.sort_extensions_execution(ext)
|
27
|
+
ext.sort do |a, b|
|
28
|
+
sort_extensions_execution_ord(a) <=> sort_extensions_execution_ord(b)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class DisambigFiles
|
33
|
+
def initialize
|
34
|
+
@seen_filenames = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def source2dest_filename(name, disambig = true)
|
38
|
+
n = name.sub(%r{^(\./)?(\.\./)+}, "")
|
39
|
+
dir = File.dirname(n)
|
40
|
+
base = File.basename(n)
|
41
|
+
if disambig && @seen_filenames.include?(base)
|
42
|
+
base = disambiguate_filename(base)
|
43
|
+
end
|
44
|
+
@seen_filenames << base
|
45
|
+
dir == "." ? base : File.join(dir, base)
|
46
|
+
end
|
47
|
+
|
48
|
+
def disambiguate_filename(base)
|
49
|
+
m = /^(?<start>.+\.)(?!0)(?<num>\d+)\.(?<suff>[^.]*)$/.match(base) ||
|
50
|
+
/^(?<start>.+\.)(?<suff>[^.]*)/.match(base) ||
|
51
|
+
/^(?<start>.+)$/.match(base)
|
52
|
+
i = m.names.include?("num") ? m["num"].to_i + 1 : 1
|
53
|
+
while @seen_filenames.include? base = "#{m['start']}#{i}.#{m['suff']}"
|
54
|
+
i += 1
|
55
|
+
end
|
56
|
+
base
|
57
|
+
end
|
17
58
|
end
|
18
59
|
end
|
19
60
|
end
|
data/lib/metanorma/version.rb
CHANGED
data/metanorma.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.bindir = "bin"
|
21
21
|
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
|
-
spec.required_ruby_version = ">= 2.
|
23
|
+
spec.required_ruby_version = ">= 2.5.0"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "asciidoctor"
|
26
|
-
spec.add_runtime_dependency "fontist", "~> 1.
|
26
|
+
spec.add_runtime_dependency "fontist", "~> 1.9"
|
27
27
|
spec.add_runtime_dependency "htmlentities"
|
28
28
|
spec.add_runtime_dependency "metanorma-utils", "~> 1.2.0"
|
29
29
|
spec.add_runtime_dependency "mn2pdf", "~> 1"
|
@@ -36,10 +36,11 @@ Gem::Specification.new do |spec|
|
|
36
36
|
|
37
37
|
spec.add_development_dependency "byebug", "~> 10.0"
|
38
38
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
39
|
-
spec.add_development_dependency "metanorma-iso", "~> 1.
|
39
|
+
spec.add_development_dependency "metanorma-iso", "~> 1.9.0"
|
40
40
|
spec.add_development_dependency "rake", "~> 13.0"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
42
42
|
spec.add_development_dependency "rspec-command", "~> 1.0"
|
43
43
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
44
44
|
spec.add_development_dependency "sassc", "~> 2.4.0"
|
45
|
+
spec.add_development_dependency "mnconvert"
|
45
46
|
end
|
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: 1.3.
|
4
|
+
version: 1.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: htmlentities
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
145
|
+
version: 1.9.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
152
|
+
version: 1.9.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rake
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: 2.4.0
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: mnconvert
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
223
237
|
description: Library to process any Metanorma standard.
|
224
238
|
email:
|
225
239
|
- open.source@ribose.com
|
@@ -286,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
300
|
requirements:
|
287
301
|
- - ">="
|
288
302
|
- !ruby/object:Gem::Version
|
289
|
-
version: 2.
|
303
|
+
version: 2.5.0
|
290
304
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
291
305
|
requirements:
|
292
306
|
- - ">="
|