metanorma-standoc 1.7.0 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +17 -0
  3. data/lib/asciidoctor/standoc/base.rb +33 -44
  4. data/lib/asciidoctor/standoc/basicdoc.rng +5 -3
  5. data/lib/asciidoctor/standoc/blocks.rb +7 -7
  6. data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
  7. data/lib/asciidoctor/standoc/cleanup.rb +28 -77
  8. data/lib/asciidoctor/standoc/cleanup_block.rb +5 -15
  9. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +56 -0
  10. data/lib/asciidoctor/standoc/cleanup_inline.rb +22 -26
  11. data/lib/asciidoctor/standoc/cleanup_maths.rb +86 -0
  12. data/lib/asciidoctor/standoc/cleanup_ref.rb +0 -85
  13. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
  14. data/lib/asciidoctor/standoc/converter.rb +0 -61
  15. data/lib/asciidoctor/standoc/front.rb +2 -2
  16. data/lib/asciidoctor/standoc/inline.rb +2 -1
  17. data/lib/asciidoctor/standoc/isodoc.rng +29 -3
  18. data/lib/asciidoctor/standoc/lists.rb +2 -2
  19. data/lib/asciidoctor/standoc/macros_plantuml.rb +1 -1
  20. data/lib/asciidoctor/standoc/ref_sect.rb +2 -2
  21. data/lib/asciidoctor/standoc/reqt.rb +6 -1
  22. data/lib/asciidoctor/standoc/section.rb +4 -80
  23. data/lib/asciidoctor/standoc/table.rb +1 -1
  24. data/lib/asciidoctor/standoc/terms.rb +125 -0
  25. data/lib/asciidoctor/standoc/utils.rb +2 -96
  26. data/lib/metanorma/standoc/version.rb +1 -1
  27. data/metanorma-standoc.gemspec +2 -3
  28. data/spec/asciidoctor-standoc/base_spec.rb +34 -5
  29. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +5 -5
  30. data/spec/asciidoctor-standoc/cleanup_spec.rb +178 -4
  31. data/spec/asciidoctor-standoc/inline_spec.rb +2 -0
  32. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -4
  33. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +1 -1
  34. data/spec/asciidoctor-standoc/refs_dl_spec.rb +17 -5
  35. data/spec/asciidoctor-standoc/refs_spec.rb +12 -12
  36. data/spec/asciidoctor-standoc/section_spec.rb +143 -3
  37. data/spec/asciidoctor-standoc/table_spec.rb +60 -0
  38. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
  39. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  40. data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
  41. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
  42. data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
  43. data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
  44. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  45. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +56 -56
  46. metadata +19 -32
  47. data/lib/asciidoctor/standoc/log.rb +0 -59
  48. data/spec/asciidoctor-standoc/converter_spec.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6af6d01c6514c3fbfe4a1bbe33b088f15eb78c7243db92fb36694d050a84635
4
- data.tar.gz: 4dc1bdc07d11ce753ff4a26482cf5adba8f81153da808a9eb68a6b4cdda13a89
3
+ metadata.gz: 90c09f71739f8d485363ce3a4f950b143c0264f5b4657fd0891df83a00c44f72
4
+ data.tar.gz: cb0c51236e8c1780aa2a89b7a0c53efeabc2a4af3ef68e6c08aa8936efdea47d
5
5
  SHA512:
6
- metadata.gz: dc0064271a3104f6e26cecdd33228befe52771b31aff7aa18e44325851ebaeb5d2bda60aca28fe5113d87097df945153723553526357e7d6225176a9dbc1067f
7
- data.tar.gz: b5f306f4fbab92edefee5887fb3acaa22d31583d37d0de0ddb8d8c469a17ced57d8300ab6254e0c860e3aa7c6519e0ce5f77eaa7986e49bfb497672997c7c743
6
+ metadata.gz: 96533136bca911c4f886e6d0aeaa0e86ce94cf754d721af5537c835b744980fef11555e494d5d485a348c1ea911d1394cfb215f9f02cbf095a90bd652cae2916
7
+ data.tar.gz: 80bd100da6d8d05fdc69f8f52d20e9af182bd3196c42074663241dc8e35bee952eb8bf7ef95fbf444dbcd25f1bd45ac7d864f70c394df372f8d24b1e26a385d7
@@ -36,6 +36,9 @@ jobs:
36
36
  with:
