metanorma-standoc 1.2.4 → 1.3.0

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: 06176e145f12bd799593297fca5b0820ae94de9b676f4b1003f4450fb1a6148e
4
- data.tar.gz: 45a4c760ebed46439988ad8117cb4ce4dfe2fbddcd30c927b1283f52fbcb0049
3
+ metadata.gz: 3549faf588ef5ac25ac0f5fc7793fb1b8ec5f43b0e1cf6782c8db9858583b023
4
+ data.tar.gz: 191776185cad00c0691dab60a744a7d41cac34276b118d3440a4697e5f969043
5
5
  SHA512:
6
- metadata.gz: 1c3a0df087934b281540c6ea2c64097fa156f549c9ce69d4a29c5ab5d1b2cc75ad6513196e21740c7ae61820e7b6d92dd074253856801438c254bb858689c646
7
- data.tar.gz: 95e186a6532958595ab9796dd369155e4ddbc7217a6f64ba7865ad5d4acba5736593aa636ad17e59ab400eb350d1b6b9f223790dd83ecafdb9c80ca9a8e1712e
6
+ metadata.gz: 44ae4a1c90f48a83a4d727d28534736d7c714a8abc3b6cf85f2eadab0c4834a8d47d61e852e1070301c50044677aeb774e74dc1eeb99b106d9e35ae7ce13d4c4
7
+ data.tar.gz: 698b0a2f29a7c4739234307995ef89da77185d1dd1d4da7511c8036f043f91a0d7ad6fc19eb2df9abf76fd31e712f2ea1a23a9136a1494c6749b3663aef40009
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- metanorma-standoc (1.2.4)
4
+ metanorma-standoc (1.3.0)
5
5
  asciidoctor (~> 1.5.7)
6
6
  concurrent-ruby
7
7
  html2doc (~> 0.8.11)
8
8
  iev (~> 0.2.1)
9
- isodoc (~> 0.10.0)
9
+ isodoc (~> 1.0.0)
10
10
  relaton (~> 0.5.0)
11
11
  relaton-iev (~> 0.1.0)
12
12
  ruby-jing
@@ -65,7 +65,7 @@ GEM
65
65
  iev (0.2.2)
66
66
  nokogiri
67
67
  image_size (2.0.2)
68
- isodoc (0.10.4)
68
+ isodoc (1.0.0)
69
69
  asciimath
70
70
  html2doc (~> 0.8.11)
71
71
  htmlentities (~> 4.3.4)
@@ -94,7 +94,7 @@ GEM
94
94
  mime-types-data (3.2019.0331)
95
95
  mini_portile2 (2.4.0)
96
96
  nenv (0.3.0)
97
- nokogiri (1.10.3)
97
+ nokogiri (1.10.4)
98
98
  mini_portile2 (~> 2.4.0)
99
99
  notiffany (0.1.3)
100
100
  nenv (~> 0.1)
@@ -113,16 +113,15 @@ GEM
113
113
  rb-fsevent (0.10.3)
114
114
  rb-inotify (0.10.0)
115
115
  ffi (~> 1.0)
116
- relaton (0.5.0)
116
+ relaton (0.5.2)
117
117
  algoliasearch
118
118
  relaton-gb (~> 0.6.0)
119
119
  relaton-iec (~> 0.4.0)
120
120
  relaton-ietf (~> 0.6.0)
121
121
  relaton-iso (~> 0.6.0)
122
- relaton-iso-bib (~> 0.3.0)
123
122
  relaton-itu (~> 0.3.0)
124
123
  relaton-nist (~> 0.3.0)
125
- relaton-bib (0.3.3)
124
+ relaton-bib (0.3.5)
126
125
  addressable
127
126
  nokogiri (~> 1.10)
128
127
  relaton-gb (0.6.1)
@@ -132,20 +131,20 @@ GEM
132
131
  relaton-iec (0.4.2)
