metanorma 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40466d3eca9782461819ef5828d00dcdc4203e000cc0a6762e658ac75fab81c2
4
- data.tar.gz: ff68a9e27dd193c8e1263bcb1200f76d87eaf10363ef4c4eb32b9719e9b82eee
3
+ metadata.gz: 92e4b253c6c10fcce6aee6e827adec6281f79cd0e72e2ee84696af2bc288d0b1
4
+ data.tar.gz: 6bf08b8a123331df15d3ad9fc62d61b31ce3c53208cd14252830fee11c1b8977
5
5
  SHA512:
6
- metadata.gz: 77388c12e9b2067cd0e319cdacc3ea914984e5185ce130ea5b6dbc893ab4d1d851294b7f3833811235b3952b50c98ad4830614c87a472dac9a26dc644b48f031
7
- data.tar.gz: 749c67ae8b9c967a0a2446847fb04fc9b045d5f42d4046a66aa79ce0abd5dc373545af2a1520559fa3fb0db4065a51aa2f043fcbe3007b84990ab89b99a286b9
6
+ metadata.gz: 9cda0f7b08169d3d9bb7aef6f25a372882f561310f5cf8913cae241398b83acae2c8d160be3d6ec1aa924a030e49d4058f2b42ff7f404c6ff8c4d906d8c126ec
7
+ data.tar.gz: 810ef3dd1033bcb57e7d097647dc5fa5f360310b15bf0e62d0056d62e67c2d290ec13c68720b0e080e1bc08ed5d13093928fb785c963ee276f9248c6473cf913
@@ -82,6 +82,7 @@ module Metanorma
82
82
  end
83
83
 
84
84
  def render(opts)
85
+ opts[:format].nil? || opts[:format].empty? and opts[:format] = [:html]
85
86
  ::Metanorma::Collection::Renderer.render self, opts.merge(log: @log)
86
87
  clean_exit
87
88
  end
@@ -25,7 +25,7 @@ module Metanorma
25
25
  update_direct_refs_to_docs(xml, docid)
26
26
  hide_refs(xml)
27
27
  sso and eref2link(xml)
28
- svgmap_resolve(xml, docid)
28
+ @nested or svgmap_resolve(xml, docid)
29
29
  xml.to_xml
30
30
  end
31
31
 
@@ -59,13 +59,6 @@ module Metanorma
59
59
  doclist
60
60
  end
61
61
 
62
- def new_hidden_ref(xmldoc)
63
- ins = xmldoc.at(ns("bibliography")) or
64
- xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
65
- ins.at(ns("./referenced[@hidden = 'true']")) or
66
- ins.add_child("<references hidden='true' normative='false'/>").first
67
- end
68
-
69
62
  def eref2link(docxml)
70
63
  isodoc = IsoDoc::PresentationXMLConvert.new({})
71
64
  isodoc.bibitem_lookup(docxml)
@@ -86,20 +79,36 @@ module Metanorma
86
79
  end
87
80
  end
88
81
 
82
+ def svg_datauri(docxml, docid)
83
+ rel = @files.get(docid, :rel_path)
84
+ parent = @files.get(docid, :parentid) and
85
+ rel = @files.get(parent, :rel_path)
86
+ # if sectionsplit, use orig file dir
87
+ dir = File.join(@dirname, File.dirname(rel))
88
+ datauri_encode(docxml, dir)
89
+ end
90
+
89
91
  def svgmap_resolve(docxml, docid)
90
92
  ids = @files.get(docid, :ids)
91
- dir = File.join(@dirname, File.dirname(@files.get(docid, :rel_path)))
92
- docxml = datauri_encode(docxml, dir)
93
+ docxml = svg_unnest(svg_datauri(docxml, docid))
93
94
  isodoc = IsoDoc::PresentationXMLConvert.new({})
94
95
  isodoc.bibitem_lookup(docxml)
95
96
  docxml.xpath(ns("//svgmap//eref")).each do |e|
96
- svgmap_resolve1(e, isodoc, docxml, ids)
97
+ svgmap_resolve_eref(e, isodoc, docxml, ids)
97
98
  end
98
99
  Vectory::SvgMapping.new(docxml, "").call
99
100
  docxml.xpath(ns("//svgmap")).each { |s| isodoc.svgmap_extract(s) }
100
101
  end
101
102
 