37
37
  ruby-version: ${{ matrix.ruby }}
38
38
 
39
+ - if: matrix.os == 'macos-latest'
40
+ run: brew install autoconf automake libtool
41
+
39
42
  - uses: actions/cache@v2
40
43
  with:
41
44
  path: vendor/bundle
@@ -64,3 +67,17 @@ jobs:
64
67
  run: cinst -y plantuml
65
68
 
66
69
  - run: bundle exec rake
70
+
71
+ tests-passed:
72
+ needs: rake
73
+ runs-on: ubuntu-latest
74
+ continue-on-error: true
75
+ steps:
76
+ - name: Trigger tests passed event
77
+ uses: Sibz/github-status-action@v1
78
+ with:
79
+ authToken: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
80
+ context: 'tests-passed-successfully'
81
+ description: 'Tests passed successfully'
82
+ state: 'success'
83
+ sha: ${{ github.event.pull_request.head.sha || github.sha }}
@@ -7,6 +7,7 @@ require "open-uri"
7
7
  require "isodoc"
8
8
  require "relaton"
9
9
  require "fileutils"
10
+ require "metanorma-utils"
10
11
 
11
12
  module Asciidoctor
12
13
  module Standoc
@@ -91,6 +92,7 @@ module Asciidoctor
91
92
  @draft = false
92
93
  @refids = Set.new
93
94
  @anchors = {}
95
+ @internal_eref_namespaces = []
94
96
  @draft = node.attributes.has_key?("draft")
95
97
  @novalid = node.attr("novalid")
96
98
  @smartquotes = node.attr("smartquotes") != "false"
@@ -98,28 +100,32 @@ module Asciidoctor
98
100
  @fontheader = default_fonts(node)
99
101
  @files_to_delete = []
100
102
  @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
101
- @localdir = Utils::localdir(node)
103
+ @localdir = Metanorma::Utils::localdir(node)
102
104
  @output_dir = outputdir node
103
105
  @no_isobib_cache = node.attr("no-isobib-cache")
104
106
  @no_isobib = node.attr("no-isobib")
107
+ @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
108
+ @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
105
109
  @bibdb = nil
106
110
  @seen_headers = []
107
111
  @datauriimage = node.attr("data-uri-image")
108
112
  @boilerplateauthority = node.attr("boilerplate-authority")
109
- @log = Asciidoctor::Standoc::Log.new
113
+ @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
114
+ @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
115
+ @log = Metanorma::Utils::Log.new
110
116
  init_bib_caches(node)
111
117
  init_iev_caches(node)
112
118
  @lang = (node.attr("language") || "en")
113
- @script = (node.attr("script") || "Latn")
119
+ @script = (node.attr("script") || default_script(node.attr("language")))
114
120
  @isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
115
121
  @i18n = @isodoc.i18n
116
122
  end
117
123
 
118
124
  def default_fonts(node)
119
125
  b = node.attr("body-font") ||
