metanorma 2.0.0 → 2.1.2

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/collection/collection.rb +43 -14
  3. data/lib/metanorma/collection/config/bibdata.rb +2 -2
  4. data/lib/metanorma/collection/config/compile_options.rb +4 -5
  5. data/lib/metanorma/collection/config/config.rb +41 -73
  6. data/lib/metanorma/collection/config/converters.rb +27 -1
  7. data/lib/metanorma/collection/config/directive.rb +9 -3
  8. data/lib/metanorma/collection/config/manifest.rb +33 -27
  9. data/lib/metanorma/collection/document/document.rb +12 -10
  10. data/lib/metanorma/collection/filelookup/filelookup.rb +25 -13
  11. data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +57 -20
  12. data/lib/metanorma/collection/manifest/manifest.rb +22 -10
  13. data/lib/metanorma/collection/multilingual/multilingual.rb +660 -0
  14. data/lib/metanorma/collection/renderer/fileparse.rb +119 -104
  15. data/lib/metanorma/collection/renderer/fileprocess.rb +6 -2
  16. data/lib/metanorma/collection/renderer/navigation.rb +1 -1
  17. data/lib/metanorma/collection/renderer/render_word.rb +8 -7
  18. data/lib/metanorma/collection/renderer/renderer.rb +41 -20
  19. data/lib/metanorma/collection/renderer/svg.rb +52 -0
  20. data/lib/metanorma/collection/renderer/utils.rb +55 -18
  21. data/lib/metanorma/collection/sectionsplit/collection.rb +100 -0
  22. data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +104 -101
  23. data/lib/metanorma/collection/util/util.rb +25 -10
  24. data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +42 -28
  25. data/lib/metanorma/compile/compile.rb +12 -2
  26. data/lib/metanorma/compile/compile_options.rb +2 -0
  27. data/lib/metanorma/compile/compile_validate.rb +4 -4
  28. data/lib/metanorma/compile/extract.rb +2 -4
  29. data/lib/metanorma/input/asciidoc.rb +11 -30
  30. data/lib/metanorma/registry/registry.rb +2 -2
  31. data/lib/metanorma/version.rb +1 -1
  32. data/metanorma.gemspec +5 -4
  33. metadata +41 -25
  34. data/lib/metanorma/shale_monkeypatch.rb +0 -15
@@ -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)
@@ -48,11 +55,12 @@ module Metanorma
48
55
  def docid_to_citeas(bib)
49
56
  docid = bib.at(ns("./docidentifier[@primary = 'true']")) ||
50
57
  bib.at(ns("./docidentifier")) or return
51
- docid_prefix(docid)
58
+ ::Metanorma::Collection::Util::key(docid_prefix(docid))
52
59
  end
53
60
 
54
- def collect_erefs(docxml)
55
- docxml.xpath(ns("//eref"))
61
+ def collect_erefs(docxml, presxml)
62
+ tag = presxml ? "fmt-eref" : "eref"
63
+ docxml.xpath(ns("//#{tag}"))
56
64
  .each_with_object({ citeas: {}, bibitemid: {} }) do |i, m|
57
65
  m[:citeas][i["citeas"]] = true
58
66
  m[:bibitemid][i["bibitemid"]] = true
@@ -104,9 +112,9 @@ module Metanorma
104
112
  end
105
113
 
106
114
  def pdfconv
