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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40466d3eca9782461819ef5828d00dcdc4203e000cc0a6762e658ac75fab81c2
4
- data.tar.gz: ff68a9e27dd193c8e1263bcb1200f76d87eaf10363ef4c4eb32b9719e9b82eee
3
+ metadata.gz: 61f89a2c7a4e3b018425e87162e66fa5e1a8c20a4cf546ff477fd525be04e455
4
+ data.tar.gz: 3af3ca357995db324f7f8f844ff01a0651e0ba9c4fcd4c4f585c15baa4f33269
5
5
  SHA512:
6
- metadata.gz: 77388c12e9b2067cd0e319cdacc3ea914984e5185ce130ea5b6dbc893ab4d1d851294b7f3833811235b3952b50c98ad4830614c87a472dac9a26dc644b48f031
7
- data.tar.gz: 749c67ae8b9c967a0a2446847fb04fc9b045d5f42d4046a66aa79ce0abd5dc373545af2a1520559fa3fb0db4065a51aa2f043fcbe3007b84990ab89b99a286b9
6
+ metadata.gz: d8128a3b6b239af0af4e7cef15b5429ac3d4294c4407bcd618d22413ac49f98ee38dcba53c6e78604399321c059f33f93ee4a42d437b258cb5823e609936267c
7
+ data.tar.gz: 90bcc67a7a066eb8b84bd7abe26398d4cf7513fd8a804fa0cd60944d709ca8352ecfdbc94cc8a02c7d6e423cfddb9abc0754db3e2ecd1d54f3eb95fd64701e37
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "relaton"
4
2
  require "relaton/cli"
5
3
  require "metanorma-utils"
@@ -28,11 +26,16 @@ module Metanorma
28
26
  def initialize(**args)
29
27
  @file = args[:file]
30
28
  @dirname = File.expand_path(File.dirname(@file)) # feeds @manifest
31
- @documents = args[:documents] || {} # feeds initialize_directives
29
+ @documents = args[:documents] || {} # feeds initialize_directives, initialize_docs
32
30
  @bibdatas = args[:documents] || {}
33
31
  initialize_vars
34
32
  initialize_config(args[:config])
35
33
  initialize_directives
34
+ initialize_docs
35
+ validate_flavor(flavor)
36
+ end
37
+
38
+ def initialize_docs
36
39
  @documents.merge! @manifest.documents
37
40
  @bibdatas.merge! @manifest.documents
38
41
  @documents.transform_keys { |k| Util::key(k) }
@@ -53,12 +56,15 @@ module Metanorma
53
56
  @final = config.final_content
54
57
  @manifest = ::Metanorma::Collection::Manifest
55
58
  .new(config.manifest, self, @dirname) # feeds initialize_directives
59
+ @format = config.format.map(&:to_sym)
60
+ @format&.empty? and @format = nil
56
61
  end
57
62
 
58
63
  def initialize_directives
59
64
  d = @directives.each_with_object({}) { |x, m| m[x.key] = x.value }
60
65
  @coverpage = d["coverpage"]
61
66
  @coverpage_style = d["coverpage-style"]
67
+ @flavor = d["flavor"]
62
68
  if (@documents.any? || @manifest) && !d.key?("documents-inline") &&
63
69
  !d.key?("documents-external")
64
70
  @directives << ::Metanorma::Collection::Config::Directive
@@ -66,6 +72,10 @@ module Metanorma
66
72
  end
67
73
  end
68
74
 
75
+ def validate_flavor(flavor)
76
+ ::Metanorma::Compile.new.load_flavor(flavor)
77
+ end
78
+
69
79
  def clean_exit
70
80
  @log.write(File.join(@dirname,
71
81
  "#{File.basename(@file, '.*')}.err.html"))
@@ -82,7 +92,12 @@ module Metanorma
82
92
  end
83
93
 
84
94
  def render(opts)
85
- ::Metanorma::Collection::Renderer.render self, opts.merge(log: @log)
95
+ if opts[:format].nil? || opts[:format].empty?
96
+ opts[:format] = @format || [:html]
97
+ end
98
+ opts[:log] = @log
99
+ opts[:flavor] = @flavor
100
+ ::Metanorma::Collection::Renderer.render self, opts
86
101
  clean_exit
