metanorma-standoc 1.9.0 → 1.10.0

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -13
  3. data/.hound.yml +3 -1
  4. data/.rubocop.yml +4 -8
  5. data/lib/asciidoctor/standoc/base.rb +31 -35
  6. data/lib/asciidoctor/standoc/biblio.rng +1 -0
  7. data/lib/asciidoctor/standoc/blocks.rb +25 -9
  8. data/lib/asciidoctor/standoc/blocks_notes.rb +41 -24
  9. data/lib/asciidoctor/standoc/cleanup.rb +59 -84
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +63 -85
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -15
  12. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
  13. data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
  15. data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
  16. data/lib/asciidoctor/standoc/cleanup_ref.rb +31 -15
  17. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
  18. data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
  19. data/lib/asciidoctor/standoc/cleanup_section.rb +77 -135
  20. data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
  21. data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
  22. data/lib/asciidoctor/standoc/converter.rb +7 -2
  23. data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
  24. data/lib/asciidoctor/standoc/front.rb +35 -18
  25. data/lib/asciidoctor/standoc/front_contributor.rb +70 -45
  26. data/lib/asciidoctor/standoc/inline.rb +45 -34
  27. data/lib/asciidoctor/standoc/isodoc.rng +209 -4
  28. data/lib/asciidoctor/standoc/lists.rb +4 -2
  29. data/lib/asciidoctor/standoc/macros.rb +11 -11
  30. data/lib/asciidoctor/standoc/macros_form.rb +63 -0
  31. data/lib/asciidoctor/standoc/macros_plantuml.rb +19 -21
  32. data/lib/asciidoctor/standoc/macros_terms.rb +33 -23
  33. data/lib/asciidoctor/standoc/ref.rb +87 -112
  34. data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
  35. data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
  36. data/lib/asciidoctor/standoc/section.rb +3 -1
  37. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +40 -27
  38. data/lib/asciidoctor/standoc/terms.rb +25 -18
  39. data/lib/asciidoctor/standoc/utils.rb +35 -9
  40. data/lib/asciidoctor/standoc/validate.rb +48 -33
  41. data/lib/metanorma-standoc.rb +0 -1
  42. data/lib/metanorma/standoc/version.rb +1 -1
  43. data/metanorma-standoc.gemspec +4 -4
  44. data/spec/asciidoctor/base_spec.rb +701 -508
  45. data/spec/asciidoctor/blocks_spec.rb +831 -738
  46. data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
  47. data/spec/asciidoctor/cleanup_spec.rb +889 -682
  48. data/spec/asciidoctor/inline_spec.rb +62 -14
  49. data/spec/asciidoctor/isobib_cache_spec.rb +404 -358
  50. data/spec/asciidoctor/lists_spec.rb +149 -137
  51. data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
  52. data/spec/asciidoctor/macros_spec.rb +923 -503
  53. data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
  54. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  55. data/spec/asciidoctor/refs_spec.rb +1528 -1533
  56. data/spec/asciidoctor/section_spec.rb +405 -299
  57. data/spec/asciidoctor/table_spec.rb +6 -6
  58. data/spec/asciidoctor/validate_spec.rb +342 -304
  59. data/spec/spec_helper.rb +13 -9
  60. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -54
  61. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  62. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  63. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
  64. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  65. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  66. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  67. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
  68. metadata +16 -15
  69. data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
  70. data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
  71. data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
  72. data/lib/liquid/custom_filters/values.rb +0 -7
@@ -3,7 +3,7 @@ require "nokogiri"
3
3
  require "htmlentities"
4
4
  require "pathname"
5
5
  require "open-uri"
6
- require_relative "./front_contributor.rb"
6
+ require_relative "./front_contributor"
7
7
 
8
8
  module Asciidoctor
9
9
  module Standoc
@@ -40,6 +40,7 @@ module Asciidoctor
40
40
 
41
41
  def metadata_committee(node, xml)
42
42
  return unless node.attr("technical-committee")
43
+
43
44
  xml.editorialgroup do |a|
44
45
  committee_component("technical-committee", node, a)
45
46
  end
@@ -47,8 +48,8 @@ module Asciidoctor
47
48
 
48
49
  def metadata_ics(node, xml)
49
50
  ics = node.attr("library-ics")