120
- (node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif')
126
+ (node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
121
127
  h = node.attr("header-font") ||
122
- (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif')
128
+ (node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
123
129
  m = node.attr("monospace-font") || '"Courier New",monospace'
124
130
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
125
131
  end
@@ -185,52 +191,35 @@ module Asciidoctor
185
191
  end
186
192
  end
187
193
 
188
- def term_source_attrs(seen_xref)
189
- { bibitemid: seen_xref.children[0]["target"],
190
- format: seen_xref.children[0]["format"], type: "inline" }
191
- end
192
-
193
- def add_term_source(xml_t, seen_xref, m)
194
- if seen_xref.children[0].name == "concept"
195
- xml_t.origin { |o| o << seen_xref.children[0].to_xml }
194
+ def default_script(lang)
195
+ case lang
196
+ when "ar", "fa"
197
+ "Arab"
198
+ when "ur"
199
+ "Aran"
200
+ when "ru", "bg"
201
+ "Cyrl"
202
+ when "hi"
203
+ "Deva"
204
+ when "el"
205
+ "Grek"
206
+ when "zh"
207
+ "Hans"
208
+ when "ko"
209
+ "Kore"
210
+ when "he"
211
+ "Hebr"
212
+ when "ja"
213
+ "Jpan"
196
214
  else
197
- xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
215
+ "Latn"
198
216
  end
199
- m[:text] && xml_t.modification do |mod|
200
- mod.p { |p| p << m[:text].sub(/^\s+/, "") }
201
- end
202
- end
203
-
204
- TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
205
- ^(?<xref><(xref|concept)[^>]+>([^<]*</(xref|concept)>)?)
206
- (,\s(?<text>.*))?
207
- $
208
- REGEXP
209
- TERM_REFERENCE_RE =
210
- Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
211
- Regexp::IGNORECASE | Regexp::MULTILINE)
212
-
213
- def extract_termsource_refs(text, node)
214
- matched = TERM_REFERENCE_RE.match text
215
- matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
216
- matched
217
- end
218
-
219
- def termsource(node)
220
- matched = extract_termsource_refs(node.content, node) || return
221
- noko do |xml|
222
- attrs = { status: matched[:text] ? "modified" : "identical" }
223
- xml.termsource **attrs do |xml_t|
224
- seen_xref = Nokogiri::XML.fragment(matched[:xref])
225
- add_term_source(xml_t, seen_xref, matched)
226
- end
227
- end.join("\n")
228
217
  end
229
218
 
230
219
  private
231
220
 
232
221
  def outputdir(node)
233
- if node.attr("output_dir").nil_or_empty? then Utils::localdir(node)
222
+ if node.attr("output_dir").nil_or_empty? then Metanorma::Utils::localdir(node)
234
223
  else File.join(node.attr("output_dir"), "")
235
224
  end
236
225
  end
@@ -729,9 +729,11 @@
729
729
  </define>
730
730
  <define name="index">
731
731
  <element name="index">
732
- <attribute name="to">
733
- <data type="IDREF"/>
734
- </attribute>
732
+ <optional>
733
+ <attribute name="to">
734
+ <data type="IDREF"/>
735
+ </attribute>
736
+ </optional>
735
737
  <element name="primary">
736
738
  <oneOrMore>
737
739
  <ref name="PureTextElement"/>
@@ -6,11 +6,11 @@ module Asciidoctor
6
6
  module Standoc
7
7
  module Blocks
8
8
  def id_attr(node = nil)
9
- { id: Utils::anchor_or_uuid(node) }
9
+ { id: Metanorma::Utils::anchor_or_uuid(node) }
10
10
  end
11
11
 
12
12
  def id_unnum_attrs(node)
13
- attr_code( id: Utils::anchor_or_uuid(node),
13
+ attr_code( id: Metanorma::Utils::anchor_or_uuid(node),
14
14
  unnumbered: node.option?("unnumbered") ? "true" : nil,
15
15
  number: node.attr("number"),
16
16
  subsequence: node.attr("subsequence") )
@@ -29,7 +29,7 @@ module Asciidoctor
29
29
  # We append each contained block to its parent
30
30
  def open(node)
31
31
  role = node.role || node.attr("style")
32
- Utils::reqt_subpart(role) and return requirement_subpart(node)
32
+ reqt_subpart(role) and return requirement_subpart(node)
33
33
  result = []
34
34
  node.blocks.each do |b|
35
35
  result << send(b.context, b)
@@ -45,7 +45,7 @@ module Asciidoctor
45
45
  noko do |xml|
46
46
  xml.figure **literal_attrs(node) do |f|
47
47
  figure_title(node, f)
48
- f.pre node.lines.join("\n"), **attr_code(id: Utils::anchor_or_uuid,
48
+ f.pre node.lines.join("\n"), **attr_code(id: Metanorma::Utils::anchor_or_uuid,
49
49
  alt: node.attr("alt"))
50
50
  end
51
51
  end
@@ -121,7 +121,7 @@ module Asciidoctor
121
121
 
122
122
  def para_attrs(node)
123
123
  attr_code(keep_attrs(node).merge(align: node.attr("align"),
124
- id: Utils::anchor_or_uuid(node)))
124
+ id: Metanorma::Utils::anchor_or_uuid(node)))
125
125
  end
126
126
 
127
127
  def paragraph(node)
@@ -135,7 +135,7 @@ module Asciidoctor
135
135
 
136
136
  def quote_attrs(node)
137
137
  attr_code(keep_attrs(node).merge(align: node.attr("align"),
138
- id: Utils::anchor_or_uuid(node)))
138
+ id: Metanorma::Utils::anchor_or_uuid(node)))
139
139
  end
140
140
 
141
141
  def quote_attribution(node, out)
@@ -160,7 +160,7 @@ module Asciidoctor
160
160
 
161
161
  def listing_attrs(node)
162
162
  attr_code(keep_attrs(node).merge(lang: node.attr("language"),
163
- id: Utils::anchor_or_uuid(node),
163
+ id: Metanorma::Utils::anchor_or_uuid(node),
164
164
  unnumbered: node.option?("unnumbered") ? "true" : nil,
165
165
  number: node.attr("number"),
166
166
  filename: node.attr("filename")))
@@ -35,7 +35,7 @@ module Asciidoctor
35
35
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
36
36
  date += "T00:00:00Z" unless /T/.match date
37
37
  attr_code(
38
- id: Utils::anchor_or_uuid(node),
38
+ id: ::Metanorma::Utils::anchor_or_uuid(node),
39
39
  reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
40
40
  date: date )
41
41
  end
@@ -69,7 +69,7 @@ module Asciidoctor
69
69
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
70
70
  name = t if a.casecmp(t).zero?
71
71
  end
72
- attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node), type: name,
72
+ attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node), type: name,
73
73
  beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