133
132
  addressable
134
133
  relaton-iso-bib (~> 0.3.0)
135
- relaton-ietf (0.6.1)
134
+ relaton-ietf (0.6.2)
136
135
  relaton-bib (~> 0.3.0)
137
136
  relaton-iev (0.1.1)
138
137
  relaton (~> 0.5.0)
139
- relaton-iso (0.6.2)
138
+ relaton-iso (0.6.3)
140
139
  relaton-iec (~> 0.4.0)
141
140
  relaton-iso-bib (~> 0.3.0)
142
- relaton-iso-bib (0.3.2)
141
+ relaton-iso-bib (0.3.4)
143
142
  isoics (~> 0.1.6)
144
143
  relaton-bib (~> 0.3.0)
145
144
  ruby_deep_clone (~> 0.8.0)
146
- relaton-itu (0.3.0)
145
+ relaton-itu (0.3.2)
147
146
  relaton-iso-bib (~> 0.3.0)
148
- relaton-nist (0.3.0)
147
+ relaton-nist (0.3.2)
149
148
  relaton-bib (~> 0.3.0)
150
149
  rubyzip
151
150
  roman-numerals (0.3.0)
@@ -176,9 +175,8 @@ GEM
176
175
  ruby_dep (1.5.0)
177
176
  rubyzip (1.2.3)
178
177
  safe_yaml (1.0.5)
179
- sassc (2.0.1)
178
+ sassc (2.1.0)
180
179
  ffi (~> 1.9)
181
- rake
182
180
  shellany (0.0.1)
183
181
  simplecov (0.17.0)
184
182
  docile (~> 1.1)
@@ -116,8 +116,10 @@ module Asciidoctor
116
116
 
117
117
  def init_iev_caches(node)
118
118
  unless (@no_isobib_cache || @no_isobib)
119
- @iev_globalname = global_ievcache_name unless node.attr("local-cache-only")
120
- @iev_localname = local_ievcache_name(node.attr("local-cache") || node.attr("local-cache-only"))
119
+ node.attr("local-cache-only") or
120
+ @iev_globalname = global_ievcache_name
121
+ @iev_localname = local_ievcache_name(node.attr("local-cache") ||
122
+ node.attr("local-cache-only"))
121
123
  if node.attr("flush-caches")
122
124
  FileUtils.rm_f @iev_globalname unless @iev_globalname.nil?
123
125
  FileUtils.rm_f @iev_localname unless @iev_localname.nil?
@@ -205,12 +205,6 @@ module Asciidoctor
205
205
  termdocsource_cleanup(xmldoc)
206
206
  end
207
207
 
208
- def biblio_cleanup(xmldoc)
209
- xmldoc.xpath("//references[references]").each do |t|
210
- t.name = "clause"
211
- end
212
- end
213
-
214
208
  def empty_text_before_first_element(x)
215
209
  x.children.each do |c|
216
210
  if c.text?
@@ -75,6 +75,38 @@ module Asciidoctor
75
75
  end
76
76
  end
77
77
 
78
+ def biblio_reorder(xmldoc)
79
+ xmldoc.xpath("//references[title = 'Bibliography']").each do |r|
80
+ biblio_reorder1(r)
81
+ end
82
+ end
83
+
84
+ def biblio_reorder1(refs)
85
+ bib = sort_biblio(refs.xpath("./bibitem"))
86
+ refs.xpath("./bibitem").each { |b| b.remove }
87
+ bib.reverse.each do |b|
88
+ insert = refs.at("./title") and insert.next = b.to_xml or
89
+ refs.children.first.add_previous_sibling b.to_xml
90
+ end
91
+ refs.xpath("./references").each { |r| biblio_reorder1(r) }
92
+ end
93
+
94
+ def sort_biblio(bib)
95
+ bib
96
+ end
97
+
98
+ # default presuppose that all citations in biblio numbered
99
+ # consecutively, but that standards codes are preserved as is:
100
+ # only numeric references are renumbered
101
+ def biblio_renumber(xmldoc)
102
+ r = xmldoc.at("//references[title = 'Bibliography'] | "\
103
+ "//clause[title = 'Bibliography'][.//bibitem]") or return
104
+ r.xpath(".//bibitem[not(ancestor::bibitem)]").each_with_index do |b, i|
105
+ docid = b.at("./docidentifier[@type = 'metanorma']") and
106
+ docid.children = "[#{i + 1}]"
107
+ end
108
+ end
109
+
78
110
  # move ref before p