102
- def svgmap_resolve1(eref, isodoc, _docxml, ids)
103
+ def svg_unnest(docxml)
104
+ docxml.xpath(ns("//svgmap//image[.//*[name() = 'image']]")).each do |i|
105
+ s = i.elements.detect { |e| e.name == "svg" } and
106
+ i.replace(s)
107
+ end
108
+ docxml
109
+ end
110
+
111
+ def svgmap_resolve_eref(eref, isodoc, _docxml, ids)
103
112
  href = isodoc.eref_target(eref) or return
104
113
  href == "##{eref['bibitemid']}" ||
105
114
  (href =~ /^#/ && !ids[href.sub(/^#/, "")]) and return
@@ -189,9 +198,8 @@ module Metanorma
189
198
  @updated_anchors[anchor] = true
190
199
  end
191
200
 
192
- def update_indirect_refs_to_docs_docid(bibitem, file)
193
- docid = bibitem&.at(ns("./docidentifier[@type = 'repository']")) or
194
- return
201
+ def update_indirect_refs_to_docs_docid(bib, file)
202
+ docid = bib&.at(ns("./docidentifier[@type = 'repository']")) or return
195
203
  docid.children = "current-metanorma-collection/#{file}"
196
204
  docid.previous =
197
205
  "<docidentifier type='metanorma-collection'>#{file}</docidentifier>"
@@ -237,9 +245,8 @@ module Metanorma
237
245
  type = ins.at(ns("./locality/@type"))&.text
238
246
  type = "clause" if type == "annex"
239
247
  ref = ins.at(ns("./locality/referenceFrom"))&.text
240
- anchor = @files.get(docid, :anchors).dig(type, ref) or return
241
- ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/,
242
- '')}" \
248
+ a = @files.get(docid, :anchors).dig(type, ref) or return
249
+ ins << "<locality type='anchor'><referenceFrom>#{a.sub(/^_/, '')}" \
243
250
  "</referenceFrom></locality>"
244
251
  end
245
252
  end
@@ -51,7 +51,8 @@ module Metanorma
51
51
  out = out.relative_path_from(File.expand_path(FileUtils.pwd))
52
52
  dest = File.join(@outdir, @disambig.source2dest_filename(out.to_s))
53
53
  FileUtils.mkdir_p(File.dirname(dest))
54
- FileUtils.cp @files.get(identifier, :ref), dest
54
+ source = @files.get(identifier, :ref)
55
+ source != dest and FileUtils.cp source, dest
55
56
  end
56
57
 
57
58
  # process each file in the collection
@@ -3,7 +3,7 @@ module Metanorma
3
3
  class Renderer
4
4
  def dir_name_cleanse(name)
5
5
  path = Pathname.new(name)
