metanorma-standoc 1.10.8 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/asciidoctor/standoc/base.rb +5 -4
  4. data/lib/asciidoctor/standoc/blocks.rb +1 -1
  5. data/lib/asciidoctor/standoc/cleanup.rb +20 -11
  6. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -20
  7. data/lib/asciidoctor/standoc/cleanup_inline.rb +20 -7
  8. data/lib/asciidoctor/standoc/cleanup_maths.rb +5 -6
  9. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +25 -15
  10. data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -21
  11. data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -2
  12. data/lib/asciidoctor/standoc/cleanup_symbols.rb +48 -0
  13. data/lib/asciidoctor/standoc/cleanup_terms.rb +54 -79
  14. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +179 -0
  15. data/lib/asciidoctor/standoc/cleanup_text.rb +23 -0
  16. data/lib/asciidoctor/standoc/converter.rb +2 -0
  17. data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +6 -6
  18. data/lib/asciidoctor/standoc/inline.rb +20 -16
  19. data/lib/asciidoctor/standoc/isodoc.rng +254 -27
  20. data/lib/asciidoctor/standoc/lists.rb +1 -3
  21. data/lib/asciidoctor/standoc/macros_plantuml.rb +29 -14
  22. data/lib/asciidoctor/standoc/macros_terms.rb +49 -5
  23. data/lib/asciidoctor/standoc/ref.rb +101 -75
  24. data/lib/asciidoctor/standoc/ref_date_id.rb +30 -1
  25. data/lib/asciidoctor/standoc/ref_sect.rb +42 -24
  26. data/lib/asciidoctor/standoc/reqt.rb +1 -1
  27. data/lib/asciidoctor/standoc/section.rb +14 -13
  28. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +50 -11
  29. data/lib/asciidoctor/standoc/terms.rb +12 -2
  30. data/lib/asciidoctor/standoc/utils.rb +36 -23
  31. data/lib/asciidoctor/standoc/validate.rb +25 -16
  32. data/lib/isodoc/html/htmlstyle.css +1 -1
  33. data/lib/isodoc/html/htmlstyle.scss +1 -1
  34. data/lib/metanorma/standoc/version.rb +1 -1
  35. data/metanorma-standoc.gemspec +3 -3
  36. data/spec/asciidoctor/base_spec.rb +4 -3
  37. data/spec/asciidoctor/blocks_spec.rb +202 -21
  38. data/spec/asciidoctor/cleanup_sections_spec.rb +7 -7
  39. data/spec/asciidoctor/cleanup_spec.rb +23 -197
  40. data/spec/asciidoctor/cleanup_terms_spec.rb +1205 -0
  41. data/spec/asciidoctor/datamodel/attributes_table_preprocessor_spec.rb +21 -21
  42. data/spec/asciidoctor/datamodel/diagram_preprocessor_spec.rb +16 -16
  43. data/spec/asciidoctor/inline_spec.rb +7 -7
  44. data/spec/asciidoctor/isobib_cache_spec.rb +4 -8
  45. data/spec/asciidoctor/macros_plantuml_spec.rb +36 -1
  46. data/spec/asciidoctor/macros_spec.rb +189 -112
  47. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  48. data/spec/asciidoctor/refs_spec.rb +860 -522
  49. data/spec/asciidoctor/section_spec.rb +18 -18
  50. data/spec/asciidoctor/validate_spec.rb +59 -2
  51. data/spec/spec_helper.rb +3 -2
  52. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +180 -180
  53. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  54. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  55. data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -27
  56. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
  57. data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
  58. data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
  59. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  60. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -65
  61. metadata +11 -8
@@ -22,37 +22,44 @@ module Asciidoctor
22
22
  { id: match[:anchor], type: "standard" }
23
23
  end
24
24
 
25
- def isorefrender1(bib, match, yr, allp = "")
25
+ def isorefrender1(bib, match, year, allp = "")
26
26
  bib.title(**plaintxt) { |i| i << ref_normalise(match[:text]) }
27
27
  docid(bib, match[:usrlbl]) if match[:usrlbl]