74
74
  end
75
75
 
@@ -5,11 +5,13 @@ require "html2doc"
5
5
  require_relative "./cleanup_block.rb"
6
6
  require_relative "./cleanup_footnotes.rb"
7
7
  require_relative "./cleanup_ref.rb"
8
+ require_relative "./cleanup_ref_dl.rb"
8
9
  require_relative "./cleanup_boilerplate.rb"
9
10
  require_relative "./cleanup_section.rb"
10
11
  require_relative "./cleanup_terms.rb"
11
12
  require_relative "./cleanup_inline.rb"
12
13
  require_relative "./cleanup_amend.rb"
14
+ require_relative "./cleanup_maths.rb"
13
15
  require "relaton_iev"
14
16
 
15
17
  module Asciidoctor
@@ -23,26 +25,15 @@ module Asciidoctor
23
25
  </passthrough>}mx) { |m| HTMLEntities.new.decode($1) }
24
26
  end
25
27
 
26
- def asciimath2mathml(text)
27
- text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
28
- "<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
29
- end
30
- text = Html2Doc.
31
- asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
32
- x = Nokogiri::XML(text)
33
- x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
34
- y.wrap("<stem type='MathML'></stem>")
35
- end
36
- x.to_xml
37
- end
38
-
39
28
  def cleanup(xmldoc)
40
29
  element_name_cleanup(xmldoc)
41
30
  sections_cleanup(xmldoc)
42
31
  obligations_cleanup(xmldoc)
43
32
  table_cleanup(xmldoc)
44
33
  formula_cleanup(xmldoc)
34
+ sourcecode_cleanup(xmldoc)
45
35
  figure_cleanup(xmldoc)
36
+ element_name_cleanup(xmldoc)
46
37
  ref_cleanup(xmldoc)
47
38
  note_cleanup(xmldoc)
48
39
  clausebefore_cleanup(xmldoc)
@@ -78,14 +69,13 @@ module Asciidoctor
78
69
  end
79
70
 
80
71
  def smartquotes_cleanup(xmldoc)