87
102
  end
88
103
 
@@ -102,7 +117,7 @@ module Metanorma
102
117
  # @param builder [Nokogiri::XML::Builder]
103
118
  def content_to_xml(elm, builder)
104
119
  (cnt = send(elm)) or return
105
- @compile.load_flavor(doctype)
120
+ @compile.load_flavor(flavor)
106
121
  out = sections(dummy_header + cnt.strip)
107
122
  builder.send("#{elm}-content") { |b| b << out }
108
123
  end
@@ -110,13 +125,19 @@ module Metanorma
110
125
  # @param cnt [String] prefatory/final content
111
126
  # @return [String] XML
112
127
  def sections(cnt)
113
- c = Asciidoctor.convert(cnt, backend: doctype.to_sym, header_footer: true)
114
- Nokogiri::XML(c, &:huge).at("//xmlns:sections").children.to_xml
128
+ c = Asciidoctor.convert(cnt, backend: flavor.to_sym, header_footer: true)
129
+ x = Nokogiri::XML(c)
130
+ x.xpath("//xmlns:clause").each { |n| n["unnumbered"] = true }
131
+ file = Tempfile.new(%w(foo presentation.xml))
132
+ file.write(x.to_xml(indent: 0))
133
+ file.close
134
+ c1 = Util::isodoc_create(@flavor, @manifest.lang, @manifest.script, x, presxml: true)
135
+ .convert(file.path, nil, true)
136
+ Nokogiri::XML(c1).at("//xmlns:sections").children.to_xml
115
137
  end
116
138
 
117
139
  # @param builder [Nokogiri::XML::Builder]
118
140
  def doccontainer(builder)
119
- # Array(@directives).include? "documents-inline" or return
120
141
  @directives.detect { |d| d.key == "documents-inline" } or return
121
142
  documents.each_with_index do |(_, d), i|
122
143
  doccontainer1(builder, d, i)
@@ -135,14 +156,19 @@ module Metanorma
135
156
  end
136
157
  end
137
158
 
138
- def doctype
139
- @doctype ||= fetch_doctype || "standoc"
159
+ def flavor
160
+ @flavor ||= fetch_flavor || "standoc"
140
161
  end
141
162
 
142
- def fetch_doctype
143
- docid = @bibdata.docidentifier.first
144
- docid or return
145
- docid.type&.downcase || docid.id&.sub(/\s.*$/, "")&.downcase
163
+ # TODO: retrieve flavor based on @bibdata publisher when lookup implemented
164
+ # Will still infer based on docid, but will validate it before proceeding
165
+ def fetch_flavor
166
+ docid = @bibdata.docidentifier.first or return
167
+ f = docid.type.downcase || docid.id.sub(/\s.*$/, "").downcase or return
168
+ require ::Metanorma::Compile.new.stdtype2flavor(f)
169
+ f
170
+ rescue LoadError
171
+ nil
146
172
  end
147
173
 
148
174
  class << self
@@ -188,6 +214,9 @@ module Metanorma
188
214
  # @param fileref [String]
189
215
  # @return [String]
190
216
  def resolve_fileref(ref_folder, fileref)
217
+ warn ref_folder
218
+ warn fileref
219
+ #require "debug"; binding.b
191
220
  unless @fileref_resolver
192
221
  (Pathname.new fileref).absolute? or
193
222
  fileref = File.join(ref_folder, fileref)
@@ -1,10 +1,10 @@
1
1
  require "relaton"
2
- require "shale"
2
+ require "lutaml/model"
3
3
 
4
4
  module Metanorma
5
5
  class Collection
6
6
  module Config
7
- class Bibdata < ::Shale::Mapper
7
+ class Bibdata < ::Lutaml::Model::Serializable
8
8
  model ::RelatonBib::BibliographicItem
9
9
  end
10
10
  end
@@ -1,12 +1,11 @@
1
- require "shale"
1
+ require "lutaml/model"
2
2
 
3
3
  module Metanorma
4
4
  class Collection
5
5
  module Config