107
- doctype = @doctype.to_sym
108
- x = Asciidoctor.load nil, backend: doctype
109
- x.converter.pdf_converter(PdfOptionsNode.new(doctype,
115
+ flavor = @flavor.to_sym
116
+ x = Asciidoctor.load nil, backend: flavor
117
+ x.converter.pdf_converter(PdfOptionsNode.new(flavor,
110
118
  @compile_options))
111
119
  end
112
120
 
@@ -119,14 +127,35 @@ module Metanorma
119
127
 
120
128
  def datauri_encode(docxml, directory)
121
129
  docxml.xpath(ns("//image")).each do |i|
130
+ read_in_if_svg(i, directory.sub(%r{(?<!=/)$}, "/")) and i["src"] = nil
131
+ end
132
+ docxml.xpath(ns("//image")).each do |i| # rubocop:disable Style/CombinableLoops
133
+ i["src"] && !i["src"].empty? or next
122
134
  i["src"] = Vectory::Utils::datauri(i["src"], directory)
123
135
  end
124
136
  docxml
125
137
  end
126
138
 
139
+ def read_in_if_svg(img, localdir)
140
+ img["src"] or return false
141
+ img.elements.map(&:name).include?("svg") and return true
142
+ path = Vectory::Utils.svgmap_rewrite0_path(img["src"], localdir)
143
+ svg = svg_in_path?(path) or return false
144
+ img.children = (Nokogiri::XML(svg).root)
145
+ true
146
+ end
147
+
148
+ def svg_in_path?(path)
149
+ File.file?(path) or return false
150
+ types = MIME::Types.type_for(path) or return false
151
+ types.first == "image/svg+xml" or return false
152
+ svg = File.read(path, encoding: "utf-8") or return false
153
+ svg
154
+ end
155
+
127
156
  class PdfOptionsNode
128
- def initialize(doctype, options)
129
- p = Metanorma::Registry.instance.find_processor(doctype)
157
+ def initialize(flavor, options)
158
+ p = Metanorma::Registry.instance.find_processor(flavor)
130
159
  if ::Metanorma::Util::FontistHelper.has_custom_fonts?(p, options, {})
131
160
  @fonts_manifest =
132
161
  ::Metanorma::Util::FontistHelper.location_manifest(p, options)
@@ -140,21 +169,13 @@ module Metanorma
140
169
  end
141
170
  end
142
171
 
143
- def isodoc_create
144
- isodoc = Util::load_isodoc(@doctype)
145
- isodoc.i18n_init(@lang, @script, @locale) # read in internationalisation
146
- isodoc.metadata_init(@lang, @script, @locale, isodoc.i18n)
147
- isodoc.info(@xml, nil)
148
- isodoc
149
- end
150
-
151
172
  # create the @meta class of isodoc, for populating Liquid,
152
173
  # with "navigation" set to the index bar.
153
174
  # extracted from the manifest
154
175
  def isodoc_populate
155
176
  @isodoc.info(@xml, nil)
156
177
  { navigation: indexfile(@manifest), nav_object: index_object(@manifest),
157
- docrefs: liquid_docrefs(@manifest),
178
+ bibdata: @bibdata.to_hash, docrefs: liquid_docrefs(@manifest),
158
179
  "prefatory-content": isodoc_builder(@xml.at("//prefatory-content")),
159
180
  "final-content": isodoc_builder(@xml.at("//final-content")),
160
181
  doctitle: @bibdata.title.first.title.content,
@@ -175,6 +196,22 @@ module Metanorma
175
196
  end.doc.root.to_html
176
197
  end
177
198
 
199
+ def eref2link(docxml, presxml)
200
+ isodoc = IsoDoc::PresentationXMLConvert.new({})
201
+ isodoc.bibitem_lookup(docxml)
202
+ isodoc.eref2link(docxml)
203
+ end
204
+
205
+ def error_anchor(erefs, docid)
206
+ erefs.each do |e|
207
+ msg = "<strong>** Unresolved reference to document #{docid} " \
208
+ "from eref</strong>"
209
+ e << msg
210
+ strip_eref(e)
211
+ @log&.add("Cross-References", e, msg)
212
+ end
213
+ end
214
+
178
215
  def ns(xpath)
179
216
  @isodoc.ns(xpath)
180
217
  end
@@ -0,0 +1,100 @@
1
+ module Metanorma
2
+ class Collection
3
+ class Sectionsplit
4
+ def build_collection
5
+ collection_setup(@base, @dir)
6
+ files = sectionsplit
7
+ input_xml = Nokogiri::XML(File.read(@input_filename,
8
+ encoding: "UTF-8"), &:huge)
9
+ collection_manifest(@base, files, input_xml, @xml, @dir).render(
10
+ { format: %i(html), output_folder: "#{@output_filename}_collection",
11
+ coverpage: File.join(@dir, "cover.html") }.merge(@compile_opts),
12
+ )
13
+ section_split_attachments(out: "#{@output_filename}_collection")
14
+ end
15
+
16
+ def collection_setup(filename, dir)
17
+ FileUtils.mkdir_p "#{filename}_collection" if filename
18
+ FileUtils.mkdir_p dir
19
+ File.open(File.join(dir, "cover.html"), "w:UTF-8") do |f|
20
+ f.write(coll_cover)
21
+ end
22
+ end
23
+
24
+ def coll_cover
25
+ <<~COVER
26
+ <html><head><meta charset="UTF-8"/></head><body>
27
+ <h1>{{ doctitle }}</h1>
28
+ <h2>{{ docnumber }}</h2>
29
+ <nav>{{ navigation }}</nav>
30
+ </body></html>
31
+ COVER
32
+ end
33
+
34
+ def collection_manifest(filename, files, origxml, _presxml, dir)
35
+ File.open(File.join(dir, "#{filename}.html.yaml"), "w:UTF-8") do |f|
36
+ f.write(collectionyaml(files, origxml))
37
+ end
38
+ Metanorma::Collection.parse File.join(dir, "#{filename}.html.yaml")
39
+ end
40
+
41
+ def collectionyaml(files, xml)
42
+ ret = {
43
+ directives: ["presentation-xml", "bare-after-first"],
44
+ bibdata: {
45
+ title: {
46
+ type: "title-main", language: @lang,
47
+ content: xml.at(ns("//bibdata/title")).text
48
+ },
49
+ type: "collection",
50
+ docid: {
51
+ type: xml.at(ns("//bibdata/docidentifier/@type")).text,
52
+ id: xml.at(ns("//bibdata/docidentifier")).text,
53
+ },
54
+ },
55
+ manifest: {
56
+ level: "collection", title: "Collection",
57
+ docref: files.sort_by { |f| f[:order] }.each.map do |f|
58
+ { fileref: f[:url], identifier: f[:title] }
59
+ end
60
+ },
61
+ }
62
+ ::Metanorma::Util::recursive_string_keys(ret).to_yaml
63
+ end
64
+
65
+ def att_dir(file)
66
+ "_#{File.basename(file, '.*')}_attachments"
67
+ end
68
+
69
+ def section_split_attachments(out: nil)
70
+ attachments = att_dir(@tmp_filename)
71
+ File.directory?(attachments) or return
72
+ dir = out || File.dirname(@input_filename)
73
+ ret = File.join(dir, att_dir(@output_filename))
74
+ FileUtils.rm_rf ret
75
+ FileUtils.mv attachments, ret
76
+ File.basename(ret)
77
+ end
78
+
79
+ def section_split_cover(col, ident, one_doc_coll)
80
+ dir = File.dirname(col.file)
81
+ collection_setup(nil, dir)
82
+ r = ::Metanorma::Collection::Renderer
83
+ .new(col, dir, output_folder: "#{ident}_collection",
84
+ format: %i(html),
85
+ coverpage: File.join(dir, "cover.html"))
86
+ r.coverpage
87
+ section_split_cover1(ident, r, dir, one_doc_coll)
88
+ end
89
+
90
+ def section_split_cover1(ident, renderer, dir, _one_doc_coll)
91
+ filename = File.basename("#{ident}_index.html")
92
+ # ident can be a directory with YAML indirection
93
+ dest = File.join(dir, filename)
94
+ FileUtils.mv File.join(renderer.outdir, "index.html"), dest
95
+ FileUtils.rm_rf renderer.outdir
96
+ filename
97
+ end
98
+ end
99
+ end
100
+ end
@@ -1,6 +1,8 @@
1
1
  require "yaml"
2
2
  require_relative "../../util/util"
3
3
  require_relative "../xrefprocess/xrefprocess"
4
+ require_relative "collection"
5
+ require "concurrent-ruby"
4
6
 
5
7
  module Metanorma
6
8
  class Collection
@@ -17,48 +19,13 @@ module Metanorma
17
19
  @fileslookup = opts[:fileslookup]
18
20
  @ident = opts[:ident]
19
21
  @isodoc = opts[:isodoc]
22
+ @document_suffix = opts[:document_suffix]
20
23
  end
21
24
 
22
25
  def ns(xpath)
23
26
  @isodoc.ns(xpath)
24
27
  end
25
28
 
26
- def build_collection
27
- collection_setup(@base, @dir)
28
- files = sectionsplit # (@input_filename, @base, @dir, @compile_opts)
29
- input_xml = Nokogiri::XML(File.read(@input_filename,
30
- encoding: "UTF-8"), &:huge)
31
- collection_manifest(@base, files, input_xml, @xml, @dir).render(
32
- { format: %i(html), output_folder: "#{@output_filename}_collection",
33
- coverpage: File.join(@dir, "cover.html") }.merge(@compile_opts),
34
- )
35
- end
36
-
37
- def collection_manifest(filename, files, origxml, _presxml, dir)
38
- File.open(File.join(dir, "#{filename}.html.yaml"), "w:UTF-8") do |f|
39
- f.write(collectionyaml(files, origxml))
40
- end
41
- Metanorma::Collection.parse File.join(dir, "#{filename}.html.yaml")
42
- end
43
-
44
- def collection_setup(filename, dir)
45
- FileUtils.mkdir_p "#{filename}_collection" if filename
46
- FileUtils.mkdir_p dir
47
- File.open(File.join(dir, "cover.html"), "w:UTF-8") do |f|
48
- f.write(coll_cover)
49
- end
50
- end
51
-
52
- def coll_cover
53
- <<~COVER
54
- <html><head><meta charset="UTF-8"/></head><body>
55
- <h1>{{ doctitle }}</h1>
56
- <h2>{{ docnumber }}</h2>
57
- <nav>{{ navigation }}</nav>
58
- </body></html>
59
- COVER
60
- end
61
-
62
29
  SPLITSECTIONS =
63
30
  [["//preface/*", "preface"], ["//sections/*", "sections"],
64
31
  ["//annex", nil],
@@ -66,21 +33,41 @@ module Metanorma
66
33
  ["//indexsect", nil], ["//colophon", nil]].freeze
67
34
 
68
35
  # Input XML is Semantic
69
- # def sectionsplit(filename, basename, dir, compile_options, fileslookup = nil, ident = nil)
70
36
  def sectionsplit
71
37
  xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
72
38
  @key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
73
- SPLITSECTIONS.each_with_object([]) do |n, ret|
39
+ empty = empty_doc(xml)
40
+ empty1 = empty_attachments(empty)
41
+ @mutex = Mutex.new
42
+ #@pool = Concurrent::FixedThreadPool.new(4)
43
+ @pool = Concurrent::FixedThreadPool.new(1)
44
+ sectionsplit1(xml, empty, empty1, 0)
45
+ end
46
+
47
+ def sectionsplit1(xml, empty, empty1, idx)
48
+ ret = SPLITSECTIONS.each_with_object([]) do |n, m|
74
49
  conflate_floatingtitles(xml.xpath(ns(n[0]))).each do |s|
75
- ret << sectionfile(xml, emptydoc(xml), "#{@base}.#{ret.size}", s,
76
- n[1])
50
+ sectionsplit2(xml, idx.zero? ? empty : empty1, s, n[1],
51
+ { acc: m, idx: idx })
52
+ idx += 1
77
53
  end
78
54
  end
55
+ @pool.shutdown
56
+ @pool.wait_for_termination
57
+ ret
58
+ end
59
+
60
+ def sectionsplit2(xml, empty, chunks, parentnode, opt)
61
+ @pool.post do
62
+ a = sectionfile(xml, empty, "#{@base}.#{opt[:idx]}", chunks,
63
+ parentnode)
64
+ @mutex.synchronize { opt[:acc] << a }
65
+ end
79
66
  end
80
67
 
81
68
  def block?(node)
82
69
  %w(p table formula admonition ol ul dl figure quote sourcecode example
83
- pre note pagebrreak hr bookmark requirement recommendation permission
70
+ pre note pagebreak hr bookmark requirement recommendation permission
84
71
  svgmap inputform toc passthrough review imagemap).include?(node.name)
85
72
  end
86
73
 
@@ -96,53 +83,79 @@ module Metanorma
96
83
 
97
84
  def sectionsplit_prep(file, filename, dir)
98
85
  @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)
86
+ xml, type = sectionsplit_preprocess_semxml(file, filename)
87
+ flags = { format: :asciidoc, extension_keys: [:presentation],
88
+ type: type }.merge(@compile_opts)
89
+ #require "debug"; binding.b
90
+ Compile.new.compile(xml, flags)
91
+ f = File.open(xml.sub(/\.xml$/, ".presentation.xml"), encoding: "utf-8")
92
+ r = Nokogiri::XML(f, &:huge)
93
+ f.close
94
+ r.xpath("//xmlns:svgmap1").each { |x| x.name = "svgmap" }
95
+ r
107
96
  end
108
97
 
109
98
  def sectionsplit_preprocess_semxml(file, filename)
110
99
  xml = Nokogiri::XML(file, &:huge)
111
- type = xml.root.name.sub("-standard", "").to_sym
100
+ type = xml.root["flavor"]
101
+ type ||= xml.root.name.sub("-standard", "").to_sym
112
102
  sectionsplit_update_xrefs(xml)
113
103
  xml1 = sectionsplit_write_semxml(filename, xml)
114
- @filecache ||= []
115
- @filecache << xml1
116
- [xml1.path, type]
104
+ @tmp_filename = xml1
105
+ [xml1, type]
117
106
  end
118
107
 
119
108
  def sectionsplit_update_xrefs(xml)
120
109
  if c = @fileslookup&.parent
121
110
  n = c.nested
122
111
  c.nested = true # so unresolved erefs are not deleted
112
+ #require "debug"; binding.b
123
113
  c.update_xrefs(xml, @ident, {})
124
114
  c.nested = n
115
+ xml.xpath("//xmlns:svgmap").each { |x| x.name = "svgmap1" }
116
+ # do not process svgmap until after files are split
125
117
  end
126
118
  end
127
119
 
128
120
  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)))