81
- xmldoc.xpath("//date").each { |d| Utils::endash_date(d) }
72
+ xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
82
73
  xmldoc.traverse do |n|
83
74
  next unless n.text?
84
75
  if @smartquotes
85
76
  /[-'"(<>]|\.\.|\dx/.match(n) or next
86
- n.ancestors("pre, tt, sourcecode, bibdata, on, "\
87
- "stem, figure[@class = 'pseudocode']").empty? or next
88
- n.replace(Utils::smartformat(n.text))
77
+ n.ancestors("pre, tt, sourcecode, bibdata, on, stem, figure[@class = 'pseudocode']").empty? or next
78
+ n.replace(Metanorma::Utils::smartformat(n.text))
89
79
  else
90
80
  n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
91
81
  #gsub(/</, "&lt;").gsub(/>/, "&gt;"))
@@ -148,60 +138,26 @@ module Asciidoctor
148
138
  align_callouts_to_annotations(xmldoc)
149
139
  end
150
140
 
151
- def xml_unescape_mathml(x)
152
- return if x.children.any? { |y| y.element? }
153
- math = x.text.gsub(/&lt;/, "<").gsub(/&gt;/, ">").gsub(/&quot;/, '"').
154
- gsub(/&apos;/, "'").gsub(/&amp;/, "&").
155
- gsub(/<[^: \r\n\t\/]+:/, "<").gsub(/<\/[^ \r\n\t:]+:/, "</")
156
- x.children = math
157
- end
158
-
159
- MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
160
-
161
- def mathml_preserve_space(m)
162
- m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
163
- x.children = x.children.to_xml.gsub(/^\s/, "&#xA0;").
164
- gsub(/\s$/, "&#xA0;")
165
- end
166
- end
167
-
168
- def mathml_namespace(stem)
169
- stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
170
- end
171
-
172
- def mathml_mi_italics
173
- { uppergreek: true, upperroman: true,
174
- lowergreek: true, lowerroman: true }
175
- end
176
-
177
- # presuppose multichar mi upright, singlechar mi MathML default italic
178
- def mathml_italicise(x)
179
- x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
180
- char = HTMLEntities.new.decode(i.text)
181
- i["mathvariant"] = "normal" if mi_italicise?(char)
182
- end
183
- end
184
-
185
- def mi_italicise?(c)
186
- return false if c.length > 1
187
- if /\p{Greek}/.match(c)
188
- /\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
189
- /\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
190
- elsif /\p{Latin}/.match(c)
191
- /\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
192
- /\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
193
- else
194
- false
141
+ def sourcecode_cleanup(xmldoc)
142
+ xmldoc.xpath("//sourcecode").each do |x|
143
+ x.traverse do |n|
144
+ next unless n.text?
145
+ next unless /#{Regexp.escape(@sourcecode_markup_start)}/.match(n.text)
146
+ n.replace(sourcecode_markup(n))
147
+ end
195
148
  end
196
149
  end
197
150
 
198
- def mathml_cleanup(xmldoc)
199
- xmldoc.xpath("//stem[@type = 'MathML']").each do |x|
200
- xml_unescape_mathml(x)
201
- mathml_namespace(x)
202
- mathml_preserve_space(x)
203
- mathml_italicise(x)
151
+ def sourcecode_markup(n)
152
+ acc = []
153
+ n.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|#{Regexp.escape(@sourcecode_markup_end)})/).
154
+ each_slice(4).map do |a|
155
+ acc << Nokogiri::XML::Text.new(a[0], n.document).
156
+ to_xml(encoding: "US-ASCII", save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
157
+ next unless a.size == 4
158
+ acc << Asciidoctor.convert(a[2], backend: (self&.backend&.to_sym || :standoc), doctype: :inline)
204
159
  end
160
+ acc.join
205
161
  end
206
162
 
207
163
  # allows us to deal with doc relation localities,
@@ -215,23 +171,18 @@ module Asciidoctor
215
171
 
216
172
  def img_cleanup(xmldoc)
217
173
  return xmldoc unless @datauriimage
218
- xmldoc.xpath("//image").each do |i|
219
- i["src"] = datauri(i["src"])
220
- end
174
+ xmldoc.xpath("//image").each { |i| i["src"] = datauri(i["src"]) }
221
175
  end
222
176
 
223
177
  def variant_cleanup(xmldoc)
224
178
  xmldoc.xpath("//*[variant]").each do |c|
225
- c&.next&.text? && c&.next&.next&.name == "variant" &&
226
- c.next.text.gsub(/\s/, "").empty? and c.next.remove
179
+ c&.next&.text? && c&.next&.next&.name == "variant" && c.next.text.gsub(/\s/, "").empty? and
180
+ c.next.remove
227
181
  end
228
182
  xmldoc.xpath("//*[variant]").each do |c|
229
- next unless c.children.any? do |n|
230
- n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
231
- end
183
+ next unless c.children.any? { |n| n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?) }
232
184
  c.xpath("./variant").each do |n|
233
- if n.at_xpath('preceding-sibling::node()[not(self::text()'\
234
- '[not(normalize-space())])][1][self::variantwrap]')
185
+ if n.at_xpath('preceding-sibling::node()[not(self::text()[not(normalize-space())])][1][self::variantwrap]')
235
186
  n.previous_element << n
236
187
  else
237
188
  n.replace('<variantwrap/>').first << n
@@ -8,14 +8,14 @@ module Asciidoctor
8
8
  module Cleanup
9
9
  def para_cleanup(xmldoc)
10
10
  ["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
11
- "//ul[not(ancestor::bibdata)]",
11
+ "//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
12
12
  "//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"
13
13
  ].each { |w| inject_id(xmldoc, w) }
14
14
  end
15
15
 
16
16
  def inject_id(xmldoc, path)
17
17
  xmldoc.xpath(path).each do |x|
18
- x["id"] ||= Utils::anchor_or_uuid
18
+ x["id"] ||= Metanorma::Utils::anchor_or_uuid
19
19
  end
20
20
  end
21
21
 
@@ -32,8 +32,7 @@ module Asciidoctor
32
32
  def dl2_table_cleanup(xmldoc)
33
33
  q = "//table/following-sibling::*[1][self::p]"
34
34
  xmldoc.xpath(q).each do |s|
35
- if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
36
- s.next_element.name == "dl"
35
+ if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? && s.next_element.name == "dl"
37
36
  s.next_element["key"] = "true"
38
37
  s.previous_element << s.next_element.remove
39
38
  s.remove
@@ -101,8 +100,7 @@ module Asciidoctor
101
100
  def formula_cleanup_where2(x)
102
101
  q = "//formula/following-sibling::*[1][self::p]"
103
102
  x.xpath(q).each do |s|
104
- if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? &&
105
- s.next_element.name == "dl"
103
+ if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? && s.next_element.name == "dl"
106
104
  s.next_element["key"] = "true"
107
105
  s.previous_element << s.next_element.remove
108
106
  s.remove
@@ -133,14 +131,6 @@ module Asciidoctor
133
131
  end
134
132
 
135
133
  # examples containing only figures become subfigures of figures
136
- def subfigure_cleanup(xmldoc)
137
- nodes = xmldoc.xpath("//example/figure")
138
- while !nodes.empty?
139
- nodes[0].parent.name = "figure"
140
- nodes = xmldoc.xpath("//example/figure")
141
- end
142
- end
143
-
144
134
  def subfigure_cleanup(xmldoc)
145
135
  xmldoc.xpath("//example[figure]").each do |e|
146
136
  next unless e.elements.map { |m| m.name }.
@@ -193,7 +183,7 @@ module Asciidoctor
193
183
  def requirement_descriptions(x)
194
184
  x.xpath("//requirement | //recommendation | //permission").each do |r|
195
185
  r.children.each do |e|
196
- unless e.element? && (Utils::reqt_subpart(e.name) ||
186
+ unless e.element? && (reqt_subpart(e.name) ||
197
187
  %w(requirement recommendation permission).include?(e.name))
198
188
  t = Nokogiri::XML::Element.new("description", x)
199
189
  e.before(t)