79
111
  def ref_cleanup(xmldoc)
80
112
  xmldoc.xpath("//p/ref").each do |r|
@@ -91,6 +123,14 @@ module Asciidoctor
91
123
  end
92
124
  end
93
125
 
126
+ def biblio_cleanup(xmldoc)
127
+ biblio_reorder(xmldoc)
128
+ biblio_renumber(xmldoc)
129
+ xmldoc.xpath("//references[references]").each do |t|
130
+ t.name = "clause"
131
+ end
132
+ end
133
+
94
134
  def docid_prefix(prefix, docid)
95
135
  docid = "#{prefix} #{docid}" unless omit_docid_prefix(prefix)
96
136
  docid
@@ -122,50 +162,10 @@ module Asciidoctor
122
162
  end
123
163
  end
124
164
 
125
- =begin
126
- # converts generic IEV citation to citation of IEC 60050-n
127
- # assumes IEV citations are of form
128
- # <eref type="inline" bibitemid="a" citeas="IEC 60050">
129
- # <locality type="clause"><referenceFrom>101-01-01</referenceFrom></locality></eref>
130
- def linksIev2iec60050part(xmldoc)
131
- parts = Set.new()
132
- xmldoc.xpath("//eref[@citeas = 'IEC 60050:2011'] | "\
133
- "//origin[@citeas = 'IEC 60050:2011']").each do |x|
134
- cl = x&.at("./locality[@type = 'clause']/referenceFrom")&.text || next
135
- m = /^(\d+)/.match cl || next
136
- parts << m[0]
137
- x["citeas"] = x["citeas"].sub(/60050/, "60050-#{m[0]}")
138
- x["bibitemid"] = "IEC60050-#{m[0]}"
139
- end
140
- parts
141
- end
142
-
143
- # replace generic IEV reference with references to all extracted
144
- # IEV parts
145
- def refsIev2iec60050part(xmldoc, parts, iev)
146
- new_iev = ""
147
- parts.sort.each do |p|
148
- hit = @bibdb&.fetch("IEC 60050-#{p}", nil, keep_year: true) || next
149
- new_iev += hit.to_xml.sub(/ id="[^"]+"/, %{ id="IEC60050-#{p}"})
150
- date = hit.date[0].on.year
151
- xmldoc.xpath("//*[@citeas = 'IEC 60050-#{p}:2011']").each do |x|
152
- x["citeas"] = x["citeas"].sub(/:2011$/, ":#{date}")
153
- end
154
- end
155
- iev.replace(new_iev)
156
- end
157
-
158
- # call after xref_cleanup and origin_cleanup
159
- def iev_cleanup(xmldoc)
160
- iev = xmldoc.at("//bibitem[docidentifier = 'IEC 60050:2011']") || return
161
- parts = linksIev2iec60050part(xmldoc)
162
- refsIev2iec60050part(xmldoc, parts, iev)
163
- end
164
- =end
165
-
166
165
  def ref_dl_cleanup(xmldoc)
167
166
  xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
168
167
  bib = dl_bib_extract(c) or next
168
+ #warn bib
169
169
  bibitemxml = RelatonBib::BibliographicItem.new(
170
170
  RelatonBib::HashConverter::hash_to_bib(bib)).to_xml or next
171
171
  bibitem = Nokogiri::XML(bibitemxml)