50
- ics && ics.split(/,\s*/).each do |i|
51
- xml.ics { |ics| ics.code i }
51
+ ics&.split(/,\s*/)&.each do |i|
52
+ xml.ics { |elem| elem.code i }
52
53
  end
53
54
  end
54
55
 
@@ -71,15 +72,15 @@ module Asciidoctor
71
72
 
72
73
  def datetypes
73
74
  %w{ published accessed created implemented obsoleted
74
- confirmed updated issued circulated unchanged received
75
- vote-started vote-ended
76
- }
75
+ confirmed updated issued circulated unchanged received
76
+ vote-started vote-ended announced }
77
77
  end
78
78
 
79
79
  def metadata_date(node, xml)
80
80
  datetypes.each { |t| metadata_date1(node, xml, t) }
81
- node.attributes.keys.each do |a|
81
+ node.attributes.each_key do |a|
82
82
  next unless a == "date" || /^date_\d+$/.match(a)
83
+
83
84
  type, date = node.attr(a).split(/ /, 2)
84
85
  type or next
85
86
  xml.date **{ type: type } do |d|
@@ -93,7 +94,8 @@ module Asciidoctor
93
94
  end
94
95
 
95
96
  def metadata_script(node, xml)
96
- xml.script (node.attr("script") || default_script(node.attr("language")))
97
+ xml.script (node.attr("script") ||
98
+ default_script(node.attr("language")))
97
99
  end
98
100
 
99
101
  def relaton_relations
@@ -114,8 +116,8 @@ module Asciidoctor
114
116
  end
115
117
 
116
118
  def relation_normalise(type)
117
- type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From").
118
- sub(/-in$/, "In")
119
+ type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
120
+ .sub(/-in$/, "In")
119
121
  end
120
122
 
121
123
  def metadata_getrelation(node, xml, type, desc = nil)
@@ -124,8 +126,8 @@ module Asciidoctor
124
126
  id = d.split(/,\s*/)
125
127
  xml.relation **{ type: relation_normalise(type) } do |r|
126
128
  desc.nil? or r.description relation_normalise(desc)
127
- fetch_ref(r, d, nil, {}) or r.bibitem do |b|
128
- b.title id[1] ? id[1] : "--"
129
+ fetch_ref(r, d, nil, **{}) or r.bibitem do |b|
130
+ b.title id[1] || "--"
129
131
  b.docidentifier id[0]
130
132
  end
131
133
  end
@@ -134,11 +136,20 @@ module Asciidoctor
134
136
 
135
137
  def metadata_keywords(node, xml)
136
138
  return unless node.attr("keywords")
137
- node.attr("keywords").split(/,[ ]*/).each do |kw|
139
+
140
+ node.attr("keywords").split(/,\s*/).each do |kw|
138
141
  xml.keyword kw
139
142
  end
140
143
  end
141
144
 
145
+ def metadata_classifications(node, xml)
146
+ csv_split(node.attr("classification"), ",")&.each do |c|
147
+ vals = c.split(/:/, 2)
148
+ vals.size == 1 and vals = ["default", vals[0]]
149
+ xml.classification vals[1], type: vals[0]
150
+ end
151
+ end
152
+
142
153
  def metadata(node, xml)
143
154
  title node, xml
144
155
  metadata_source(node, xml)
@@ -155,14 +166,16 @@ module Asciidoctor
155
166
  metadata_copyright(node, xml)
156
167
  metadata_relations(node, xml)
157
168
  metadata_series(node, xml)
169
+ metadata_classifications(node, xml)
158
170
  metadata_keywords(node, xml)
159
- xml.ext do |ext|
171
+ xml.ext do
160
172
  metadata_ext(node, xml)
161
173
  end
162
174
  end
163
175
 
164
176
  def metadata_ext(node, ext)
165
177
  metadata_doctype(node, ext)
178
+ metadata_subdoctype(node, ext)
166
179
  metadata_committee(node, ext)
167
180
  metadata_ics(node, ext)
168
181
  end
@@ -171,11 +184,13 @@ module Asciidoctor
171
184
  xml.doctype doctype(node)
172
185
  end
173
186
 
174
- def metadata_note(node, xml)
187
+ def metadata_subdoctype(node, xml)
188
+ s = node.attr("docsubtype") and xml.subdoctype s
175
189
  end