6
- clean_regex = /[<>:"|?*]/
6
+ clean_regex = /[<>:"|?*\p{Zs}]/
7
7
  fallback_sym = "_"
8
8
  return name.gsub(clean_regex, fallback_sym) unless path.absolute?
9
9
 
@@ -40,6 +40,13 @@ module Metanorma
40
40
  end
41
41
  end
42
42
 
43
+ def new_hidden_ref(xmldoc)
44
+ ins = xmldoc.at(ns("bibliography")) or
45
+ xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
46
+ ins.at(ns("./referenced[@hidden = 'true']")) or
47
+ ins.add_child("<references hidden='true' normative='false'/>").first
48
+ end
49
+
43
50
  def strip_eref(eref)
44
51
  eref.xpath(ns("./locality | ./localityStack")).each(&:remove)
45
52
  eref.replace(eref.children)
@@ -119,11 +126,32 @@ module Metanorma
119
126
 
120
127
  def datauri_encode(docxml, directory)
121
128
  docxml.xpath(ns("//image")).each do |i|
129
+ read_in_if_svg(i, directory.sub(%r{(?<!=/)$}, "/")) and i["src"] = nil
130
+ end
131
+ docxml.xpath(ns("//image")).each do |i| # rubocop:disable Style/CombinableLoops
132
+ i["src"] && !i["src"].empty? or next
122
133
  i["src"] = Vectory::Utils::datauri(i["src"], directory)
123
134
  end
124
135
  docxml
125
136
  end
126
137
 
138
+ def read_in_if_svg(img, localdir)
139
+ img["src"] or return false
140
+ img.elements.map(&:name).include?("svg") and return true
141
+ path = Vectory::Utils.svgmap_rewrite0_path(img["src"], localdir)
142
+ svg = svg_in_path?(path) or return false
143
+ img.children = (Nokogiri::XML(svg).root)
144
+ true
145
+ end
146
+
147
+ def svg_in_path?(path)
148
+ File.file?(path) or return false
149
+ types = MIME::Types.type_for(path) or return false
150
+ types.first == "image/svg+xml" or return false
151
+ svg = File.read(path, encoding: "utf-8") or return false
152
+ svg
153
+ end
154
+
127
155
  class PdfOptionsNode
128
156
  def initialize(doctype, options)
129
157
  p = Metanorma::Registry.instance.find_processor(doctype)
@@ -66,7 +66,6 @@ module Metanorma
66
66
  ["//indexsect", nil], ["//colophon", nil]].freeze
67
67
 
68
68
  # Input XML is Semantic
69
- # def sectionsplit(filename, basename, dir, compile_options, fileslookup = nil, ident = nil)
70
69
  def sectionsplit
71
70
  xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
72
71
  @key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
@@ -96,14 +95,15 @@ module Metanorma
96
95
 
97
96
  def sectionsplit_prep(file, filename, dir)
98
97
  @splitdir = dir
99
- xml1filename, type = sectionsplit_preprocess_semxml(file, filename)
100
- Compile.new.compile(
101
- xml1filename,
102
- { format: :asciidoc, extension_keys: [:presentation], type: type }
103
- .merge(@compile_opts),
104
- )
105
- Nokogiri::XML(File.read(xml1filename.sub(/\.xml$/, ".presentation.xml"),
106
- encoding: "utf-8"), &:huge)
98
+ xml1, type = sectionsplit_preprocess_semxml(file, filename)
99
+ flags = { format: :asciidoc, extension_keys: [:presentation],
100
+ type: type }.merge(@compile_opts)
101
+ Compile.new.compile(xml1, flags)
102
+ f = File.open(xml1.sub(/\.xml$/, ".presentation.xml"),
103
+ encoding: "utf-8")
104
+ r = Nokogiri::XML(f, &:huge)
105
+ r.xpath("//xmlns:svgmap1").each { |x| x.name = "svgmap" }
106
+ r
107
107
  end
108
108
 
109
109
  def sectionsplit_preprocess_semxml(file, filename)
@@ -111,9 +111,7 @@ module Metanorma
111
111
  type = xml.root.name.sub("-standard", "").to_sym
112
112
  sectionsplit_update_xrefs(xml)
113
113
  xml1 = sectionsplit_write_semxml(filename, xml)
114
- @filecache ||= []
115
- @filecache << xml1
116
- [xml1.path, type]
114
+ [xml1, type]
117
115
  end
118
116
 
119
117
  def sectionsplit_update_xrefs(xml)
@@ -122,15 +120,17 @@ module Metanorma
122
120
  c.nested = true # so unresolved erefs are not deleted
123
121
  c.update_xrefs(xml, @ident, {})
124
122
  c.nested = n
123
+ xml.xpath("//xmlns:svgmap").each { |x| x.name = "svgmap1" }
124
+ # do not process svgmap until after files are split
125
125
  end
126
126
  end
127
127
 
128
128
  def sectionsplit_write_semxml(filename, xml)
129
- Tempfile.open([filename, ".xml"], encoding: "utf-8") do |f|
130
- # f.write(@isodoc.to_xml(svg_preprocess(xml)))
129
+ outname = Pathname.new("tmp_#{filename}").sub_ext(".xml").to_s
130
+ File.open(outname, "w:UTF-8") do |f|
131
131
  f.write(@isodoc.to_xml(xml))
132
- f
133
132
  end
133
+ outname
134
134
  end
135
135
 
136
136
  def emptydoc(xml)
@@ -152,7 +152,8 @@ module Metanorma
152
152
  def create_sectionfile(xml, out, file, chunks, parentnode)
153
153
  ins = out.at(ns("//metanorma-extension")) || out.at(ns("//bibdata"))
154
154
  sectionfile_insert(ins, chunks, parentnode)
155
- Metanorma::Collection::XrefProcess::xref_process(out, xml, @key, @ident, @isodoc)
155
+ Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
156
+ @ident, @isodoc)
156
157
  outname = "#{file}.xml"
157
158
  File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
158
159
  f.write(out)
@@ -149,7 +149,8 @@ module Metanorma
149
149
  if ext == :rxl
150
150
  relaton_export(isodoc, options.merge(relaton: fnames[:out]))
151
151
  elsif options[:passthrough_presentation_xml] && ext == :presentation
152
- f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
152
+ #f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
153
+ f = File.exist?(fnames[:orig_filename]) ? fnames[:orig_filename] : fnames[:f]
153
154
  FileUtils.cp f, fnames[:presentationxml]
154
155
  elsif ext == :html && options[:sectionsplit]
155
156
  sectionsplit_convert(fnames[:xml], isodoc, fnames[:out],
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.0.1".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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-04 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor