metanorma 1.6.3 → 1.6.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca433d59b111534c114a96b7ce386ccf0267a70cedcbfbe61ef11cf2f42737d3
4
- data.tar.gz: c1a73eb056acb7910d255c8348273dd9abf79dd06ef4826ac3ab3d5474543242
3
+ metadata.gz: abbc191b2e898bbeeea46f7867bb9d25d44cfd7f9a0dd2c690fcbdb8383136fd
4
+ data.tar.gz: a9e184662fcf25a575c278d604440b8215fd7b54b76f980a4cf4bfd5f8a1f543
5
5
  SHA512:
6
- metadata.gz: 2e57292cdc5217cb985be7beb617035ee8edcfb0c9ee3c38cd2c6dc49e71c63468c05d3e6c3000985e93e94a4313f7cf77b24a24c4affe80778f3727c3c7a5b8
7
- data.tar.gz: b1a33f6b99669f384af4426cf75e3052f480c0878ec9f1d5716661bc5340e228273f6993930aacba3b1bfe6da7f166791718b0c02c0c71440f83d8642e019355
6
+ metadata.gz: bfc28efd7f7f48f0bfd7dfa630bf88f1186006022dc6d5f82f188a3749304bc73837c9e96dd9246655de67f2b1ee29d9525f49c2ba568e2116d4329bf3689bda
7
+ data.tar.gz: 40bc185f4dbe9b4570349e22a15334a2e3fb089dfe3002ab43cb4a8ffa4afe4f2a3ae8357f80e61d585a57ab3b64e24dd5fb2700241dd6f1b958693214afdbc6
@@ -58,10 +58,10 @@ module Metanorma
58
58
  update_indirect_refs_to_docs(docxml, internal_refs)
59
59
  ids = @files.get(identifier, :ids)
60
60
  @files.add_document_suffix(identifier, docxml)
61
- svgmap_resolve(datauri_encode(docxml), ids)
62
61
  update_direct_refs_to_docs(docxml, identifier)
63
62
  hide_refs(docxml)
64
63
  @files.get(identifier, :sectionsplit_output) and eref2link(docxml)
64
+ svgmap_resolve(datauri_encode(docxml), ids)
65
65
  docxml.to_xml
66
66
  end
67
67
 
@@ -98,12 +98,12 @@ module Metanorma
98
98
  svgmap_resolve1(e, isodoc, docxml, ids)
99
99
  end
100
100
  Metanorma::Utils::svgmap_rewrite(docxml, "")
101
+ docxml.xpath(ns("//svgmap")).each { |s| isodoc.svgmap_extract(s) }
101
102
  end
102
103
 
103
104
  def svgmap_resolve1(eref, isodoc, _docxml, ids)
104
105
  href = isodoc.eref_target(eref)
105
106
  return if href == "##{eref['bibitemid']}" ||