28
- docid(bib, id_and_year(match[:code], yr) + allp)
28
+ docid(bib, id_and_year(match[:code], year) + allp)
29
29
  docnumber(bib, match[:code])
30
30
  end
31
31
 
32
- def isorefmatches(xml, match)
32
+ def isorefmatchescode(match)
33
33
  yr = norm_year(match[:year])
34
- ref = fetch_ref xml, match[:code], yr,
35
- title: match[:text], usrlbl: match[:usrlbl],
36
- lang: (@lang || :all)
37
- return use_my_anchor(ref, match[:anchor]) if ref
38
-
39
- xml.bibitem **attr_code(ref_attributes(match)) do |t|
40
- isorefrender1(t, match, yr)
41
- yr and t.date **{ type: "published" } do |d|
42
- set_date_range(d, yr)
34
+ { code: match[:code], year: yr, match: match,
35
+ title: match[:text], usrlbl: match[:usrlbl],
36
+ lang: (@lang || :all) }
37
+ end
38
+
39
+ def isorefmatchesout(item, xml)
40
+ if item[:doc] then use_retrieved_relaton(item, xml)
41
+ else
42
+ xml.bibitem **attr_code(ref_attributes(item[:ref][:match])) do |t|
43
+ isorefrender1(t, item[:ref][:match], item[:ref][:year])
44
+ item[:ref][:year] and t.date **{ type: "published" } do |d|
45
+ set_date_range(d, item[:ref][:year])
46
+ end
47
+ iso_publisher(t, item[:ref][:match][:code])
43
48
  end
44
- iso_publisher(t, match[:code])
45
49
  end
46
50
  end
47
51
 
48
- def isorefmatches2(xml, match)
49
- ref = fetch_ref xml, match[:code], nil,
50
- no_year: true, note: match[:fn],
51
- title: match[:text], usrlbl: match[:usrlbl],
52
- lang: (@lang || :all)
53
- return use_my_anchor(ref, match[:anchor]) if ref
52
+ def isorefmatches2code(match)
53
+ { code: match[:code], no_year: true,
54
+ note: match[:fn], year: nil, match: match,
55
+ title: match[:text], usrlbl: match[:usrlbl],
56
+ lang: (@lang || :all) }
57
+ end
54
58
 
55
- isorefmatches2_1(xml, match)
59
+ def isorefmatches2out(item, xml)
60
+ if item[:doc] then use_retrieved_relaton(item, xml)
61
+ else isorefmatches2_1(xml, item[:ref][:match])
62
+ end
56
63
  end
57
64
 
58
65
  def isorefmatches2_1(xml, match)
@@ -70,16 +77,22 @@ module Asciidoctor
70
77
  end
71
78
  end
72
79
 
73
- def isorefmatches3(xml, match)
80
+ def isorefmatches3code(match)
74
81
  yr = norm_year(match[:year])
75
82
  hasyr = !yr.nil? && yr != "--"
76
- ref = fetch_ref(xml, match[:code], hasyr ? yr : nil,
77
- all_parts: true, no_year: yr == "--",
78
- text: match[:text], usrlbl: match[:usrlbl],
79
- lang: (@lang || :all))
80
- return use_my_anchor(ref, match[:anchor]) if ref
81
-
82
- isorefmatches3_1(xml, match, yr, hasyr, ref)
83
+ { code: match[:code], match: match, yr: yr, hasyr: hasyr,
84
+ year: hasyr ? yr : nil,
85
+ all_parts: true, no_year: yr == "--",
86
+ text: match[:text], usrlbl: match[:usrlbl],
87
+ lang: (@lang || :all) }
88
+ end
89
+
90
+ def isorefmatches3out(item, xml)
91
+ if item[:doc] then use_retrieved_relaton(item, xml)
92
+ else
93
+ isorefmatches3_1(xml, item[:ref][:match], item[:ref][:yr],
94
+ item[:ref][:hasyr], item[:doc])
95
+ end
83
96
  end
84
97
 
85
98
  def isorefmatches3_1(xml, match, yr, _hasyr, _ref)
