metanorma-standoc 1.8.7 → 1.9.3

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -2
  3. data/Gemfile.devel +0 -0
  4. data/lib/asciidoctor/standoc/base.rb +39 -36
  5. data/lib/asciidoctor/standoc/biblio.rng +1 -0
  6. data/lib/asciidoctor/standoc/blocks.rb +25 -9
  7. data/lib/asciidoctor/standoc/blocks_notes.rb +41 -24
  8. data/lib/asciidoctor/standoc/cleanup.rb +59 -84
  9. data/lib/asciidoctor/standoc/cleanup_block.rb +63 -85
  10. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +51 -29
  11. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
  12. data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
  13. data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
  14. data/lib/asciidoctor/standoc/cleanup_ref.rb +24 -15
  15. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
  16. data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
  17. data/lib/asciidoctor/standoc/cleanup_section.rb +104 -94
  18. data/lib/asciidoctor/standoc/converter.rb +10 -3
  19. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
  20. data/lib/asciidoctor/standoc/front.rb +35 -18
  21. data/lib/asciidoctor/standoc/front_contributor.rb +5 -5
  22. data/lib/asciidoctor/standoc/inline.rb +1 -1
  23. data/lib/asciidoctor/standoc/isodoc.rng +305 -4
  24. data/lib/asciidoctor/standoc/lists.rb +4 -2
  25. data/lib/asciidoctor/standoc/macros.rb +50 -23
  26. data/lib/asciidoctor/standoc/macros_form.rb +63 -0
  27. data/lib/asciidoctor/standoc/ref.rb +87 -112
  28. data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
  29. data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
  30. data/lib/asciidoctor/standoc/section.rb +3 -1
  31. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +31 -16
  32. data/lib/asciidoctor/standoc/terms.rb +27 -16
  33. data/lib/asciidoctor/standoc/utils.rb +35 -9
  34. data/lib/asciidoctor/standoc/validate.rb +30 -28
  35. data/lib/metanorma-standoc.rb +0 -1
  36. data/lib/metanorma/standoc/version.rb +5 -5
  37. data/metanorma-standoc.gemspec +11 -11
  38. data/spec/asciidoctor/base_spec.rb +85 -19
  39. data/spec/asciidoctor/blocks_spec.rb +830 -727
  40. data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
  41. data/spec/asciidoctor/cleanup_spec.rb +1900 -1917
  42. data/spec/asciidoctor/inline_spec.rb +282 -283
  43. data/spec/asciidoctor/isobib_cache_spec.rb +406 -358
  44. data/spec/asciidoctor/lists_spec.rb +3 -3
  45. data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
  46. data/spec/asciidoctor/macros_spec.rb +546 -444
  47. data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
  48. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  49. data/spec/asciidoctor/refs_spec.rb +19 -19
  50. data/spec/asciidoctor/section_spec.rb +778 -689
  51. data/spec/asciidoctor/table_spec.rb +6 -6
  52. data/spec/asciidoctor/validate_spec.rb +21 -21
  53. data/spec/spec_helper.rb +13 -9
  54. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +62 -62
  55. data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
  56. data/spec/vcr_cassettes/isobib_get_123_1.yml +28 -28
  57. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +41 -41
  58. data/spec/vcr_cassettes/isobib_get_123_2001.yml +16 -16
  59. data/spec/vcr_cassettes/isobib_get_124.yml +15 -15
  60. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  61. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +63 -61
  62. metadata +68 -67
  63. data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
  64. data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
  65. data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
  66. data/lib/liquid/custom_filters/values.rb +0 -7