121
+ outname = Pathname.new("tmp_#{filename}").sub_ext(".xml").to_s
122
+ File.open(outname, "w:UTF-8") do |f|
131
123
  f.write(@isodoc.to_xml(xml))
132
- f
133
124
  end
125
+ outname
126
+ end
127
+
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
134
139
  end
135
140
 
136
- def emptydoc(xml)
141
+ def empty_doc(xml)
137
142
  out = xml.dup
138
143
  out.xpath(
139
144
  ns("//preface | //sections | //annex | //bibliography/clause | " \
140
- "//bibliography/references[not(@hidden = 'true')] | //indexsect | " \
141
- "//colophon"),
145
+ "//bibliography/references[not(@hidden = 'true')] | " \
146
+ "//indexsect | //colophon"),
142
147
  ).each(&:remove)
143
148
  out
144
149
  end
145
150
 
151
+ def empty_attachments(xml)
152
+ out = xml.dup
153
+ out.xpath(ns("//metanorma-ext//attachment | " \
154
+ "//semantic__metanorma-ext//semantic__attachment"))
155
+ .each(&:remove) # keep only one copy of attachments
156
+ out
157
+ end
158
+
146
159
  def sectionfile(fulldoc, xml, file, chunks, parentnode)
147
160
  fname = create_sectionfile(fulldoc, xml.dup, file, chunks, parentnode)