@@ -120,56 +133,34 @@ module Asciidoctor
120
133
  end
121
134
 
122
135
  MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
123
- "https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
124
- "https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
125
-
126
- def analyse_ref_nofetch(ret)
127
- return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
128
-
129
- ret.merge(id: m[:id], nofetch: true)
130
- end
131
-
132
- def analyse_ref_repo_path(ret)
133
- return ret unless m =
134
- /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
135
-
136
- id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
137
- ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
138
- end
139
-
140
- def analyse_ref_numeric(ret)
141
- return ret unless /^\d+$/.match?(ret[:id])
142
-
143
- ret.merge(numeric: true)
144
- end
145
-
146
- # ref id = (usrlbl)code[:-]year
147
- # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
148
- def analyse_ref_code(code)
149
- ret = { id: code }
150
- return ret if code.blank?
151
-
152
- analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
153
- end
136
+ "https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
137
+ "https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
154
138
 
155
139
  # TODO: alternative where only title is available
156
- def refitem(xml, item, node)
157
- m = NON_ISO_REF.match(item) and return refitem1(xml, item, m)
140
+ def refitemcode(item, node)
141
+ m = NON_ISO_REF.match(item) and return refitem1code(item, m)
158
142
  @log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
159
- nil
143
+ {}
160
144
  end
161
145
 
162
- def refitem1(xml, _item, match)
146
+ def refitem1code(_item, match)
163
147
  code = analyse_ref_code(match[:code])
164
- unless code[:id] && code[:numeric] || code[:nofetch]
165
- ref = fetch_ref(xml, code[:id],
166
- match.names.include?("year") ? match[:year] : nil,
167
- title: match[:text],
168
- usrlbl: match[:usrlbl], lang: (@lang || :all)) and
169
- return use_my_anchor(ref, match[:anchor])
148
+ if (code[:id] && code[:numeric]) || code[:nofetch]
149
+ { code: nil, match: match, analyse_code: code }
150
+ else
151
+ { code: code[:id], analyse_code: code,
152
+ year: match.names.include?("year") ? match[:year] : nil,
153
+ title: match[:text], match: match,
154
+ usrlbl: match[:usrlbl], lang: (@lang || :all) }
170
155
  end
156
+ end
157
+
158
+ def refitemout(item, xml)
159
+ return nil if item[:ref][:match].nil?
171
160
 
172
- refitem_render(xml, match, code)
161
+ item[:doc] or return refitem_render(xml, item[:ref][:match],
162
+ item[:ref][:analyse_code])
163
+ use_retrieved_relaton(item, xml)
173
164
  end
174
165
 
175
166
  def ref_normalise(ref)
@@ -211,15 +202,50 @@ module Asciidoctor
211
202
  [matched, matched2, matched3]
212
203
  end
213
204
 
214
- def reference1(node, item, xml)
205
+ def reference1code(item, node)
215
206
  matched, matched2, matched3 = reference1_matches(item)
216
207
  if matched3.nil? && matched2.nil? && matched.nil?
217
- refitem(xml, item, node)
218
- elsif !matched.nil? then isorefmatches(xml, matched)
219
- elsif !matched2.nil? then isorefmatches2(xml, matched2)
220
- elsif !matched3.nil? then isorefmatches3(xml, matched3)
208
+ refitemcode(item, node).merge(process: 0)
209
+ elsif !matched.nil? then isorefmatchescode(matched).merge(process: 1)
210
+ elsif !matched2.nil? then isorefmatches2code(matched2).merge(process: 2)
211
+ elsif !matched3.nil? then isorefmatches3code(matched3).merge(process: 3)
221
212
  end
222
213
  end