6
- class CompileOptions < ::Shale::Mapper
7
- attribute :no_install_fonts, ::Shale::Type::Boolean,
8
- default: -> { true }
9
- attribute :agree_to_terms, ::Shale::Type::Boolean, default: -> { true }
6
+ class CompileOptions < ::Lutaml::Model::Serializable
7
+ attribute :install_fonts, :boolean, default: -> { false }
8
+ attribute :agree_to_terms, :boolean, default: -> { true }
10
9
  end
11
10
  end
12
11
  end
@@ -1,5 +1,4 @@
1
- require "shale"
2
- require_relative "../../shale_monkeypatch"
1
+ require "lutaml/model"
3
2
  require_relative "../../array_monkeypatch"
4
3
  require_relative "compile_options"
5
4
  require_relative "converters"
@@ -10,37 +9,35 @@ require_relative "manifest"
10
9
  module Metanorma
11
10
  class Collection
12
11
  module Config
13
- require "shale/adapter/nokogiri"
14
- ::Shale.xml_adapter = ::Shale::Adapter::Nokogiri
12
+ Lutaml::Model::Config.configure do |config|
13
+ config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
14
+ end
15
15
 
16
- class Config < ::Shale::Mapper
16
+ class Config < ::Lutaml::Model::Serializable
17
17
  attr_accessor :path, :collection, :from_xml
18
18
 
19
19
  attribute :bibdata, Bibdata
20
20
  attribute :directive, Directive, collection: true
21
21
  attribute :manifest, Manifest
22
- attribute :format, ::Shale::Type::String, collection: true,
23
- default: -> { [:html] }
24
- attribute :output_folder, ::Shale::Type::String
25
- attribute :coverpage, ::Shale::Type::String, default: -> {
26
- "cover.html"
27
- }
22
+ attribute :coverpage, :string, default: -> { "cover.html" }
23
+ attribute :format, :string, collection: true, default: -> { [:html] }
24
+ attribute :output_folder, :string
28
25
  attribute :compile, CompileOptions
29
- attribute :prefatory_content, ::Shale::Type::String
30
- attribute :final_content, ::Shale::Type::String
26
+ attribute :prefatory_content, :string, raw: true
27
+ attribute :final_content, :string, raw: true
31
28
  attribute :documents, Bibdata, collection: true
32
- attribute :xmlns, ::Shale::Type::String, default: -> { "http://metanorma.org" }
29
+ attribute :xmlns, :string, default: -> { "http://metanorma.org" }
33
30
 
34
31
  yaml do
35
- map "directives", using: { from: :directives_from_yaml,
36
- to: :directives_to_yaml }
37
- map "bibdata", using: { from: :bibdata_from_yaml,
38
- to: :bibdata_to_yaml }
32
+ map "directives", to: :directive, with: { from: :directives_from_yaml,
33
+ to: :directives_to_yaml }
34
+ map "bibdata", to: :bibdata, with: { from: :bibdata_from_yaml,
35
+ to: :bibdata_to_yaml }
39
36
  map "manifest", to: :manifest
40
- map "format", to: :format
37
+ map "format", to: :format, render_default: true
41
38
  map "output_folder", to: :output_folder
42
- map "coverpage", to: :coverpage
43
- map "compile", to: :compile
39
+ map "coverpage", to: :coverpage, render_default: true
40
+ map "compile", to: :compile, render_default: true
44
41
  map "prefatory-content", to: :prefatory_content
45
42
  map "final-content", to: :final_content
46
43
  end
@@ -49,23 +46,27 @@ module Metanorma
49
46
  root "metanorma-collection"
50
47
  # namespace "http://metanorma.org", "m"
51
48
  # map_attribute "xmlns", to: :xmlns
52
- map_element "bibdata", using: { from: :bibdata_from_xml,
53
- to: :bibdata_to_xml }
54
- map_element "directive", using: { from: :directive_from_xml,
55
- to: :directive_to_xml }
56
- map_element "entry", using: { from: :manifest_from_xml,
57
- to: :manifest_to_xml }
58
- map_element "format", to: :format
49
+ map_element "bibdata", to: :bibdata, with: { from: :bibdata_from_xml,
50
+ to: :bibdata_to_xml }
51
+ map_element "directive", to: :directive
52
+ map_element "entry", to: :manifest, with: { from: :manifest_from_xml,
53
+ to: :manifest_to_xml }
54
+ map_element "format", to: :format, render_default: true
59
55
  map_element "output_folder", to: :output_folder