176
190
 
177
- def metadata_series(node, xml)
178
- end
191
+ def metadata_note(node, xml); end
192
+
193
+ def metadata_series(node, xml); end
179
194
 
180
195
  def title(node, xml)
181
196
  title_english(node, xml)
@@ -187,7 +202,8 @@ module Asciidoctor
187
202
  at = { language: lang, format: "text/plain" }
188
203
  xml.title **attr_code(at) do |t|
189
204
  t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
190
- node.attr("title-en")) || node.title)
205
+ node.attr("title-en")) ||
206
+ node.title)
191
207
  end
192
208
  end
193
209
  end
@@ -196,6 +212,7 @@ module Asciidoctor
196
212
  node.attributes.each do |k, v|
197
213
  next unless /^title-(?<titlelang>.+)$/ =~ k
198
214
  next if titlelang == "en"
215
+
199
216
  xml.title v, { language: titlelang, format: "text/plain" }
200
217
  end
201
218
  end
@@ -10,18 +10,18 @@ module Asciidoctor
10
10
  module Front
11
11
  def committee_component(compname, node, out)
12
12
  out.send compname.gsub(/-/, "_"), node.attr(compname),
13
- **attr_code(number: node.attr("#{compname}-number"),
14
- type: node.attr("#{compname}-type"))
13
+ **attr_code(number: node.attr("#{compname}-number"),
14
+ type: node.attr("#{compname}-type"))
15
15
  i = 2
16
- while node.attr(compname+"_#{i}") do
17
- out.send compname.gsub(/-/, "_"), node.attr(compname+"_#{i}"),
18
- **attr_code(number: node.attr("#{compname}-number_#{i}"),
19
- type: node.attr("#{compname}-type_#{i}"))
16
+ while node.attr(compname + "_#{i}")
17
+ out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
18
+ **attr_code(number: node.attr("#{compname}-number_#{i}"),
19
+ type: node.attr("#{compname}-type_#{i}"))
20
20
  i += 1
21
21
  end
22
22
  end
23
23
 
24
- def organization(org, orgname, node = nil, default_org = nil)
24
+ def organization(org, orgname, is_pub, node = nil, default_org = nil)
25
25
  abbrevs = org_abbrev
26
26
  n = abbrevs.invert[orgname] and orgname = n
27
27
  org.name orgname
@@ -29,37 +29,39 @@ module Asciidoctor
29
29
  abbr = org_abbrev[orgname]
30
30
  default_org && b = node.attr("subdivision-abbr") and abbr = b
31
31
  abbr and org.abbreviation abbr
32
- default_org and org_address(node, org)
32
+ is_pub && node and org_address(node, org)
33
33
  end
34
34
 
35
- def org_address(node, p)
36
- node.attr("pub-address") and p.address do |ad|
35
+ def org_address(node, person)
36
+ node.attr("pub-address") and person.address do |ad|
37
37
  ad.formattedAddress do |f|
38
38
  f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
39
39
  end
40
40
  end
41
- node.attr("pub-phone") and p.phone node.attr("pub-phone")
42
- node.attr("pub-fax") and p.phone node.attr("pub-fax"), **{type: "fax"}
43
- node.attr("pub-email") and p.email node.attr("pub-email")
44
- node.attr("pub-uri") and p.uri node.attr("pub-uri")
41
+ node.attr("pub-phone") and person.phone node.attr("pub-phone")
42
+ node.attr("pub-fax") and
43
+ person.phone node.attr("pub-fax"), **{ type: "fax" }
44
+ node.attr("pub-email") and person.email node.attr("pub-email")
45
+ node.attr("pub-uri") and person.uri node.attr("pub-uri")
45
46
  end
46
47
 
47
48
  # , " => ," : CSV definition does not deal with space followed by quote
48
49
  # at start of field