214
+
215
+ def reference1out(item, xml)
216
+ case item[:ref][:process]
217
+ when 0 then refitemout(item, xml)
218
+ when 1 then isorefmatchesout(item, xml)
219
+ when 2 then isorefmatches2out(item, xml)
220
+ when 3 then isorefmatches3out(item, xml)
221
+ end
222
+ end
223
+
224
+ def reference_preproc(node)
225
+ refs = node.items.each_with_object([]) do |b, m|
226
+ m << reference1code(b.text, node)
227
+ end
228
+ results = refs.each_with_index.with_object(Queue.new) do |(ref, i), res|
229
+ fetch_ref_async(ref.merge(ord: i), i, res)
230
+ end
231
+ [refs, results]
232
+ end
233
+
234
+ def reference(node)
235
+ refs, results = reference_preproc(node)
236
+ noko do |xml|
237
+ ret = refs.each.with_object([]) do |_, m|
238
+ ref, i, doc = results.pop
239
+ m[i.to_i] = { ref: ref }
240
+ if doc.is_a?(RelatonBib::RequestError)
241
+ @log.add("Bibliography", nil, "Could not retrieve #{ref[:code]}: "\
242
+ "no access to online site")
243
+ else m[i.to_i][:doc] = doc
244
+ end
245
+ end
246
+ ret.each { |b| reference1out(b, xml) }
247
+ end.join
248
+ end
223
249
  end
224
250
  end
225
251
  end
@@ -26,7 +26,7 @@ module Asciidoctor
26
26
  def conditional_date(bib, match, noyr)
27
27
  if match.names.include?("year") && !match[:year].nil?
28
28
  bib.date(**{ type: "published" }) do |d|
29
- noyr and d.on "--" or set_date_range(d, norm_year(match[:year]))
29
+ (noyr and d.on "--") or set_date_range(d, norm_year(match[:year]))
30
30
  end
31
31
  end
32
32
  end
@@ -57,6 +57,35 @@ module Asciidoctor
57
57
  def mn_code(code)
58
58
  code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
59
59
  end
60
+
61
+ def analyse_ref_nofetch(ret)
62
+ return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
63
+
64
+ ret.merge(id: m[:id], nofetch: true)
65
+ end
66
+
67
+ def analyse_ref_repo_path(ret)
68
+ return ret unless m =
69
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
70
+
71
+ id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
72
+ ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
73
+ end
74
+
75
+ def analyse_ref_numeric(ret)
76
+ return ret unless /^\d+$/.match?(ret[:id])
77
+
78
+ ret.merge(numeric: true)
79
+ end
80
+
81
+ # ref id = (usrlbl)code[:-]year
82
+ # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
83
+ def analyse_ref_code(code)
84
+ ret = { id: code }
85
+ return ret if code.blank?
86
+
87
+ analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
88
+ end
60
89
  end
61
90
  end
62
91
  end
@@ -9,23 +9,15 @@ module Asciidoctor
9
9
  @norm_ref
10
10
  end
11
11
 
12
- def reference(node)
13
- noko do |xml|
14
- node.items.each { |item| reference1(node, item.text, xml) }
15
- end.join
16
- end
17
-
18
12
  def bibliography_parse(attrs, xml, node)
19
- node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
20
- node.attr("style") == "bibliography" or
21
- @log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
13
+ x = biblio_prep(attrs, xml, node) and return x
22
14
  @biblio = true
23
- xml.references **attr_code(attrs.merge(
24
- normative: node.attr("normative") || false)) do |xml_section|
25
- xml_section.title { |t| t << node.title }
26
- xml_section << node.content
27
- end
28
- @biblio = false
15
+ attrs = attrs.merge(normative: node.attr("normative") || false)
16
+ xml.references **attr_code(attrs) do |xml_section|
17
+ xml_section.title { |t| t << node.title }
18
+ xml_section << node.content
19
+ end
20
+ @biblio = false
29
21
  end
30
22
 
31
23
  def bibitem_parse(attrs, xml, node)
@@ -33,15 +25,14 @@ module Asciidoctor
33
25
  biblio = @biblio
34
26
  @biblio = false
35
27
  @norm_ref = false
36
- clause_parse(attrs, xml, node)
28
+ ret = clause_parse(attrs, xml, node)
37
29
  @biblio = biblio
38
30
  @norm_ref = norm_ref
31
+ ret
39
32
  end
40
33
 