60
- map_element "coverpage", to: :coverpage
61
- map_element "compile", to: :compile
62
- map_element "prefatory-content", using: { from: :prefatory_from_xml,
63
- to: :prefatory_to_xml }
56
+ map_element "coverpage", to: :coverpage, render_default: true
57
+ map_element "compile", to: :compile, render_default: true
58
+ map_element "prefatory-content",
59
+ to: :prefatory_content,
60
+ with: { from: :prefatory_from_xml,
61
+ to: :prefatory_to_xml }
64
62
  map_element "doc-container",
65
- using: { from: :documents_from_xml,
66
- to: :documents_to_xml }
67
- map_element "final-content", using: { from: :final_from_xml,
68
- to: :final_to_xml }
63
+ to: :documents,
64
+ with: { from: :documents_from_xml,
65
+ to: :documents_to_xml }
66
+ map_element "final-content",
67
+ to: :final_content,
68
+ with: { from: :final_from_xml,
69
+ to: :final_to_xml }
69
70
  end
70
71
 
71
72
  def manifest_from_xml(model, node)
@@ -78,7 +79,7 @@ module Metanorma
78
79
  end
79
80
 
80
81
  def prefatory_from_xml(model, node)
81
- model.prefatory_content = node.to_xml
82
+ model.prefatory_content = node.children.map(&:to_xml).join
82
83
  end
83
84
 
84
85
  def prefatory_to_xml(model, parent, doc)
@@ -92,7 +93,8 @@ module Metanorma
92
93
  def content_to_xml(model, parent, doc, type)
93
94
  x = model.send("#{type}_content") or return
94
95
  n = Nokogiri::XML(x)
95
- elem = if n.elements.size == 1 then n.root
96
+ elem = if n.elements.size == 1
97
+ "<#{type}-content>#{x}</#{type}-content>" # n.root
96
98
  else
97
99
  b = Nokogiri::XML::Builder.new
98
100
  model.collection.content_to_xml(type, b)
@@ -102,19 +104,7 @@ module Metanorma
102
104
  end
103
105
 
104
106
  def final_from_xml(model, node)
105
- model.final_content = node.to_xml
106
- end
107
-
108
- def directive_from_xml(model, node)
109
- model.directive ||= []
110
- model.directive << Directive.from_xml(node.to_xml)
111
- end
112
-
113
- def directive_to_xml(model, parent, doc)
114
- Array(model.directive).each do |e|
115
- elem = e.to_xml
116
- doc.add_element(parent, elem)
117
- end
107
+ model.final_content = node.children.map(&:to_xml).join
118
108
  end
119
109
 
120
110
  def directives_from_yaml(model, value)
@@ -134,28 +124,6 @@ module Metanorma
134
124
  end
135
125
  end
136
126
 
137
- def documents_from_xml(model, value)
138
- x = if value.is_a?(Shale::Adapter::Nokogiri::Node)
139
- value.content
140
- else Nokogiri::XML(value)
141
- end
142
- model.documents = x.xpath(".//bibdata")
143
- .each_with_object([]) do |b, m|
144
- m << Bibdata.from_xml(b.to_xml)
145
- end
146
- end
147
-
148
- def documents_to_xml(model, parent, doc)
149
- b = Nokogiri::XML::Builder.new do |xml|
150
- xml.document do |m|
151
- model.collection.doccontainer(m) or return
152
- end
153
- end
154
- b.parent.elements.first.elements.each do |x|
155
- doc.add_element(parent, x)
156
- end
157
- end
158
-
159
127
  include Converters
160
128
  end
161
129
  end
@@ -14,7 +14,8 @@ module Metanorma
14
14
  end
15
15
 
16
16
  def bibdata_from_xml(model, node)
17
- model.bibdata = Relaton::Cli.parse_xml(node.content)
17
+ node and
18
+ model.bibdata = Relaton::Cli.parse_xml(node.adapter_node)
18
19
  end