@@ -202,7 +202,8 @@ module Asciidoctor
202
202
  return nil if dtd.children.empty?
203
203
  dtd.at("./dl") and return dl_bib_extract(dtd)
204
204
  elems = dtd.remove.elements
205
- return p_unwrap(dtd) unless elems.size == 1 && %w(ol ul).include?(elems[0].name)
205
+ return p_unwrap(dtd) unless elems.size == 1 &&
206
+ %w(ol ul).include?(elems[0].name)
206
207
  ret = []
207
208
  elems[0].xpath("./li").each do |li|
208
209
  ret << p_unwrap(li)
@@ -211,8 +212,7 @@ module Asciidoctor
211
212
  end
212
213
 
213
214
  def add_to_hash(bib, key, val)
214
- bib[key] = bib[key].is_a?(Array) ? (bib[key] << val) :
215
- bib[key].nil? ? val : [bib[key], val]
215
+ Utils::set_nested_value(bib, key.split(/\./), val)
216
216
  end
217
217
 
218
218
  # definition list, with at most one level of unordered lists
@@ -87,7 +87,8 @@ module Asciidoctor
87
87
  end
88
88
  end
89
89
  node.attr("email#{suffix}") and p.email node.attr("email#{suffix}")
90
- node.attr("contributor-uri#{suffix}") and p.uri node.attr("contributor-uri#{suffix}")
90
+ node.attr("contributor-uri#{suffix}") and
91
+ p.uri node.attr("contributor-uri#{suffix}")
91
92
  end
92
93
  end
93
94
  end
@@ -144,7 +145,8 @@ module Asciidoctor
144
145
  node.attr("html-uri") && xml.uri(node.attr("html-uri"), type: "html")
145
146
  node.attr("pdf-uri") && xml.uri(node.attr("pdf-uri"), type: "pdf")
146
147
  node.attr("doc-uri") && xml.uri(node.attr("doc-uri"), type: "doc")
147
- node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"), type: "relaton")
148
+ node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"),
149
+ type: "relaton")
148
150
  end
149
151
 
150
152
  def metadata_date1(node, xml, type)
@@ -266,7 +268,8 @@ module Asciidoctor
266
268
  ["en"].each do |lang|
267
269
  at = { language: lang, format: "text/plain" }
268
270
  xml.title **attr_code(at) do |t|
269
- t << asciidoc_sub(node.attr("title") || node.attr("title-en") || node.title)
271
+ t << asciidoc_sub(node.attr("title") || node.attr("title-en") ||
272
+ node.title)
270
273
  end
271
274
  end
272
275
  end
@@ -107,7 +107,8 @@ module Asciidoctor
107
107
  xml.stem math, **{ type: "MathML" }
108
108
  elsif style == :latexmath
109
109
  latex_cmd = Metanorma::Standoc::Requirements[:latexml].cmd