@@ -0,0 +1,63 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ class FormInputMacro < Asciidoctor::Extensions::InlineMacroProcessor
4
+ use_dsl
5
+ named :input
6
+
7
+ def process(_parent, target, attr)
8
+ m = %w(id name value disabled readonly checked maxlength minlength)
9
+ .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
10
+ %{<input type='#{target}' #{m.join}/>}
11
+ end
12
+ end
13
+
14
+ class FormLabelMacro < Asciidoctor::Extensions::InlineMacroProcessor
15
+ use_dsl
16
+ named :label
17
+ parse_content_as :text
18
+
19
+ def process(parent, target, attr)
20
+ out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
21
+ %{<label for="#{target}">#{out}</label>}
22
+ end
23
+ end
24
+
25
+ class FormTextareaMacro < Asciidoctor::Extensions::InlineMacroProcessor
26
+ use_dsl
27
+ named :textarea
28
+ using_format :short
29
+
30
+ def process(_parent, _target, attr)
31
+ m = %w(id name rows cols value)
32
+ .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
33
+ %{<textarea #{m.join}/>}
34
+ end
35
+ end
36
+
37
+ class FormSelectMacro < Asciidoctor::Extensions::InlineMacroProcessor
38
+ use_dsl
39
+ named :select
40
+ using_format :short
41
+
42
+ def process(parent, _target, attr)
43
+ m = %w(id name size disabled multiple value)
44
+ .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
45
+ out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
46
+ %{<select #{m.join}>#{out}</select>}
47
+ end
48
+ end
49
+
50
+ class FormOptionMacro < Asciidoctor::Extensions::InlineMacroProcessor
51
+ use_dsl
52
+ named :option
53
+ using_format :short
54
+
55
+ def process(parent, _target, attr)
56
+ m = %w(disabled value)
57
+ .map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
58
+ out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
59
+ %{<option #{m.join}">#{out}</option>}
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,12 +1,14 @@
1
+ require_relative "ref_date_id"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Refs
4
- def iso_publisher(t, code)
6
+ def iso_publisher(bib, code)
5
7
  code.sub(/ .*$/, "").split(/\//).each do |abbrev|
6
- t.contributor do |c|
8
+ bib.contributor do |c|
7
9
  c.role **{ type: "publisher" }
8
10
  c.organization do |org|
9
- organization(org, abbrev)
11
+ organization(org, abbrev, true)
10
12
  end
11
13
  end
12
14
  end
@@ -20,58 +22,19 @@ module Asciidoctor
20
22
  { id: m[:anchor], type: "standard" }
21
23
  end
22
24
 
23
- def set_date_range(date, text)
24
- matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
25
- return unless matched[:from]
26
- if matched[:to]
27
- date.from matched[:from]
28
- date.to matched[:to]
29
- else
30
- date.on matched[:from]
31
- end
32
- end
33
-
34
- def use_my_anchor(ref, id)
35
- ref.parent.elements.last["id"] = id
36
- ref
37
- end
38
-
39
- def id_and_year(id, year)
40
- year ? "#{id}:#{year}" : id
41
- end
42
-
43
- def docid(t, code)
44
- type, code1 = /^\[\d+\]$|^\([^)]+\).*$/.match(code) ?
45
- ["metanorma", mn_code(code)] : @bibdb&.docid_type(code) || [nil, code]
46
- code1.sub!(/^nofetch\((.+)\)$/, "\\1")
47
- t.docidentifier **attr_code(type: type) do |d|
48
- d << code1
49
- end
50
- end
51
-
52
- def docnumber(t, code)
53
- t.docnumber do |d|
54
- d << HTMLEntities.new.decode(code).sub(/^[^\d]*/, "")
55
- end
56
- end
57
-
58
- def norm_year(yr)
59
- /^\&\#821[12];$/.match(yr) and return "--"
60
- /^\d\d\d\d-\d\d\d\d$/.match(yr) and return yr
61
- yr&.sub(/(?<=[0-9])-.*$/, "")
62
- end
63
-
64
- def isorefrender1(t, m, yr, allp = "")
65
- t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
66
- docid(t, m[:usrlbl]) if m[:usrlbl]
67
- docid(t, id_and_year(m[:code], yr) + allp)
68
- docnumber(t, m[:code])
25
+ def isorefrender1(bib, m, yr, allp = "")
26
+ bib.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
27
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
28
+ docid(bib, id_and_year(m[:code], yr) + allp)
29
+ docnumber(bib, m[:code])
69
30
  end
70
31
 
71
32
  def isorefmatches(xml, m)
72
33
  yr = norm_year(m[:year])
73
- ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
34
+ ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl],
35
+ lang: (@lang || :all)
74
36
  return use_my_anchor(ref, m[:anchor]) if ref
37
+
75
38
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
76
39
  isorefrender1(t, m, yr)
77
40
  yr and t.date **{ type: "published" } do |d|
@@ -85,6 +48,7 @@ module Asciidoctor
85
48
  ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
86
49
  title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
87
50
  return use_my_anchor(ref, m[:anchor]) if ref
51
+
88
52
  isorefmatches2_1(xml, m)
89
53
  end
90
54
 
@@ -95,49 +59,51 @@ module Asciidoctor
95
59
  d.on "--"
96
60
  end
97
61
  iso_publisher(t, m[:code])
98
- m[:fn].nil? or t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
99
- p << "#{m[:fn]}"
62
+ unless m[:fn].nil?
63
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
64
+ p << (m[:fn]).to_s
65
+ end
100
66
  end
101
67
  end
102
68
  end
103
69
 
104
- def conditional_date(t, m, noyr)
105
- m.names.include?("year") and !m[:year].nil? and
106
- t.date(**{ type: "published" }) do |d|
107
- noyr and d.on "--" or set_date_range(d, norm_year(m[:year]))
108
- end
109
- end
110
-
111
70
  def isorefmatches3(xml, m)
112
71
  yr = norm_year(m[:year])
113
72
  hasyr = !yr.nil? && yr != "--"
114
- ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
115
- no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
73
+ ref = fetch_ref(xml, m[:code], hasyr ? yr : nil,
74
+ all_parts: true,
75
+ no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl],
76
+ lang: (@lang || :all))
116
77
  return use_my_anchor(ref, m[:anchor]) if ref
78
+
117
79
  isorefmatches3_1(xml, m, yr, hasyr, ref)
118
80
  end
119
81
 
120
- def isorefmatches3_1(xml, m, yr, hasyr, ref)
82
+ def isorefmatches3_1(xml, m, yr, _hasyr, _ref)
121
83
  xml.bibitem(**attr_code(ref_attributes(m))) do |t|
122
84
  isorefrender1(t, m, yr, " (all parts)")
123
85
  conditional_date(t, m, yr == "--")
124
86
  iso_publisher(t, m[:code])
125
- m.names.include?("fn") && m[:fn] and
126
- t.note(**plaintxt.merge(type: "Unpublished-Status")) { |p| p << "#{m[:fn]}" }
127
- t.extent **{ type: 'part' } do |e|
87
+ if m.names.include?("fn") && m[:fn]
88
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
89
+ p << (m[:fn]).to_s
90
+ end
91
+ end
92
+ t.extent **{ type: "part" } do |e|
128
93
  e.referenceFrom "all"
129
94
  end
130
95
  end
131
96
  end
132
97
 
133
- def refitem_render1(m, code, t)
98
+ def refitem_render1(m, code, bib)
134
99
  if code[:type] == "path"
135
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
136
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
100
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
101
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
137
102
  end
138
- docid(t, m[:usrlbl]) if m[:usrlbl]
139
- docid(t, /^\d+$/.match(code[:id]) ? "[#{code[:id]}]" : code[:id])
140
- code[:type] == "repo" and t.docidentifier code[:key], **{ type: "repository" }
103
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
104
+ docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
105
+ code[:type] == "repo" and
106
+ bib.docidentifier code[:key], **{ type: "repository" }
141
107
  end
142
108
 
143
109
  def refitem_render(xml, m, code)
@@ -146,7 +112,7 @@ module Asciidoctor
146
112
  i << ref_normalise_no_format(m[:text])
147
113
  end
148
114
  refitem_render1(m, code, t)
149
- docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match(code[:id])
115
+ docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match?(code[:id])
150
116
  end
151
117
  end
152
118
 
@@ -156,25 +122,30 @@ module Asciidoctor
156
122
 
157
123
  def analyse_ref_nofetch(ret)
158
124
  return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
125
+
159
126
  ret.merge(id: m[:id], nofetch: true)
160
127
  end
161
128
 
162
129
  def analyse_ref_repo_path(ret)
163
- return ret unless m = /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
130
+ return ret unless m =
131
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
132
+
164
133
  id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
165
134
  ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
166
135
  end
167
136
 
168
137
  def analyse_ref_numeric(ret)
169
- return ret unless /^\d+$/.match(ret[:id])
138
+ return ret unless /^\d+$/.match?(ret[:id])
139
+
170
140
  ret.merge(numeric: true)
171
141
  end
172
142
 
173
143
  # ref id = (usrlbl)code[:-]year
174
144
  # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
175
145
  def analyse_ref_code(code)
176
- ret = {id: code}
177
- return ret if code.nil? || code.empty?
146
+ ret = { id: code }
147
+ return ret if code.blank?
148
+
178
149
  analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
179
150
  end
180
151
 
@@ -185,11 +156,13 @@ module Asciidoctor
185
156
  nil
186
157
  end
187
158
 
188
- def refitem1(xml, item, m)
159
+ def refitem1(xml, _item, m)
189
160
  code = analyse_ref_code(m[:code])
190
161
  unless code[:id] && code[:numeric] || code[:nofetch]
191
- ref = fetch_ref xml, code[:id], m.names.include?("year") ? m[:year] : nil, title: m[:text],
192
- usrlbl: m[:usrlbl], lang: (@lang || :all)
162
+ ref = fetch_ref(xml, code[:id],
163
+ m.names.include?("year") ? m[:year] : nil,
164
+ title: m[:text],
165
+ usrlbl: m[:usrlbl], lang: (@lang || :all))
193
166
  return use_my_anchor(ref, m[:anchor]) if ref
194
167
  end
195
168
  refitem_render(xml, m, code)
@@ -203,44 +176,46 @@ module Asciidoctor
203
176
  ref.gsub(/&amp;amp;/, "&amp;")
204
177
  end
205
178
 
206
- ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
179
+ ISO_REF =
180
+ %r{^<ref\sid="(?<anchor>[^"]+)">
207
181
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
208
- (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
182
+ (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
209
183
 
210
- ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
184
+ ISO_REF_NO_YEAR =
185
+ %r{^<ref\sid="(?<anchor>[^"]+)">
211
186
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
212
- (--|\&\#821[12]\;)\]</ref>,?\s*
187
+ (--|&\#821[12];)\]</ref>,?\s*
213
188
  (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
214
-
215
- ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
216
- \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
217
- (:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
218
- \(all\sparts\)\]</ref>,?\s*
219
- (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
220
-
221
- NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
222
- \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
223
- ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
224
-
225
- def reference1_matches(item)
226
- matched = ISO_REF.match item
227
- matched2 = ISO_REF_NO_YEAR.match item
228
- matched3 = ISO_REF_ALL_PARTS.match item
229
- [matched, matched2, matched3]
230
- end
231
-
232
- def reference1(node, item, xml)
233
- matched, matched2, matched3 = reference1_matches(item)
234
- if matched3.nil? && matched2.nil? && matched.nil? then refitem(xml, item, node)
235
- elsif !matched.nil? then isorefmatches(xml, matched)
236
- elsif !matched2.nil? then isorefmatches2(xml, matched2)
237
- elsif !matched3.nil? then isorefmatches3(xml, matched3)
238
- end
239
- end
240
-
241
- def mn_code(code)
242
- code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
189
+ .freeze
190
+
191
+ ISO_REF_ALL_PARTS =
192
+ %r{^<ref\sid="(?<anchor>[^"]+)">
193
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
194
+ (:(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
195
+ \(all\sparts\)\]</ref>,?\s*
196
+ (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
197
+
198
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
199
+ \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
200
+ ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
201
+ .freeze
202
+
203
+ def reference1_matches(item)
204
+ matched = ISO_REF.match item
205
+ matched2 = ISO_REF_NO_YEAR.match item
206
+ matched3 = ISO_REF_ALL_PARTS.match item
207
+ [matched, matched2, matched3]
208
+ end
209
+
210
+ def reference1(node, item, xml)
211
+ matched, matched2, matched3 = reference1_matches(item)
212
+ if matched3.nil? && matched2.nil? && matched.nil?
213
+ refitem(xml, item, node)
214
+ elsif !matched.nil? then isorefmatches(xml, matched)
215
+ elsif !matched2.nil? then isorefmatches2(xml, matched2)
216
+ elsif !matched3.nil? then isorefmatches3(xml, matched3)
243
217
  end
218
+ end
244
219
  end
245
220
  end
246
221
  end
@@ -0,0 +1,62 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ module Refs
4
+ def set_date_range(date, text)
5
+ matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
6
+ return unless matched[:from]
7
+
8
+ if matched[:to]
9
+ date.from matched[:from]
10
+ date.to matched[:to]
11
+ else
12
+ date.on matched[:from]
13
+ end
14
+ end
15
+
16
+ def id_and_year(id, year)
17
+ year ? "#{id}:#{year}" : id
18
+ end
19
+
20
+ def norm_year(year)
21
+ /^&\#821[12];$/.match(year) and return "--"
22
+ /^\d\d\d\d-\d\d\d\d$/.match(year) and return year
23
+ year&.sub(/(?<=[0-9])-.*$/, "")
24
+ end
25
+
26
+ def conditional_date(bib, match, noyr)
27
+ if match.names.include?("year") && !match[:year].nil?
28
+ bib.date(**{ type: "published" }) do |d|
29
+ noyr and d.on "--" or set_date_range(d, norm_year(match[:year]))
30
+ end
31
+ end
32
+ end
33
+
34
+ def use_my_anchor(ref, id)
35
+ ref.parent.elements.last["id"] = id
36
+ ref
37
+ end
38
+
39
+ def docid(bib, code)
40
+ type, code1 = if /^\[\d+\]$|^\([^)]+\).*$/.match?(code)
41
+ ["metanorma", mn_code(code)]
42
+ else
43
+ @bibdb&.docid_type(code) || [nil, code]
44
+ end
45
+ code1.sub!(/^nofetch\((.+)\)$/, "\\1")
46
+ bib.docidentifier **attr_code(type: type) do |d|
47
+ d << code1
48
+ end
49
+ end
50
+
51
+ def docnumber(bib, code)
52
+ bib.docnumber do |d|
53
+ d << HTMLEntities.new.decode(code).sub(/^[^\d]*/, "")
54
+ end
55
+ end
56
+
57
+ def mn_code(code)
58
+ code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -10,10 +10,10 @@ module Asciidoctor
10
10
  end
11
11
 
12
12
  def reference(node)
13
- noko do |xml|
14
- node.items.each { |item| reference1(node, item.text, xml) }
15
- end.join
16
- end
13
+ noko do |xml|
14
+ node.items.each { |item| reference1(node, item.text, xml) }
15
+ end.join
16
+ end
17
17
 
18
18
  def bibliography_parse(attrs, xml, node)
19
19
  node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
@@ -43,12 +43,12 @@ module Asciidoctor
43
43
  node.attr("style") == "bibliography" or
44
44
  @log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
45
45
  @norm_ref = true
46
- xml.references **attr_code(attrs.merge(
47
- normative: node.attr("normative") || true)) do |xml_section|
48
- xml_section.title { |t| t << node.title }
49
- xml_section << node.content
50
- end
51
- @norm_ref = false
46
+ attrs = attrs.merge(normative: node.attr("normative") || true)
47
+ xml.references **attr_code(attrs) do |xml_section|
48
+ xml_section.title { |t| t << node.title }
49
+ xml_section << node.content
50
+ end
51
+ @norm_ref = false
52
52
  end
53
53
 
54
54
  def global_ievcache_name
@@ -57,6 +57,7 @@ module Asciidoctor
57
57
 
58
58
  def local_ievcache_name(cachename)
59
59
  return nil if cachename.nil?
60
+
60
61
  cachename += "_iev" unless cachename.empty?
61
62
  cachename = "iev" if cachename.empty?
62
63
  "#{cachename}/cache"
@@ -64,10 +65,11 @@ module Asciidoctor
64
65
 
65
66
  def fetch_ref(xml, code, year, **opts)
66
67
  return nil if opts[:no_year]
68
+
67
69
  code = code.sub(/^\([^)]+\)/, "")
68
- #require "byebug"; byebug if opts[:lang] == "fr"
69
70
  hit = @bibdb&.fetch(code, year, opts)
70
71
  return nil if hit.nil?
72
+
71
73
  xml.parent.add_child(smart_render_xml(hit, code, opts))
72
74
  xml
73
75
  rescue RelatonBib::RequestError
@@ -91,10 +93,9 @@ module Asciidoctor
91
93
  "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
92
94
  end
93
95
 
94
- def smart_render_xml(x, code, opts)
95
- x.respond_to? :to_xml or return nil
96
- xstr = x.to_xml(lang: opts[:lang])
97
- xml = Nokogiri::XML(xstr)
96
+ def smart_render_xml(xml, code, opts)
97
+ xml.respond_to? :to_xml or return nil
98
+ xml = Nokogiri::XML(xml.to_xml(lang: opts[:lang]))
98
99
  emend_biblio(xml, code, opts[:title], opts[:usrlbl])
99
100
  xml.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
100
101
  xml.traverse do |n|
@@ -105,17 +106,19 @@ module Asciidoctor
105
106
 
106
107
  def init_bib_caches(node)
107
108
  return if @no_isobib
109
+
108
110
  global = !@no_isobib_cache && !node.attr("local-cache-only")
109
111
  local = node.attr("local-cache") || node.attr("local-cache-only")
110
112
  local = nil if @no_isobib_cache
111
113
  @bibdb = Relaton::DbCache.init_bib_caches(
112
114
  local_cache: local,
113
115
  flush_caches: node.attr("flush-caches"),
114
- global_cache: global)
116
+ global_cache: global
117
+ )
115
118
  end
116
119
 
117
120
  def init_iev_caches(node)
118
- unless (@no_isobib_cache || @no_isobib)
121
+ unless @no_isobib_cache || @no_isobib
119
122
  node.attr("local-cache-only") or
120
123
  @iev_globalname = global_ievcache_name
121
124
  @iev_localname = local_ievcache_name(node.attr("local-cache") ||