19
20
 
20
21
  def bibdata_to_xml(model, parent, doc)
@@ -24,6 +25,31 @@ module Metanorma
24
25
  end
25
26
 
26
27
  def nop_to_yaml(model, doc); end
28
+
29
+ def documents_from_xml(model, value)
30
+ model.documents = value
31
+ .each_with_object([]) do |b, m|
32
+ m << b
33
+ end
34
+ end
35
+
36
+ def documents_to_xml(model, parent, doc)
37
+ documents_to_xml?(doc) or return
38
+ b = Nokogiri::XML::Builder.new do |xml|
39
+ xml.document do |m|
40
+ model.collection.doccontainer(m) or return
41
+ end
42
+ end
43
+ b.parent.elements.first.elements
44
+ .each { |x| doc.add_element(parent, x) }
45
+ end
46
+
47
+ def documents_to_xml?(doc)
48
+ ret = doc.parent.elements.detect do |x|
49
+ x.name == "doc-container"
50
+ end
51
+ !ret
52
+ end
27
53
  end
28
54
  end
29
55
  end
@@ -1,9 +1,15 @@
1
1
  module Metanorma
2
2
  class Collection
3
3
  module Config
4
- class Directive < ::Shale::Mapper
5
- attribute :key, ::Shale::Type::String
6
- attribute :value, ::Shale::Type::String
4
+ class Directive < ::Lutaml::Model::Serializable
5
+ attribute :key, :string
6
+ attribute :value, :string
7
+
8
+ xml do
9
+ root "directive"
10
+ map_element "key", to: :key
11
+ map_element "value", to: :value
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -1,5 +1,5 @@
1
- require "shale"
2
- require_relative "../../shale_monkeypatch"
1
+ require "lutaml/model"
2
+ require "lutaml/model/xml_adapter/nokogiri_adapter"
3
3
  require_relative "../../array_monkeypatch"
4
4
  require_relative "converters"
5
5
  require_relative "bibdata"
@@ -7,59 +7,65 @@ require_relative "bibdata"
7
7
  module Metanorma
8
8
  class Collection
9
9
  module Config
10
- require "shale/adapter/nokogiri"
11
- ::Shale.xml_adapter = ::Shale::Adapter::Nokogiri
10
+ Lutaml::Model::Config.configure do |config|
11
+ config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
12
+ end
12
13
 
13
- class Manifest < ::Shale::Mapper
14
- attribute :identifier, ::Shale::Type::String,
15
- default: -> { UUIDTools::UUID.random_create.to_s }
16
- attribute :id, ::Shale::Type::String
14
+ class Manifest < ::Lutaml::Model::Serializable
15
+ attribute :identifier, :string,
16
+ default: -> { UUIDTools::UUID.random_create.to_s }
17
+ attribute :id, :string
17
18
  attribute :bibdata, Bibdata
18
- attribute :type, ::Shale::Type::String
19
- attribute :title, ::Shale::Type::String
20
- attribute :url, ::Shale::Type::String
21
- attribute :attachment, ::Shale::Type::Boolean
22
- attribute :sectionsplit, ::Shale::Type::Boolean
23
- attribute :index, ::Shale::Type::Boolean, default: -> { true }
19
+ attribute :type, :string
20
+ attribute :title, :string
21
+ attribute :url, :string
22
+ attribute :level, :string
23
+ attribute :attachment, :boolean
24
+ attribute :sectionsplit, :boolean
25
+ attribute :index, :boolean, default: -> { true }
24
26
  attribute :entry, Manifest, collection: true
25
- attribute :file, ::Shale::Type::String
27
+ attribute :file, :string
26
28
 
27
29
  yaml do
28
30
  map "identifier", to: :identifier
29
31
  map "type", to: :type
30
- map "level", using: { from: :level_from_yaml, to: :nop_to_yaml }
32
+ map "level", to: :level,
33
+ with: { from: :level_from_yaml, to: :nop_to_yaml }
31
34
  map "title", to: :title
32
35
  map "url", to: :url
33
36
  map "attachment", to: :attachment
34
37
  map "sectionsplit", to: :sectionsplit
35
38
  map "index", to: :index