41
34
  def norm_ref_parse(attrs, xml, node)
42
- node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
43
- node.attr("style") == "bibliography" or
44
- @log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
35
+ x = biblio_prep(attrs, xml, node) and return x
45
36
  @norm_ref = true
46
37
  attrs = attrs.merge(normative: node.attr("normative") || true)
47
38
  xml.references **attr_code(attrs) do |xml_section|
@@ -51,6 +42,17 @@ module Asciidoctor
51
42
  @norm_ref = false
52
43
  end
53
44
 
45
+ def biblio_prep(attrs, xml, node)
46
+ if node.option? "bibitem"
47
+ bibitem_parse(attrs, xml, node)
48
+ else
49
+ node.attr("style") == "bibliography" or
50
+ @log.add("AsciiDoc Input", node,
51
+ "Section not marked up as [bibliography]!")
52
+ nil
53
+ end
54
+ end
55
+
54
56
  def global_ievcache_name
55
57
  "#{Dir.home}/.iev/cache"
56
58
  end
@@ -74,10 +76,20 @@ module Asciidoctor
74
76
  xml
75
77
  rescue RelatonBib::RequestError
76
78
  @log.add("Bibliography", nil, "Could not retrieve #{code}: "\
77
- "no access to online site")
79
+ "no access to online site")
78
80
  nil
79
81
  end
80
82
 
83
+ def fetch_ref_async(ref, idx, res)
84
+ if ref[:code].nil? || ref[:no_year] || @bibdb.nil?
85
+ res << [ref, idx, nil]
86
+ else
87
+ @bibdb.fetch_async(ref[:code], ref[:year], ref) do |doc|
88
+ res << [ref, idx, doc]
89
+ end
90
+ end
91
+ end
92
+
81
93
  def emend_biblio(xml, code, title, usrlbl)
82
94
  unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