148
161
  { order: chunks.last["displayorder"].to_i, url: fname,
@@ -151,8 +164,11 @@ module Metanorma
151
164
 
152
165
  def create_sectionfile(xml, out, file, chunks, parentnode)
153
166
  ins = out.at(ns("//metanorma-extension")) || out.at(ns("//bibdata"))
167
+ #require "debug"; binding.b
154
168
  sectionfile_insert(ins, chunks, parentnode)
155
- Metanorma::Collection::XrefProcess::xref_process(out, xml, @key, @ident, @isodoc)
169
+ Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
170
+ @ident, @isodoc, true)
171
+ #truncate_semxml(out, chunks)
156
172
  outname = "#{file}.xml"
157
173
  File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
158
174
  f.write(out)
@@ -160,6 +176,31 @@ module Metanorma
160
176
  outname
161
177
  end
162
178
 
179
+ # KILL
180
+ def semantic_xml_ids_gather(out)
181
+ out.at(ns("//semantic__bibdata")) or return
182
+ SPLITSECTIONS.each_with_object({}) do |s, m|
183
+ out.xpath(ns(s[0].sub("//", "//semantic__"))).each do |x|
184
+ x["id"] or next
185
+ m[x["id"].sub(/^semantic__/, "")] = x
186
+ end
187
+ end
188
+ end
189
+
190
+ # KILL
191
+ def semxml_presxml_nodes_match(nodes, chunks)
192
+ chunks.each do |x|
193
+ nodes[x["id"]] and nodes.delete(x["id"])
194
+ end
195
+ end
196
+
197
+ # KILL
198
+ def truncate_semxml(out, chunks)
199
+ nodes = semantic_xml_ids_gather(out) or return
200
+ semxml_presxml_nodes_match(nodes, chunks)
201
+ nodes.each_value(&:remove)
202
+ end
203
+
163
204
  def sectionfile_insert(ins, chunks, parentnode)