36
39
  map "file", to: :file
37
- map "fileref", using: { from: :fileref_from_yaml, to: :nop_to_yaml }
40
+ map "fileref", to: :file,
41
+ with: { from: :fileref_from_yaml, to: :nop_to_yaml }
38
42
  map "entry", to: :entry
39
- map "docref", using: { from: :docref_from_yaml, to: :nop_to_yaml }
40
- map "manifest", using: { from: :docref_from_yaml, to: :nop_to_yaml }
41
- map "bibdata", using: { from: :bibdata_from_yaml,
42
- to: :bibdata_to_yaml }
43
+ map "docref", to: :entry,
44
+ with: { from: :docref_from_yaml, to: :nop_to_yaml }
45
+ map "manifest", to: :entry,
46
+ with: { from: :docref_from_yaml, to: :nop_to_yaml }
47
+ map "bibdata", to: :bibdata, with: { from: :bibdata_from_yaml,
48
+ to: :bibdata_to_yaml }
43
49
  end
44
50
 
45
51
  xml do
46
52
  root "entry"
47
- map_attribute "id", to: :id
53
+ map_attribute "target", to: :id
48
54
  map_attribute "attachment", to: :attachment
49
55
  map_attribute "sectionsplit", to: :sectionsplit
50
56
  map_attribute "index", to: :index
51
57
  map_attribute "url", to: :url
52
58
  map_attribute "fileref", to: :file
53
- map_element "identifier", to: :identifier
59
+ map_element "identifier", to: :identifier, render_default: true
54
60
  map_element "type", to: :type
55
61
  map_element "title", to: :title
56
- map_element "bibdata", using: { from: :bibdata_from_xml,
57
- to: :bibdata_to_xml }
58
- map_element "entry", to: :entry # using: { from: :entry_from_xml, to: :entry_to_xml }
62
+ map_element "bibdata", to: :bibdata, with: { from: :bibdata_from_xml,
63
+ to: :bibdata_to_xml }
64
+ map_element "entry", to: :entry
59
65
  end
60
66
 
61
67
  def entry_from_xml(model, node)
62
- model.entry = Manifest.from_xml(node.content)
68
+ model.entry = Manifest.from_xml(node.node.to_xml)
63
69
  end
64
70
 
65
71
  def entry_to_xml(model, parent, doc)
@@ -1,3 +1,5 @@
1
+ require "relaton-cli"
2
+
1
3
  module Metanorma
2
4
  class Collection
3
5
  class Document
@@ -48,16 +50,16 @@ module Metanorma
48
50
 
49
51
  def mn2relaton_parser(tag)
50
52
  case tag.sub(/-standard/, "")
51
- when "bipm" then RelatonBipm::XMLParser
52
- when "bsi" then RelatonBsi::XMLParser
53
- when "ietf" then RelatonIetf::XMLParser
54
- when "iho" then RelatonIho::XMLParser
55
- when "itu" then RelatonItu::XMLParser
56
- when "iec" then RelatonIec::XMLParser
57
- when "iso" then RelatonIsoBib::XMLParser
58
- when "nist" then RelatonNist::XMLParser
59
- when "ogc" then RelatonOgc::XMLParser
60
- else RelatonBib::XMLParser
53
+ when "bipm" then ::RelatonBipm::XMLParser
54
+ when "bsi" then ::RelatonBsi::XMLParser
55
+ when "ietf" then ::RelatonIetf::XMLParser
56
+ when "iho" then ::RelatonIho::XMLParser
57
+ when "itu" then ::RelatonItu::XMLParser
58
+ when "iec" then ::RelatonIec::XMLParser
59
+ when "iso" then ::RelatonIsoBib::XMLParser
60
+ when "nist" then ::RelatonNist::XMLParser
61
+ when "ogc" then ::RelatonOgc::XMLParser
62
+ else ::RelatonBib::XMLParser
61
63
  end
62
64
  end
63
65
 
@@ -62,12 +62,24 @@ module Metanorma
62
62
  file, _filename = targetfile(entry, read: true)
63
63
  xml = Nokogiri::XML(file, &:huge)
64
64
  add_document_suffix(ident, xml)