83
95
  @log.add("Bibliography", nil,
@@ -87,10 +99,10 @@ module Asciidoctor
87
99
  unless xml.at("/bibitem/title[text()]")
88
100
  @log.add("Bibliography", nil,
89
101
  "ERROR: No title retrieved for #{code}")
90
- xml.root << "<title>#{title || "(MISSING TITLE)"}</title>"
102
+ xml.root << "<title>#{title || '(MISSING TITLE)'}</title>"
91
103
  end
92
104
  usrlbl and xml.at("/bibitem/docidentifier").next =
93
- "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
105
+ "<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
94
106
  end
95
107
 
96
108
  def smart_render_xml(xml, code, opts)
@@ -104,6 +116,12 @@ module Asciidoctor
104
116
  xml.to_xml.sub(/<\?[^>]+>/, "")
105
117
  end
106
118
 
119
+ def use_retrieved_relaton(item, xml)
120
+ xml.parent.add_child(smart_render_xml(item[:doc], item[:ref][:code],
121
+ item[:ref]))
122
+ use_my_anchor(xml, item[:ref][:match][:anchor])
123
+ end
124
+
107
125
  def init_bib_caches(node)
108
126
  return if @no_isobib
109
127
 
@@ -113,7 +131,7 @@ module Asciidoctor
113
131
  @bibdb = Relaton::DbCache.init_bib_caches(
114
132
  local_cache: local,
115
133
  flush_caches: node.attr("flush-caches"),
116
- global_cache: global
134
+ global_cache: global,
117
135
  )
118
136
  end
119
137
 
@@ -128,7 +146,7 @@ module Asciidoctor
128
146
  FileUtils.rm_f @iev_localname unless @iev_localname.nil?
129
147
  end
130
148
  end
131
- #@iev = Iev::Db.new(globalname, localname) unless @no_isobib
149
+ # @iev = Iev::Db.new(globalname, localname) unless @no_isobib
132
150
  end
133
151
  end
134
152
  end
@@ -1,5 +1,5 @@
1
1
  require "htmlentities"
2
- require "uri"
2
+ require "uri" if /^2\./.match?(RUBY_VERSION)
3
3
  require "mime/types"
4
4
  require "base64"
5
5
 
@@ -1,4 +1,4 @@
1
- require "uri"
1
+ require "uri" if /^2\./.match?(RUBY_VERSION)
2
2
  require_relative "ref_sect"
3
3
  require_relative "terms"
4
4
 
@@ -18,7 +18,7 @@ module Asciidoctor
18
18
  def sectiontype(node, level = true)
19
19
  ret = sectiontype1(node)
20
20
  ret1 = sectiontype_streamline(ret)
21
- return ret1 if "symbols and abbreviated terms" == ret1
21
+ return ret1 if ret1 == "symbols and abbreviated terms"
22
22
  return nil unless !level || node.level == 1
23
23
  return nil if @seen_headers.include? ret
24
24
 
@@ -49,7 +49,8 @@ module Asciidoctor
49
49
  script: node.attributes["script"],
50
50
  number: node.attributes["number"],
51
51
  type: node.attributes["type"],
52
- annex: (if (node.attr("style") == "appendix" || node.role == "appendix") &&
52
+ annex: (if (node.attr("style") == "appendix" ||
53
+ node.role == "appendix") &&
53
54
  node.level == 1
54
55
  true
55
56
  end),
@@ -84,13 +85,11 @@ module Asciidoctor
84
85
  else
85
86
  if @term_def then term_def_subclause_parse(a, xml, node)
86
87
  elsif @definitions then symbols_parse(a, xml, node)
87
- elsif @norm_ref then norm_ref_parse(a, xml, node)
88
- elsif @biblio then bibliography_parse(a, xml, node)
89
- elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "normative references"
88
+ elsif @norm_ref ||
89
+ (node.attr("style") == "bibliography" &&
90
+ sectiontype(node, false) == "normative references")
90
91
  norm_ref_parse(a, xml, node)
91
- elsif node.attr("style") == "bibliography" && sectiontype(node, false) == "bibliography"
92
- bibliography_parse(a, xml, node)
93
- elsif node.attr("style") == "bibliography"
92
+ elsif @biblio || node.attr("style") == "bibliography"
94
93
  bibliography_parse(a, xml, node)
95
94
  elsif node.attr("style") == "abstract"
96
95
  abstract_parse(a, xml, node)
@@ -118,7 +117,9 @@ module Asciidoctor
118
117
  def preamble(node)
119
118
  noko do |xml|
120
119
  xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
121
- xml_abstract.title { |t| t << (node.blocks[0].title || @i18n.foreword) }
120
+ xml_abstract.title do |t|
121
+ t << (node.blocks[0].title || @i18n.foreword)
122
+ end
122
123
  content = node.content
123
124
  xml_abstract << content
124
125
  end
@@ -143,7 +144,7 @@ module Asciidoctor
143
144
  end
144
145
 
145
146
  def clause_parse(attrs, xml, node)
146
- attrs["inline-header".to_sym] = node.option? "inline-header"
147
+ attrs[:"inline-header"] = node.option? "inline-header"
147
148
  attrs[:bibitem] = true if node.option? "bibitem"
148
149
  attrs[:level] = node.attr("level")
149
150
  set_obligation(attrs, node)
@@ -154,7 +155,7 @@ module Asciidoctor
154
155
  end
155
156
 
156
157
  def annex_parse(attrs, xml, node)
157
- attrs["inline-header".to_sym] = node.option? "inline-header"
158
+ attrs[:"inline-header"] = node.option? "inline-header"
158
159
  set_obligation(attrs, node)
159
160
  xml.annex **attr_code(attrs) do |xml_section|
160
161
  xml_section.title { |name| name << node.title }
@@ -180,7 +181,7 @@ module Asciidoctor
180
181
 
181
182
  def acknowledgements_parse(attrs, xml, node)
182
183
  xml.acknowledgements **attr_code(attrs) do |xml_section|
183
- xml_section.title { |t| t << node.title || @i18n.acknowledgements }
184
+ xml_section.title { |t| (t << node.title) || @i18n.acknowledgements }
184
185
  content = node.content
185
186
  xml_section << content
186
187
  end
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true.
2
+ require "asciidoctor/standoc/utils"
3
+
2
4
 
3
5
  module Asciidoctor
4
6
  module Standoc
@@ -13,7 +15,7 @@ module Asciidoctor
13
15
  def initialize(xmldoc, log)
14
16
  @xmldoc = xmldoc
15
17
  @log = log
16
- @termlookup = { term: {}, symbol: {} }
18
+ @termlookup = { term: {}, symbol: {}, secondary2primary: {} }
17
19
  @idhash = {}
18
20
  end
19
21
 
@@ -22,6 +24,7 @@ module Asciidoctor
22
24
  @termlookup = replace_automatic_generated_ids_terms
23
25
  set_termxref_tags_target
24
26
  concept_cleanup
27
+ related_cleanup
25
28
  end
26
29
 
27
30
  private
@@ -29,6 +32,19 @@ module Asciidoctor
29
32
  def concept_cleanup
30
33
  xmldoc.xpath("//concept").each do |n|
31
34
  n.delete("type")
35
+ refterm = n.at("./refterm") or next
36
+ p = @termlookup[:secondary2primary][refterm.text] and
37
+ refterm.children = p
38
+ end
39
+ end
40
+
41
+ def related_cleanup
42
+ xmldoc.xpath("//related").each do |n|
43
+ refterm = n.at("./refterm") or next
44
+ p = @termlookup[:secondary2primary][refterm.text] and
45
+ refterm.children = p
46
+ refterm.replace("<preferred><expression><name>#{refterm.children.to_xml}"\
47
+ "</name></expression></preferred>")
32
48
  end
33
49
  end
34
50
 
@@ -47,8 +63,7 @@ module Asciidoctor
47
63
  remove_missing_ref(node, target)
48
64
  next
49
65
  end
50
- x = node.at("../xrefrender")
51
- modify_ref_node(x, target)
66
+ x = node.at("../xrefrender") and modify_ref_node(x, target)
52
67
  node.name = "refterm"
53
68
  end
54
69
  end
@@ -66,12 +81,12 @@ module Asciidoctor
66
81
  %(Error: Term reference in `term[#{target}]` missing: \
67
82
  "#{target}" is not defined in document))
68
83
  node.name = "strong"
69
- node.at("../xrefrender").remove
84
+ node&.at("../xrefrender")&.remove
70
85
  display = node&.at("../renderterm")&.remove&.children
71
86
  display = [] if display.nil? || display&.to_xml == node.text
72
87
  d = display.empty? ? "" : ", display <tt>#{display.to_xml}</tt>"
73
88
  node.children = "term <tt>#{node.text}</tt>#{d} "\
74
- "not resolved via ID <tt>#{target}</tt>"
89
+ "not resolved via ID <tt>#{target}</tt>"
75
90
  end
76
91
 
77
92
  def remove_missing_ref_symbol(node, target)
@@ -79,12 +94,12 @@ module Asciidoctor
79
94
  %(Error: Symbol reference in `symbol[#{target}]` missing: \
80
95
  "#{target}" is not defined in document))