110
- latexmlmath_input = Unicode2LaTeX::unicode2latex(text).gsub(/'/, '\\').gsub(/\n/, " ")
110
+ latexmlmath_input =
111
+ Unicode2LaTeX::unicode2latex(text).gsub(/'/, '\\').gsub(/\n/, " ")
111
112
  latex = IO.popen(latex_cmd, "r+", external_encoding: "UTF-8") do |io|
112
113
  io.write(latexmlmath_input)
113
114
  io.close_write
@@ -49,7 +49,8 @@ module Asciidoctor
49
49
  def process parent, reader, attrs
50
50
  attrs['name'] = 'todo'
51
51
  attrs['caption'] = 'TODO'
52
- create_block parent, :admonition, reader.lines, attrs, content_model: :compound
52
+ create_block parent, :admonition, reader.lines, attrs,
53
+ content_model: :compound
53
54
  end
54
55
  end
55
56
 
@@ -88,6 +89,9 @@ module Asciidoctor
88
89
  fn = save_plantuml parent, reader, localdir
89
90
  umlfile = Pathname.new(localdir) + "plantuml" + "#{fn}.pml"
90
91
  system "plantuml #{umlfile}"
92
+ # sleep need for windows because dot works in separate process and plantuml process may
93
+ # finish erlier then dot, as result png file maybe not created yet after plantuml finish
94
+ sleep(2) if Gem.win_platform?
91
95
  outfile = parent.image_uri("#{fn}.png")
92
96
  if outfile == "#{fn}.png"
93
97
  (Pathname.new("plantuml") + "#{fn}.png").to_s
@@ -105,9 +109,8 @@ module Asciidoctor
105
109
  /^@startuml (?<fn>[^\n]+)\n/ =~ src
106
110
  fn ||= UUIDTools::UUID.random_create
107
111
  path = Pathname.new(localdir) + "plantuml"
108
- FileUtils.mkdir_p path.to_s # "#{localdir}/plantuml"
109
- #File.open("#{localdir}plantuml/#{fn}.pml", "w") { |f| f.write src }
110
- File.open((path + "#{fn}.pml").to_s, "w") { |f| f.write src }
112
+ path.mkpath()
113
+ (path + "#{fn}.pml").write(src)
111
114
  fn
112
115
  end
113
116
 
@@ -136,7 +139,8 @@ module Asciidoctor
136
139
  warn "PlantUML not installed"
137
140
  # attrs.delete(1) : remove the style attribute
138
141
  attrs["language"] = "plantuml"
139
- create_listing_block parent, reader.source, attrs.reject { |k, v| k == 1 }
142
+ create_listing_block parent, reader.source,
143
+ attrs.reject { |k, v| k == 1 }
140
144
  end
141
145
  end
142
146
  end
@@ -42,12 +42,13 @@ module Asciidoctor
42
42
  end
43
43
 
44
44
  def docid(t, code)
45
- type, code1 = @bibdb&.docid_type(code) unless /^\[\d+\]$/.match(code)
46
- t.docidentifier (code1 || code), **attr_code(type: type)
45
+ type, code1 = /^\[\d+\]$/.match(code) ? ["metanorma", code] :
46
+ @bibdb&.docid_type(code) || [nil, code]
47
+ t.docidentifier code1, **attr_code(type: type)
47
48
  end
48
49
 
49
50
  def isorefmatches(xml, m)
50
- ref = fetch_ref xml, m[:code], m[:year]
51
+ ref = fetch_ref xml, m[:code], m[:year], title: m[:text]
51
52
  return use_my_anchor(ref, m[:anchor]) if ref
52
53
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
53
54
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
@@ -60,7 +61,8 @@ module Asciidoctor
60
61
  end
61
62
 
62
63
  def isorefmatches2(xml, m)
63
- ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn]
64
+ ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
65
+ title: m[:text]
64
66
  return use_my_anchor(ref, m[:anchor]) if ref
65
67
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
66
68
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
@@ -87,7 +89,7 @@ module Asciidoctor
87
89
  hasyr = m.names.include?("year") && m[:year] != "--"
88
90
  noyr = m.names.include?("year") && m[:year] == "--"
89
91
  ref = fetch_ref xml, m[:code], hasyr ? m[:year] : nil,
90
- all_parts: true, no_year: noyr
92
+ all_parts: true, no_year: noyr, text: m[:text]
91
93
  return use_my_anchor(ref, m[:anchor]) if ref
92
94
  xml.bibitem(**attr_code(ref_attributes(m))) do |t|
93
95
  t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
@@ -96,7 +98,6 @@ module Asciidoctor
96
98
  iso_publisher(t, m[:code])
97
99
  m.names.include?("fn") && m[:fn] and
98
100
  t.note(**plaintxt) { |p| p << "ISO DATE: #{m[:fn]}" }
99
- #t.allparts "true"
100
101
  t.extent **{ type: 'part' } do |e|
101
102
  e.referenceFrom "all"
102
103
  end
@@ -107,7 +108,7 @@ module Asciidoctor
107
108
  return nil if opts[:no_year]
108
109
  hit = @bibdb&.fetch(code, year, opts)
109
110
  return nil if hit.nil?
110
- xml.parent.add_child(Utils::smart_render_xml(hit))
111
+ xml.parent.add_child(Utils::smart_render_xml(hit, code, opts[:title]))
111
112
  xml
112
113
  rescue RelatonBib::RequestError
113
114
  warn "Could not retrieve #{code}: no access to online site"
@@ -131,7 +132,7 @@ module Asciidoctor
131
132
  end
132
133
  unless m[:code] && /^\d+$/.match(m[:code])
133
134
  ref = fetch_ref xml, m[:code],
134
- m.names.include?("year") ? m[:year] : nil, {}
135
+ m.names.include?("year") ? m[:year] : nil, { title: m[:text] }
135
136
  return use_my_anchor(ref, m[:anchor]) if ref
136
137
  end
137
138
  refitem_render(xml, m)
@@ -87,7 +87,7 @@
87
87
  </element>
88
88
  </define>
89
89
  <define name="reqinherit">
90
- <element name="subject">
90
+ <element name="inherit">
91
91
  <text/>
92
92
  </element>
93
93
  </define>
@@ -43,12 +43,48 @@ module Asciidoctor
43
43
  gsub(/--/, "&#8212;").smart_format.gsub(/</, "&lt;").gsub(/>/, "&gt;")
44
44
  end
45
45
 
46
- def smart_render_xml(x)
46
+ # Set hash value using keys path
47
+ # mod from https://stackoverflow.com/a/42425884
48
+ def set_nested_value(hash, keys, new_val)
49
+ key = keys[0]
50
+ if keys.length == 1
51
+ hash[key] = hash[key].is_a?(Array) ? (hash[key] << new_val) :
52
+ hash[key].nil? ? new_val : [hash[key], new_val]
53
+ return hash
54
+ end
55
+ if hash[key].is_a?(Array)
56
+ hash[key][-1] = {} if hash[key][-1].nil?
57
+ set_nested_value(hash[key][-1], keys[1..-1], new_val)
58
+ elsif hash[key].nil? || hash[key].empty?
59
+ hash[key] = {}
60
+ set_nested_value(hash[key], keys[1..-1], new_val)
61
+ elsif hash[key].is_a?(Hash) && !hash[key][keys[1]]
62
+ set_nested_value(hash[key], keys[1..-1], new_val)
63
+ elsif !hash[key][keys[1]]
64
+ hash[key] = [hash[key], {}]
65
+ set_nested_value(hash[key][-1], keys[1..-1], new_val)
66
+ else
67
+ set_nested_value(hash[key], keys[1..-1], new_val)
68
+ end
69
+ end
70
+
71
+ def emend_biblio(xml, code, title)
72
+ unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
73
+ warn "ERROR: No document identifier retrieved for #{code}"
74
+ xml.root << "<docidentifier>#{code}</docidentifier>"
75
+ end
76
+ unless xml.at("/bibitem/title[text()]")
77
+ warn "ERROR: No title retrieved for #{code}"
78
+ xml.root << "<title>#{title || "(MISSING TITLE)"}</title>"
79
+ end
80
+ end
81
+
82
+ def smart_render_xml(x, code, title)
47
83
  xstr = x.to_xml if x.respond_to? :to_xml
48
84
  xml = Nokogiri::XML(xstr)
85
+ emend_biblio(xml, code, title)
49
86
  xml.traverse do |n|
50
- next unless n.text?
51
- n.replace(smartformat(n.text))
87
+ n.text? and n.replace(smartformat(n.text))
52
88
  end
53
89
  xml.to_xml.sub(/<\?[^>]+>/, "")
54
90
  end