65
- entry.merge!(anchors: read_anchors(xml), ids: read_ids(xml),
66
- bibdata: xml.at(ns("//bibdata")),
67
- document_suffix: xml.root["document_suffix"])
65
+ entry.merge!(bibdata_extract(xml))
68
66
  end
69
67
  end
70
68
 
69
+ def anchors_lookup(anchors)
70
+ anchors.values.each_with_object({}) do |v, m|
71
+ v.each_value { |v1| m[v1] = true }
72
+ end
73
+ end
74
+
75
+ def bibdata_extract(xml)
76
+ anchors = read_anchors(xml)
77
+ { anchors: anchors, anchors_lookup: anchors_lookup(anchors),
78
+ ids: read_ids(xml),
79
+ bibdata: xml.at(ns("//bibdata")),
80
+ document_suffix: xml.root["document_suffix"] }
81
+ end
82
+
71
83
  def bibitem_process(entry)
72
84
  entry[:bibitem] = entry[:bibdata].dup
73
85
  entry[:bibitem].name = "bibitem"
@@ -76,7 +88,7 @@ module Metanorma
76
88
  end
77
89
 
78
90
  # ref is the absolute source file address
79
- # rel_path is the relative source file address, relative to the YAML locaton
91
+ # rel_path is the relative source file address, relative to the YAML location
80
92
  # out_path is the destination file address, with any references outside
81
93
  # the working directory (../../...) truncated, and based on relative path
82
94
  # identifier is the id with only spaces, no nbsp
@@ -104,15 +116,15 @@ module Metanorma
104
116
  %w(attachment sectionsplit index presentation-xml url
105
117
  bare-after-first).each do |s|
106
118
  ref.respond_to?(s.to_sym) and
107
- ret[s.gsub("-", "").to_sym] = ref.send(s)
119
+ ret[s.delete("-").to_sym] = ref.send(s)
108
120
  end
109
121
  end
110
122
 
111
123
  def add_document_suffix(identifier, doc)
112
124
  document_suffix = Metanorma::Utils::to_ncname(identifier)
113
- Metanorma::Utils::anchor_attributes.each do |(tag_name, attribute_name)|
114
- Util::add_suffix_to_attributes(doc, document_suffix, tag_name,
115
- attribute_name, @isodoc)
125
+ Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
126
+ Util::add_suffix_to_attrs(doc, document_suffix, tag_name, attr_name,
127
+ @isodoc)
116
128
  end
117
129
  url_in_css_styles(doc, document_suffix)
118
130
  doc.root["document_suffix"] ||= ""
@@ -123,7 +135,7 @@ module Metanorma
123
135
  def url_in_css_styles(doc, document_suffix)
124
136
  doc.xpath("//*[@style]").each do |s|
125
137
  s["style"] = s["style"]
126
- .gsub(%r{url\(#([^)]+)\)}, "url(#\\1_#{document_suffix})")
138
+ .gsub(%r{url\(#([^()]+)\)}, "url(#\\1_#{document_suffix})")
127
139
  end
128
140
  end
129
141
 
@@ -198,10 +210,10 @@ module Metanorma
198
210
  ret[val[:type]] ||= {}
199
211
  index = if val[:container] || val[:label].nil? || val[:label].empty?
200
212
  UUIDTools::UUID.random_create.to_s
201
- else val[:label]
213
+ else val[:label].gsub(%r{<[^>]+>}, "")
202
214
  end
203
215
  ret[val[:type]][index] = key
204
- ret[val[:type]][val[:value]] = key if val[:value]
216
+ v = val[:value] and ret[val[:type]][v.gsub(%r{<[^>]+>}, "")] = key
205
217
  end
206
218
 
207
219
  # Also parse all ids in doc (including ones which won't be xref targets)
@@ -216,8 +228,8 @@ module Metanorma
216
228
  end
217
229
 
218
230
  def key(ident)
219
- @c.decode(ident).gsub(/(\p{Zs})+/, " ").sub(/^metanorma-collection /,
220
- "")
231
+ @c.decode(ident).gsub(/(\p{Zs})+/, " ")
232
+ .sub(/^metanorma-collection /, "")
221
233
  end
222
234
 
223
235
  def keys