164
205
  if parentnode
165
206
  ins.next = "<#{parentnode}/>"
@@ -169,49 +210,11 @@ module Metanorma
169
210
  end
170
211
 
171
212
  def titlerender(section)
172
- title = section.at(ns("./title")) or return "[Untitled]"
213
+ title = section.at(ns("./fmt-title")) or return "[Untitled]"
173
214
  t = title.dup
174
215
  t.xpath(ns(".//tab | .//br")).each { |x| x.replace(" ") }
175
- t.xpath(ns(".//strong")).each { |x| x.replace(x.children) }
176
- t.children.to_xml
177
- end
178
-
179
- def collectionyaml(files, xml)
180
- ret = {
181
- directives: ["presentation-xml", "bare-after-first"],
182
- bibdata: {
183
- title: {
184
- type: "title-main", language: @lang,
185
- content: xml.at(ns("//bibdata/title")).text
186
- },
187
- type: "collection",
188
- docid: {
189
- type: xml.at(ns("//bibdata/docidentifier/@type")).text,
190
- id: xml.at(ns("//bibdata/docidentifier")).text,
191
- },
192
- },
193
- manifest: {
194
- level: "collection", title: "Collection",
195
- docref: files.sort_by { |f| f[:order] }.each.map do |f|
196
- { fileref: f[:url], identifier: f[:title] }
197
- end
198
- },
199
- }
200
- ::Metanorma::Util::recursive_string_keys(ret).to_yaml
201
- end
202
-
203
- def section_split_cover(col, ident, _one_doc_coll)
204
- dir = File.dirname(col.file)
205
- collection_setup(nil, dir)
206
- r = ::Metanorma::Collection::Renderer
207
- .new(col, dir, output_folder: "#{ident}_collection",
208
- format: %i(html), coverpage: File.join(dir, "cover.html"))
209
- r.coverpage
210
- # filename = one_doc_coll ? "#{ident}_index.html" : "index.html"
211
- filename = File.basename("#{ident}_index.html") # ident can be a directory with YAML indirection
212
- FileUtils.mv File.join(r.outdir, "index.html"), File.join(dir, filename)
213
- FileUtils.rm_rf r.outdir
214
- filename
216
+ t.xpath(ns(".//bookmark")).each(&:remove)
217
+ t.xpath('.//text()').map(&:text).join
215
218
  end