106
- # (href =~ /^#/ && !docxml.at("//*[@id = '#{href.sub(/^#/, '')}']"))
107
107
  (href =~ /^#/ && !ids[href.sub(/^#/, "")])
108
108
 
109
109
  eref["target"] = href.strip
@@ -157,7 +157,6 @@ module Metanorma
157
157
 
158
158
  def update_indirect_refs_to_docs1(_docxml, key, file, bibitems, erefs)
159
159
  erefs[key]&.each do |e|
160
- # docxml.xpath(ns("//eref[@bibitemid = '#{key}']")).each do |e|
161
160
  e["citeas"] = file
162
161
  a = e.at(ns(".//locality[@type = 'anchor']/referenceFrom")) and
163
162
  a.children = "#{a.text}_#{Metanorma::Utils::to_ncname(file)}"
@@ -172,7 +171,6 @@ module Metanorma
172
171
  # update crossrefences to other documents, to include
173
172
  # disambiguating document suffix on id
174
173
  def update_anchors(bib, docid, erefs)
175
- #docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
176
174
  erefs.each do |e|
177
175
  if @files.get(docid) then update_anchor_loc(bib, e, docid)
178
176
  else
@@ -1,6 +1,7 @@
1
1
  require "isodoc"
2
2
  require "htmlentities"
3
3
  require "metanorma-utils"
4
+ require_relative "files_lookup_sectionsplit"
4
5
 
5
6
  module Metanorma
6
7
  # XML collection renderer
@@ -58,64 +59,6 @@ module Metanorma
58
59
  entry[:bibitem].at("./*[local-name() = 'ext']")&.remove
59
60
  end
60
61
 
61
- def add_section_split
62
- ret = @files.keys.each_with_object({}) do |k, m|
63
- if @files[k][:sectionsplit] == "true" && !@files[k]["attachment"]
64
- s, manifest = sectionsplit(@files[k][:ref], k)
65
- s.each_with_index { |f1, i| add_section_split_instance(f1, m, k, i) }
66
- m["#{k}:index.html"] = add_section_split_cover(manifest, k)
67
- @files_to_delete << m["#{k}:index.html"][:ref]
68
- end
69
- m[k] = @files[k]
70
- end
71
- @files = ret
72
- end
73
-
74
- def add_section_split_cover(manifest, ident)
75
- cover = @sectionsplit.section_split_cover(manifest,
76
- @parent.dir_name_cleanse(ident))
77
- @files[ident][:out_path] = cover
78
- { attachment: true, index: false, out_path: cover,
79
- ref: File.join(File.dirname(manifest.file), cover) }
80
- end
81
-
82
- def add_section_split_instance(file, manifest, key, idx)
83
- presfile, newkey, xml =
84
- add_section_split_instance_prep(file, key)
85
- manifest[newkey] =
86
- { parentid: key, presentationxml: true, type: "fileref",
87
- rel_path: file[:url], out_path: File.basename(file[:url]),
88
- anchors: read_anchors(xml), ids: read_ids(xml),
89
- sectionsplit_output: true,
90
- bibdata: @files[key][:bibdata], ref: presfile }
91
- @files_to_delete << file[:url]
92
- manifest[newkey][:bare] = true unless idx.zero?
93
- end
94
-
95
- def add_section_split_instance_prep(file, key)
96
- presfile = File.join(File.dirname(@files[key][:ref]),
97
- File.basename(file[:url]))
98
- newkey = key("#{key.strip} #{file[:title]}")
99
- xml = Nokogiri::XML(File.read(presfile), &:huge)
100
- [presfile, newkey, xml]
101
- end
102
-
103
- def sectionsplit(file, ident)
104
- @sectionsplit =
105
- Sectionsplit.new(input: file, base: File.basename(file), dir: File.dirname(file),
106
- output: file, compile_options: @parent.compile_options,
107
- fileslookup: self, ident: ident, isodoc: @isodoc)
108
- coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
109
- # s = @compile.sectionsplit(file, File.basename(file), File.dirname(file),
110
- # @parent.compile_options, self, ident)
111
- # .sort_by { |f| f[:order] }
112
- # xml = Nokogiri::XML(File.read(file, encoding: "UTF-8")) { |x| x.huge }
113
- xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
114
- [coll, @sectionsplit
115
- .collection_manifest(File.basename(file), coll, xml, nil,
116
- File.dirname(file))]
117
- end
118
-
119
62
  # rel_path is the source file address, determined relative to the YAML.
120
63
  # out_path is the destination file address, with any references outside
121
64
  # the working directory (../../...) truncated
@@ -0,0 +1,69 @@
1
+ module Metanorma
2
+ # XML collection renderer
3
+ class FileLookup
4
+ def add_section_split
5
+ ret = @files.keys.each_with_object({}) do |k, m|
6
+ if @files[k][:sectionsplit] == "true" && !@files[k]["attachment"]
7
+ s, manifest = sectionsplit(@files[k][:ref], k)
8
+ s.each_with_index { |f1, i| add_section_split_instance(f1, m, k, i) }
9
+ m["#{k}:index.html"] = add_section_split_cover(manifest, k)
10
+ @files_to_delete << m["#{k}:index.html"][:ref]
11
+ end
12
+ m[k] = @files[k]
13
+ end
14
+ @files = ret
15
+ end
16
+
17
+ def add_section_split_cover(manifest, ident)
18
+ cover = @sectionsplit
19
+ .section_split_cover(manifest, @parent.dir_name_cleanse(ident),
20
+ one_doc_collection?)
21
+ @files[ident][:out_path] = cover
22
+ { attachment: true, index: false, out_path: cover,
23
+ ref: File.join(File.dirname(manifest.file), cover) }
24
+ end
25
+
26
+ def one_doc_collection?
27
+ docs = 0
28
+ @files.each_value do |v|
29
+ v[:attachment] and next
30
+ v[:presentationxml] and next
31
+ docs += 1
32
+ end
33
+ docs > 1
34
+ end
35
+
36
+ def add_section_split_instance(file, manifest, key, idx)
37
+ presfile, newkey, xml =
38
+ add_section_split_instance_prep(file, key)
39
+ manifest[newkey] =
40
+ { parentid: key, presentationxml: true, type: "fileref",
41
+ rel_path: file[:url], out_path: File.basename(file[:url]),
42
+ anchors: read_anchors(xml), ids: read_ids(xml),
43
+ sectionsplit_output: true,
44
+ bibdata: @files[key][:bibdata], ref: presfile }
45
+ @files_to_delete << file[:url]
46
+ manifest[newkey][:bare] = true unless idx.zero?
47
+ end
48
+
49
+ def add_section_split_instance_prep(file, key)
50
+ presfile = File.join(File.dirname(@files[key][:ref]),
51
+ File.basename(file[:url]))
52
+ newkey = key("#{key.strip} #{file[:title]}")
53
+ xml = Nokogiri::XML(File.read(presfile), &:huge)
54
+ [presfile, newkey, xml]
55
+ end
56
+
57
+ def sectionsplit(file, ident)
58
+ @sectionsplit = Sectionsplit
59
+ .new(input: file, base: File.basename(file), dir: File.dirname(file),
60
+ output: file, compile_options: @parent.compile_options,
61
+ fileslookup: self, ident: ident, isodoc: @isodoc)
62
+ coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
63
+ xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
64
+ [coll, @sectionsplit
65
+ .collection_manifest(File.basename(file), coll, xml, nil,
66
+ File.dirname(file))]
67
+ end
68
+ end
69
+ end
@@ -109,7 +109,8 @@ module Metanorma
109
109
  type = xml.root.name.sub("-standard", "").to_sym
110
110
  @fileslookup&.parent&.update_xrefs(xml, @ident, {})
111
111
  xml1 = Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
112
- f.write(@isodoc.to_xml(svg_preprocess(xml)))
112
+ #f.write(@isodoc.to_xml(svg_preprocess(xml)))
113
+ f.write(@isodoc.to_xml((xml)))
113
114
  f
114
115
  end
115
116
  @filecache ||= []
@@ -184,17 +185,17 @@ module Metanorma
184
185
  Util::recursive_string_keys(ret).to_yaml
185
186
  end
186
187
 
187
- def section_split_cover(col, ident)
188
+ def section_split_cover(col, ident, one_doc_coll)
188
189
  dir = File.dirname(col.file)
189
190
  collection_setup(nil, dir)
190
191
  CollectionRenderer.new(col, dir,
191
192
  output_folder: "#{ident}_collection",
192
193
  format: %i(html),
193
194
  coverpage: File.join(dir, "cover.html")).coverpage
194
- FileUtils.mv "#{ident}_collection/index.html",
195
- File.join(dir, "#{ident}_index.html")
195
+ filename = one_doc_coll ? "#{ident}_index.html" : "index.html"
196
+ FileUtils.mv "#{ident}_collection/index.html", File.join(dir, filename)
196
197
  FileUtils.rm_rf "#{ident}_collection"
197
- "#{ident}_index.html"
198
+ filename
198
199
  end
199
200
  end
200
201
  end
@@ -1,12 +1,13 @@
1
1
  module Metanorma
2
2
  class Sectionsplit
3
- def xref_preprocess(xml, fileslookup, identifier)
3
+ def xref_preprocess(xml, _fileslookup, _identifier)
4
4
  key = (0...8).map { rand(65..90).chr }.join # random string
5
5
  xml.root["type"] = key # to force recognition of internal refs
6
6
  key
7
7
  end
8
8
 
9
9
  def xref_process(section, xml, key)
10
+ svg_preprocess(section, Metanorma::Utils::to_ncname(@ident))
10
11
  refs = eref_to_internal_eref(section, xml, key)
11
12
  refs += xref_to_internal_eref(section, key)
12
13
  ins = new_hidden_ref(section)
@@ -14,15 +15,14 @@ module Metanorma
14
15
  insert_indirect_biblio(ins, refs - copied_refs, key)
15
16
  end
16
17
 
17
- def svg_preprocess(xml)
18
+ def svg_preprocess(xml, document_suffix)
18
19
  xml.xpath("//m:svg", "m" => "http://www.w3.org/2000/svg").each do |s|
19
20
  m = svgmap_wrap(s)
20
21
  s.xpath(".//m:a", "m" => "http://www.w3.org/2000/svg").each do |a|
21
- next unless /^#/.match? a["href"]
22
-
22
+ /^#/.match? a["href"] or next
23
23
  a["href"] = a["href"].sub(/^#/, "")
24
24
  m << "<target href='#{a['href']}'>" \
25
- "<xref target='#{a['href']}'/></target>"
25
+ "<xref target='#{a['href']}_#{document_suffix}'/></target>"
26
26
  end
27
27
  end
28
28
  xml
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.6.3".freeze
2
+ VERSION = "1.6.4".freeze
3
3
  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.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -269,6 +269,7 @@ files:
269
269
  - lib/metanorma/document.rb
270
270
  - lib/metanorma/extract.rb
271
271
  - lib/metanorma/files_lookup.rb
272
+ - lib/metanorma/files_lookup_sectionsplit.rb
272
273
  - lib/metanorma/fontist_utils.rb
273
274
  - lib/metanorma/input.rb
274
275
  - lib/metanorma/input/asciidoc.rb