49
- def csv_split(s, delim = ";")
50
- return if s.nil?
51
- CSV.parse_line(s&.gsub(/#{delim} "(?!")/, "#{delim}\""),
50
+ def csv_split(text, delim = ";")
51
+ return if text.nil?
52
+
53
+ CSV.parse_line(text&.gsub(/#{delim} "(?!")/, "#{delim}\""),
52
54
  liberal_parsing: true,
53
- col_sep: delim)&.compact&.map { |x| x.strip }
55
+ col_sep: delim)&.compact&.map(&:strip)
54
56
  end
55
57
 
56
58
  def metadata_author(node, xml)
57
- csv_split(node.attr("publisher") || default_publisher || "")&.
58
- each do |p|
59
+ csv_split(node.attr("publisher") || default_publisher || "")
60
+ &.each do |p|
59
61
  xml.contributor do |c|
60
62
  c.role **{ type: "author" }
61
63
  c.organization do |a|
62
- organization(a, p, node, !node.attr("publisher"))
64
+ organization(a, p, false, node, !node.attr("publisher"))
63
65
  end
64
66
  end
65
67
  end
@@ -76,17 +78,18 @@ module Asciidoctor
76
78
  end
77
79
  end
78
80
 
79
- def personal_role(node, c, suffix)
80
- c.role **{ type: node.attr("role#{suffix}")&.downcase || "author" }
81
+ def personal_role(node, contrib, suffix)
82
+ type = node.attr("role#{suffix}")&.downcase || "author"
83
+ contrib.role **{ type: type }
81
84
  end
82
85
 
83
- def personal_contact(node, suffix, p)
84
- node.attr("phone#{suffix}") and p.phone node.attr("phone#{suffix}")
86
+ def personal_contact(node, suffix, person)
87
+ node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
85
88
  node.attr("fax#{suffix}") and
86
- p.phone node.attr("fax#{suffix}"), **{type: "fax"}
87
- node.attr("email#{suffix}") and p.email node.attr("email#{suffix}")
89
+ person.phone node.attr("fax#{suffix}"), **{ type: "fax" }
90
+ node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
88
91
  node.attr("contributor-uri#{suffix}") and
89
- p.uri node.attr("contributor-uri#{suffix}")
92
+ person.uri node.attr("contributor-uri#{suffix}")
90
93
  end
91
94
 
92
95
  def personal_author1(node, xml, suffix)
@@ -100,8 +103,8 @@ module Asciidoctor
100
103
  end
101
104
  end
102
105
 
103
- def person_name(node, xml, suffix, p)
104
- p.name do |n|
106
+ def person_name(node, _xml, suffix, person)
107
+ person.name do |n|
105
108
  if node.attr("fullname#{suffix}")
106
109
  n.completename node.attr("fullname#{suffix}")
107
110
  else
@@ -112,21 +115,43 @@ module Asciidoctor
112
115
  end
113
116
  end
114
117
 
115
- def person_affiliation(node, xml, suffix, p)
116
- node.attr("affiliation#{suffix}") and p.affiliation do |a|
118
+ def person_affiliation(node, _xml, suffix, person)
119
+ node.attr("affiliation#{suffix}") and person.affiliation do |a|
117
120
  a.organization do |o|
118
- o.name node.attr("affiliation#{suffix}")
119
- a = node.attr("affiliation_subdiv#{suffix}")
120
- abbr = node.attr("affiliation_abbrev#{suffix}") and o.abbreviation abbr
121
- csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
122
- o.subdivision s
123
- end
124
- node.attr("address#{suffix}") and o.address do |ad|
125
- ad.formattedAddress do |f|
126
- f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
127
- end
121
+ person_organization(node, suffix, o)
122
+ end
123
+ end
124
+ end
125
+
126
+ def person_organization(node, suffix, xml)
127
+ xml.name node.attr("affiliation#{suffix}")
128
+ abbr = node.attr("affiliation_abbrev#{suffix}") and
129
+ xml.abbreviation abbr
130
+ csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
131
+ xml.subdivision s
132
+ end
133
+ person_address(node, suffix, xml)
134
+ end
135
+
136
+ def person_address(node, suffix, xml)
137
+ if node.attr("address#{suffix}")
138
+ xml.address do |ad|
139
+ ad.formattedAddress do |f|
140
+ f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
128
141
  end
129
142
  end
143
+ elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
144
+ person_address_components(node, suffix, xml)
145
+ end
146
+ end
147
+
148
+ def person_address_components(node, suffix, xml)
149
+ xml.address do |ad|
150
+ s = node.attr("street#{suffix}") and ad.street s
151
+ s = node.attr("city#{suffix}") and ad.city s
152
+ s = node.attr("state#{suffix}") and ad.state s
153
+ s = node.attr("country#{suffix}") and ad.country s
154
+ s = node.attr("postcode#{suffix}") and ad.postcode s
130
155
  end
131
156
  end
132
157
 
@@ -135,7 +160,7 @@ module Asciidoctor
135
160
  end
136
161
 
137
162
  def org_abbrev
138
- { }
163
+ {}
139
164
  end
140
165
 
141
166
  def metadata_publisher(node, xml)
@@ -144,7 +169,7 @@ module Asciidoctor
144
169
  xml.contributor do |c|
145
170
  c.role **{ type: "publisher" }
146
171
  c.organization do |a|
147
- organization(a, p, node, !node.attr("publisher"))
172
+ organization(a, p, true, node, !node.attr("publisher"))
148
173
  end
149
174
  end
150
175
  end
@@ -157,7 +182,7 @@ module Asciidoctor
157
182
  c.from (node.attr("copyright-year") || Date.today.year)
158
183
  p.match(/[A-Za-z]/).nil? or c.owner do |owner|
159
184
  owner.organization do |a|
160
- organization(a, p, node, !pub)
185
+ organization(a, p, true, node, !pub)
161
186
  end
162
187
  end
163
188
  end
@@ -9,8 +9,8 @@ require "latexmath"
9
9
  module Asciidoctor
10
10
  module Standoc
11
11
  module Inline
12
- def refid?(x)
13
- @refids.include? x
12
+ def refid?(ref)
13
+ @refids.include? ref
14
14
  end
15
15
 
16
16
  def inline_anchor(node)
@@ -46,19 +46,20 @@ module Asciidoctor
46
46
  def inline_anchor_xref_attrs(node)
47
47
  m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
48
48
  (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
49
- casing = m.nil? ? nil : m[:case]&.sub(/%$/, "")
50
- droploc = m.nil? ? nil : ((m[:drop].nil? && m[:drop2].nil?) ? nil: true)
51
- f = (m.nil? || m[:fn].nil?) ? "inline" : "footnote"
52
- c = (!m.nil? && (%i[case fn drop drop2].any? { |x| !m[x].nil? })) ?
53
- m[:text] : node.text
54
49
  t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
55
- { target: t, type: f, case: casing, droploc: droploc, text: c }
50
+ m.nil? and return { target: t, type: "inline", text: node.text }
51
+ droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
52
+ f = m[:fn].nil? ? "inline" : "footnote"
53
+ c = %i[case fn drop drop2].any? { |x| !m[x].nil? } ? m[:text] : node.text
54
+ { target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
55
+ text: c }
56
56
  end
57
57
 
58
58
  def inline_anchor_link(node)
59
59
  contents = node.text
60
60
  contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
61
- attributes = { "target": node.target, "alt": node.attr("title") }
61
+ attributes = { "target": node.target, "alt": node.attr("title"),
62
+ "updatetype": node.attr("updatetype") }
62
63
  noko do |xml|
63
64
  xml.link **attr_code(attributes) do |l|
64
65
  l << contents
@@ -67,8 +68,8 @@ module Asciidoctor
67
68
  end
68
69
 
69
70
  def inline_anchor_bibref(node)
70
- eref_contents = (node.text || node.target || node.id)&.
71
- sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
71
+ eref_contents = (node.text || node.target || node.id)
72
+ &.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
72
73
  eref_attributes = { id: node.target || node.id }
73
74
  @refids << (node.target || node.id)
74
75
  noko do |xml|
@@ -105,7 +106,7 @@ module Asciidoctor
105
106
  attrs = {}
106
107
  node.option?("landscape") and attrs[:orientation] = "landscape"
107
108
  node.option?("portrait") and attrs[:orientation] = "portrait"
108
- noko { |xml| xml.pagebreak **attr_code(attrs)}.join
109
+ noko { |xml| xml.pagebreak **attr_code(attrs) }.join
109
110
  end
110
111
 
111
112
  def thematic_break(_node)
@@ -113,41 +114,45 @@ module Asciidoctor
113
114
  end
114
115
 
115
116
  def xml_encode(text)
116
- HTMLEntities.new.encode(text, :basic, :hexadecimal).
117
- gsub(/&amp;gt;/, ">").gsub(/\&amp;lt;/, "<").gsub(/&amp;amp;/, "&").
118
- gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&").
119
- gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
117
+ HTMLEntities.new.encode(text, :basic, :hexadecimal)
118
+ .gsub(/&amp;gt;/, ">").gsub(/&amp;lt;/, "<").gsub(/&amp;amp;/, "&")
119
+ .gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
120
+ .gsub(/&quot;/, '"').gsub(/&#xa;/, "\n").gsub(/&amp;#/, "&#")
120
121
  end
121
122
 
122
- def latex_parse(text)
123
+ def latex_parse1(text)
123
124
  lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
124
125
  results = Latexmath.parse(lxm_input).to_mathml
125
126
  results.nil? and
126
- @log.add('Math', nil,
127
+ @log.add("Math", nil,
127
128
  "latexmlmath failed to process equation:\n#{lxm_input}")
128
129
  results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
129
130
  end
130
131
 
131
132
  def stem_parse(text, xml, style)
132
133
  if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
133
- <([^:>&]+:)?math(\s+[^>&]+)?>/x.match text
134
+ <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
134
135
  math = xml_encode(text)
135
136
  xml.stem math, **{ type: "MathML" }
136
- elsif style == :latexmath
137
- latex = latex_parse(text) or return xml.stem **{ type: "MathML" }
138
- xml.stem **{ type: "MathML" } do |s|
139
- math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, "")).elements[0]
140
- math.delete("alttext")
141
- s.parent.children = math
142
- end
137
+ elsif style == :latexmath then latex_parse(text, xml)
143
138
  else
144
- xml.stem text&.gsub(/\&amp;#/, "&#"), **{ type: "AsciiMath" }
139
+ xml.stem text&.gsub(/&amp;#/, "&#"), **{ type: "AsciiMath" }
145
140
  end
146
141
  end
147
142
 
148
- def highlight_parse(text, xml)
149
- xml << text
143
+ def latex_parse(text, xml)
144
+ latex = latex_parse1(text) or return xml.stem **{ type: "MathML" }
145
+ xml.stem **{ type: "MathML" } do |s|
146
+ math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
147
+ .elements[0]
148
+ math.delete("alttext")
149
+ s.parent.children = math
150
150
  end
151
+ end
152
+
153
+ def highlight_parse(text, xml)
154
+ xml << text
155
+ end
151
156
 
152
157
  def inline_quoted(node)
153
158
  noko do |xml|
@@ -182,14 +187,20 @@ module Asciidoctor
182
187
 
183
188
  def image_attributes(node)
184
189
  uri = node.image_uri (node.attr("target") || node.target)
185
- types = /^data:/.match(uri) ? Metanorma::Utils::datauri2mime(uri) : MIME::Types.type_for(uri)
190
+ types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
191
+ else MIME::Types.type_for(uri)
192
+ end
186
193
  type = types.first.to_s
187
194
  uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
188
- attr_code(src: uri,
195
+ image_attributes1(node, uri, type)
196
+ end
197
+
198
+ def image_attributes1(node, uri, type)
199
+ attr_code(src: uri,
189
200
  id: Metanorma::Utils::anchor_or_uuid,
190
201
  mimetype: type,
191
202
  height: node.attr("height") || "auto",
192
- width: node.attr("width") || "auto" ,
203
+ width: node.attr("width") || "auto",
193
204
  filename: node.attr("filename"),
194
205
  title: node.attr("titleattr"),
195
206
  alt: node.alt == node.attr("default-alt") ? nil : node.alt)
@@ -197,14 +208,14 @@ module Asciidoctor
197
208
 
198
209
  def inline_image(node)
199
210
  noko do |xml|
200
- xml.image **(image_attributes(node))
211
+ xml.image **image_attributes(node)
201
212
  end.join("")
202
213
  end
203
214
 
204
215
  def inline_indexterm(node)
205
216
  noko do |xml|
206
217
  node.type == :visible and xml << node.text
207
- terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
218
+ terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
208
219
  xml.index do |i|
209
220
  i.primary { |x| x << terms[0] }
210
221
  a = terms.dig(1) and i.secondary { |x| x << a }