81
96
  node.name = "strong"
82
- node.at("../xrefrender").remove
97
+ node&.at("../xrefrender")&.remove
83
98
  display = node&.at("../renderterm")&.remove&.children
84
99
  display = [] if display.nil? || display&.to_xml == node.text
85
100
  d = display.empty? ? "" : ", display <tt>#{display.to_xml}</tt>"
86
101
  node.children = "symbol <tt>#{node.text}</tt>#{d} "\
87
- "not resolved via ID <tt>#{target}</tt>"
102
+ "not resolved via ID <tt>#{target}</tt>"
88
103
  end
89
104
 
90
105
  def modify_ref_node(node, target)
@@ -92,24 +107,40 @@ module Asciidoctor
92
107
  s = termlookup[:symbol][target]
93
108
  t = termlookup[:term][target]
94
109
  type = node.parent["type"]
95
- if type == "term" || !type && t
110
+ if type == "term" || ((!type || node.parent.name == "related") && t)
96
111
  node["target"] = t
97
- elsif type == "symbol" || !type && s
112
+ elsif type == "symbol" ||
113
+ ((!type || node.parent.name == "related") && s)
98
114
  node["target"] = s
99
115
  end
100
116
  end
101
117
 
102
118
  def replace_automatic_generated_ids_terms