216
219
  end
217
220
  end
@@ -14,24 +14,26 @@ module Metanorma
14
14
  end
15
15
  end
16
16
 
17
- def gather_bibitemids(xml)
17
+ def gather_bibitemids(xml, presxml)
18
18
  xml.xpath("//*[@bibitemid]").each_with_object({}) do |e, m|
19
- /^semantic__/.match?(e.name) and next
19
+ #/^semantic__/.match?(e.name) and next
20
+ presxml && %w(xref eref link).include?(e.name) and next
20
21
  m[e["bibitemid"]] ||= []
21
22
  m[e["bibitemid"]] << e
22
23
  end
23
24
  end
24
25
 
25
- def gather_citeases(xml)
26
+ def gather_citeases(xml, presxml)
26
27
  xml.xpath("//*[@citeas]").each_with_object({}) do |e, m|
27
- /^semantic__/.match?(e.name) and next
28
- m[e["citeas"]] ||= []
29
- m[e["citeas"]] << e
28
+ #/^semantic__/.match?(e.name) and next
29
+ presxml && %w(xref eref link).include?(e.name) and next
30
+ k = key(e["citeas"])
31
+ m[k] ||= []
32
+ m[k] << e
30
33
  end
31
34
  end
32
35
 
33
- def add_suffix_to_attributes(doc, suffix, tag_name, attr_name,
34
- isodoc)
36
+ def add_suffix_to_attrs(doc, suffix, tag_name, attr_name, isodoc)
35
37
  (suffix.nil? || suffix.empty?) and return
36
38
  doc.xpath(isodoc.ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
37
39
  a = elem.attributes[attr_name].value
@@ -62,10 +64,23 @@ isodoc)
62
64
  def attr(_key); end
63
65
  end
64
66
 
65
- def load_isodoc(doctype)
66
- x = Asciidoctor.load nil, backend: doctype.to_sym
67
+ def load_isodoc(flavor, presxml: false)
68
+ x = Asciidoctor.load nil, backend: flavor.to_sym
69
+ if presxml
70
+ x.converter.presentation_xml_converter(Dummy.new)
71
+ else
67
72
  x.converter.html_converter(Dummy.new) # to obtain Isodoc class
73
+ end
68
74
  end
75
+
76
+ def isodoc_create(flavor, lang, script, xml, presxml: false)
77
+ isodoc = Util::load_isodoc(flavor, presxml: presxml)
78
+ isodoc.i18n_init(lang, script, nil) # read in internationalisation
79
+ # TODO locale?
80
+ isodoc.metadata_init(lang, script, nil, isodoc.i18n)
81
+ isodoc.info(xml, nil)
82
+ isodoc
83
+ end
69
84
  end
70
85
  end
71
86
  end