103
119
  r = xmldoc.xpath("//term").each.with_object({}) do |n, res|
104
- normalize_id_and_memorize(n, res, "./preferred", "term")
120
+ normalize_id_and_memorize(n, res, "./preferred//name",
121
+ "term")
105
122
  end
106
123
  s = xmldoc.xpath("//definitions//dt").each.with_object({}) do |n, res|
107
124
  normalize_id_and_memorize(n, res, ".", "symbol")
108
125
  end
109
- { term: r, symbol: s }
126
+ { term: r, symbol: s, secondary2primary: pref_secondary2primary }
127
+ end
128
+
129
+ def pref_secondary2primary
130
+ xmldoc.xpath("//term").each.with_object({}) do |n, res|
131
+ n.xpath("./preferred//name").each_with_index do |p, i|
132
+ i.zero? and term = p.text
133
+ i.positive? and res[p.text] = term
134
+ end
135
+ end
110
136
  end
111
137
 
112
138
  def normalize_id_and_memorize(node, res_table, text_selector, prefix)
139
+ normalize_id_and_memorize_init(node, res_table, text_selector, prefix)
140
+ memorize_other_pref_terms(node, res_table, text_selector)
141
+ end
142
+
143
+ def normalize_id_and_memorize_init(node, res_table, text_selector, prefix)
113
144
  term_text = normalize_ref_id(node.at(text_selector).text)
114
145
  unless AUTOMATIC_GENERATED_ID_REGEXP.match(node["id"]).nil? &&
115
146
  !node["id"].nil?
@@ -120,6 +151,14 @@ module Asciidoctor
120
151
  res_table[term_text] = node["id"]
121
152
  end
122
153
 
154
+ def memorize_other_pref_terms(node, res_table, text_selector)
155
+ node.xpath(text_selector).each_with_index do |p, i|
156
+ next unless i.positive?
157
+
158
+ res_table[normalize_ref_id(p.text)] = node["id"]
159
+ end
160
+ end
161
+
123
162
  def normalize_ref_id(text)
124
163
  Metanorma::Utils::to_ncname(text.downcase.gsub(/[[:space:]]/, "-"))
125
164
  end
@@ -69,7 +69,7 @@ module Asciidoctor
69
69
 
70
70
  def term_def_subclause_parse1(attrs, xml, node)
71
71
  xml.term **attr_code(attrs) do |xml_section|
72
- xml_section.preferred { |name| name << node.title }
72
+ term_designation(xml_section, node, "preferred", node.title)
73
73
  xml_section << node.content
74
74
  end
75
75
  end
@@ -84,6 +84,14 @@ module Asciidoctor
84
84
  end
85
85
  end
86
86
 
87
+ def term_designation(xml, _node, tag, text)
88
+ xml.send tag do |p|
89
+ p.expression do |e|
90
+ e.name { |name| name << text }
91
+ end
92
+ end
93
+ end
94
+
87
95
  def term_source_attrs(_node, seen_xref)
88
96
  { case: seen_xref.children[0]["case"],
89
97
  droploc: seen_xref.children[0]["droploc"],
@@ -124,7 +132,9 @@ module Asciidoctor
124
132
  def termsource(node)
125
133
  matched = extract_termsource_refs(node.content, node) || return
126
134
  noko do |xml|
127
- attrs = { status: matched[:text] ? "modified" : "identical" }
135
+ status = node.attr("status") ||
136
+ (matched[:text] ? "modified" : "identical")
137
+ attrs = { status: status, type: node.attr("type") || "authoritative" }
128
138
  xml.termsource **attrs do |xml_t|
129
139
  seen_xref = Nokogiri::XML.fragment(matched[:xref])
130
140
  add_term_source(node, xml_t, seen_xref, matched)