metanorma-standoc 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cd6e66873fc1d0b703e0fee76f1ed3a56de06684135f142e3be3865bb7c21fa
4
- data.tar.gz: ec666e930ce8ad73f39563050aaf052ddc0ed31a1778dec88cd1bf7308ddef12
3
+ metadata.gz: f802ef3bf91b1b1af85aa22ca72569b6a6d74b29ed4389373e6b42e7d364b016
4
+ data.tar.gz: 55bd7031c2f7a2623955c9d1778b48a5a1666d15a0fe160a8058b544ffe60f92
5
5
  SHA512:
6
- metadata.gz: 65062d39f1c2bd1c33ceaf3bc0d55f5be7c34728c4b9027c7b7192c5ddf8a4b3cc3e37705070b471aac7c20117946a6dae150a5e31613d36afff59bb3ab5aa39
7
- data.tar.gz: e1ca0ba1c31ad442c6359d30ca338fecb840dd86839d01cf697e314b365f72da424a6f93eecb1906eafdc34e2f489f2afd9f264ce1762cd1bc2e7524711ac653
6
+ metadata.gz: 59462520c525758884fdeac23103756b75908daf58707c25ed1420c3e7184e6c3cfaaa7ecd3770619cb3f5d7d9eedc9778b96980b5a33fcdedbea015da9e2684
7
+ data.tar.gz: ad562abbf62b1217ab40c933a1f32fe7dbbc474561c47ff0ed91c7de9e9262e3b0612393d8354eccacf30b034316635f5c84aa80f24cc2d5e6e5650bd918e485
@@ -4,7 +4,7 @@ name: rake
4
4
 
5
5
  on:
6
6
  push:
7
- branches: [ master, main ]
7
+ branches: [ master, main ]
8
8
  tags: [ v* ]
9
9
  pull_request:
10
10
 
@@ -16,19 +16,9 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: [ '2.7', '2.6', '2.5', '2.4' ]
19
+ ruby: [ '3.0', '2.7', '2.6', '2.5' ]
20
20
  os: [ ubuntu-latest, windows-latest, macos-latest ]
21
21
  experimental: [ false ]
22
- include:
23
- - ruby: '3.0'
24
- os: 'ubuntu-latest'
25
- experimental: true
26
- - ruby: '3.0'
27
- os: 'windows-latest'
28
- experimental: true
29
- - ruby: '3.0'
30
- os: 'macos-latest'
31
- experimental: true
32
22
  steps:
33
23
  - uses: actions/checkout@master
34
24
 
@@ -49,5 +39,5 @@ jobs:
49
39
  with:
50
40
  token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
51
41
  repository: ${{ github.repository }}
52
- event-type: notify
42
+ event-type: tests-passed
53
43
  client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
data/.hound.yml CHANGED
@@ -1,3 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  ruby:
2
- Enabled: true
4
+ enabled: true
3
5
  config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -1,14 +1,10 @@
1
- # This project follows the Ribose OSS style guide.
2
- # https://github.com/riboseinc/oss-guides
3
- # All project-specific additions and overrides should be specified in this file.
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
4
3
  inherit_from:
5
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
6
5
 
7
6
  # local repo-specific modifications
7
+ # ...
8
8
 
9
9
  AllCops:
10
- DisplayCopNames: false
11
- StyleGuideCopsOnly: false
12
- TargetRubyVersion: 2.4
13
- Rails:
14
- Enabled: true
10
+ TargetRubyVersion: 2.5
@@ -48,11 +48,13 @@ module Asciidoctor
48
48
  htmlcoverpage: node.attr("htmlcoverpage"),
49
49
  htmlintropage: node.attr("htmlintropage"),
50
50
  scripts: node.attr("scripts"),
51
+ scripts_override: node.attr("scripts-override"),
51
52
  scripts_pdf: node.attr("scripts-pdf"),
52
53
  datauriimage: node.attr("data-uri-image"),
53
54
  htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
54
55
  doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
55
56
  break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
57
+ bare: node.attr("bare"),
56
58
  sectionsplit: node.attr("sectionsplit"),
57
59
  }
58
60
  end
@@ -80,6 +82,7 @@ module Asciidoctor
80
82
  htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
81
83
  doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
82
84
  break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
85
+ bare: node.attr("bare"),
83
86
  }
84
87
 
85
88
  if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
@@ -108,10 +111,15 @@ module Asciidoctor
108
111
  @draft = node.attributes.has_key?("draft")
109
112
  @novalid = node.attr("novalid")
110
113
  @smartquotes = node.attr("smartquotes") != "false"
111
- @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false"
114
+ @keepasciimath = node.attr("mn-keep-asciimath") &&
115
+ node.attr("mn-keep-asciimath") != "false"
112
116
  @fontheader = default_fonts(node)
113
117
  @files_to_delete = []
114
- @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
118
+ if node.attr("docfile")
119
+ @filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
120
+ else
121
+ @filename = ""
122
+ end
115
123
  @localdir = Metanorma::Utils::localdir(node)
116
124
  @output_dir = outputdir node
117
125
  @no_isobib_cache = node.attr("no-isobib-cache")
@@ -143,10 +151,12 @@ module Asciidoctor
143
151
  end
144
152
 
145
153
  def outputs(node, ret)
146
- File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
147
- presentation_xml_converter(node).convert(@filename + ".xml")
148
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
149
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
154
+ File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
155
+ presentation_xml_converter(node).convert("#{@filename}.xml")
156
+ html_converter(node).convert("#{@filename}.presentation.xml",
157
+ nil, false, "#{@filename}.html")
158
+ doc_converter(node).convert("#{@filename}.presentation.xml",
159
+ nil, false, "#{@filename}.doc")
150
160
  end
151
161
 
152
162
  def document(node)
@@ -163,12 +173,21 @@ module Asciidoctor
163
173
  end
164
174
 
165
175
  def clean_exit
166
- @log.write(@output_dir + @filename + ".err") unless @novalid
176
+ @log.write("#{@output_dir}#{@filename}.err") unless @novalid
177
+
167
178
  @files_to_delete.each { |f| FileUtils.rm f }
168
179
  end
169
180
 
181
+ def clean_abort(msg, file = nil)
182
+ file and
183
+ File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(file) }
184
+ clean_exit
185
+ abort(msg)
186
+ end
187
+
170
188
  def makexml1(node)
171
- result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag} type='semantic' version='#{version}'>"]
189
+ result = ["<?xml version='1.0' encoding='UTF-8'?>",
190
+ "<#{xml_root_tag} type='semantic' version='#{version}'>"]
172
191
  result << noko { |ixml| front node, ixml }
173
192
  result << noko { |ixml| middle node, ixml }
174
193
  result << "</#{xml_root_tag}>"
@@ -203,36 +222,13 @@ module Asciidoctor
203
222
  end
204
223
  end
205
224
 
206
- def default_script(lang)
207
- case lang
208
- when "ar", "fa"
209
- "Arab"
210
- when "ur"
211
- "Aran"
212
- when "ru", "bg"
213
- "Cyrl"
214
- when "hi"
215
- "Deva"
216
- when "el"
217
- "Grek"
218
- when "zh"
219
- "Hans"
220
- when "ko"
221
- "Kore"
222
- when "he"
223
- "Hebr"
224
- when "ja"
225
- "Jpan"
226
- else
227
- "Latn"
228
- end
229
- end
230
-
231
225
  private
232
226
 
233
227
  def outputdir(node)
234
- if node.attr("output_dir").nil_or_empty? then Metanorma::Utils::localdir(node)
235
- else File.join(node.attr("output_dir"), "")
228
+ if node.attr("output_dir").nil_or_empty?
229
+ Metanorma::Utils::localdir(node)
230
+ else
231
+ File.join(node.attr("output_dir"), "")
236
232
  end
237
233
  end
238
234
  end
@@ -787,6 +787,7 @@
787
787
  <value>adapted</value>
788
788
  <value>vote-started</value>
789
789
  <value>vote-ended</value>
790
+ <value>announced</value>
790
791
  </choice>
791
792
  </define>
792
793
  <define name="bdate">
@@ -30,6 +30,7 @@ module Asciidoctor
30
30
  def open(node)
31
31
  role = node.role || node.attr("style")
32
32
  reqt_subpart(role) and return requirement_subpart(node)
33
+ role == "form" and return form(node)
33
34
  result = []
34
35
  node.blocks.each do |b|
35
36
  result << send(b.context, b)
@@ -37,6 +38,17 @@ module Asciidoctor
37
38
  result
38
39
  end
39
40
 
41
+ def form(node)
42
+ noko do |xml|
43
+ xml.form **attr_code(
44
+ id: Metanorma::Utils::anchor_or_uuid,
45
+ name: node.attr("name"), action: node.attr("action")
46
+ ) do |f|
47
+ f << node.content
48
+ end
49
+ end
50
+ end
51
+
40
52
  def literal_attrs(node)
41
53
  attr_code(id_attr(node).merge(keep_attrs(node)))
42
54
  end
@@ -71,11 +83,14 @@ module Asciidoctor
71
83
 
72
84
  def example(node)
73
85
  return term_example(node) if in_terms?
86
+
74
87
  role = node.role || node.attr("style")
75
88
  %w(recommendation requirement permission).include?(role) and
76
89
  return requirement(node, role)
77
90
  return pseudocode_example(node) if role == "pseudocode"
78
91
  return svgmap_example(node) if role == "svgmap"
92
+ return form(node) if role == "form"
93
+
79
94
  example_proper(node)
80
95
  end
81
96
 
@@ -91,9 +106,9 @@ module Asciidoctor
91
106
  noko do |xml|
92
107
  xml.svgmap **attr_code(svgmap_attrs(node).merge(
93
108
  src: node.attr("src"), alt: node.attr("alt"))) do |ex|
94
- figure_title(node, ex)
95
- ex << node.content
96
- end
109
+ figure_title(node, ex)
110
+ ex << node.content
111
+ end
97
112
  end.join("\n")
98
113
  end
99
114
 
@@ -140,13 +155,14 @@ module Asciidoctor
140
155
  end
141
156
 
142
157
  def para_attrs(node)
143
- attr_code(keep_attrs(node).
144
- merge(align: node.attr("align"),
145
- id: Metanorma::Utils::anchor_or_uuid(node)))
158
+ attr_code(keep_attrs(node)
159
+ .merge(align: node.attr("align"),
160
+ id: Metanorma::Utils::anchor_or_uuid(node)))
146
161
  end
147
162
 
148
163
  def paragraph(node)
149
164
  return termsource(node) if node.role == "source"
165
+
150
166
  noko do |xml|
151
167
  xml.p **para_attrs(node) do |xml_t|
152
168
  xml_t << node.content
@@ -155,9 +171,9 @@ module Asciidoctor
155
171
  end
156
172
 
157
173
  def quote_attrs(node)
158
- attr_code(keep_attrs(node).
159
- merge(align: node.attr("align"),
160
- id: Metanorma::Utils::anchor_or_uuid(node)))
174
+ attr_code(keep_attrs(node)
175
+ .merge(align: node.attr("align"),
176
+ id: Metanorma::Utils::anchor_or_uuid(node)))
161
177
  end
162
178
 
163
179
  def quote_attribution(node, out)
@@ -2,30 +2,41 @@ module Asciidoctor
2
2
  module Standoc
3
3
  module Blocks
4
4
  def termnote_attrs(node)
5
- attr_code(id_attr(node).merge(
6
- unnumbered: node.attr("unnumbered"),
7
- number: node.attr("number"),
8
- subsequence: node.attr("subsequence"),
9
- "keep-with-next": node.attr("keep-with-next"),
10
- "keep-lines-together": node.attr("keep-with-next"),
11
- "keep-separate": node.attr("keep-separate")))
5
+ attr_code(
6
+ id_attr(node).merge(
7
+ unnumbered: node.attr("unnumbered"),
8
+ number: node.attr("number"),
9
+ subsequence: node.attr("subsequence"),
10
+ "keep-with-next": node.attr("keep-with-next"),
11
+ "keep-lines-together": node.attr("keep-with-next"),
12
+ "keep-separate": node.attr("keep-separate")
13
+ )
14
+ )
12
15
  end
13
16
 
14
17
  def note_attrs(node)
15
- attr_code(termnote_attrs(node).merge(
16
- type: node.attr("type"),
17
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
18
+ attr_code(
19
+ termnote_attrs(node).merge(
20
+ type: node.attr("type"),
21
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
22
+ )
23
+ )
18
24
  end
19
25
 
20
26
  def sidebar_attrs(node)
21
- todo_attrs(node).merge(attr_code(
22
- from: node.attr("from"), to: node.attr("to") || node.attr("from") ))
27
+ todo_attrs(node).merge(
28
+ attr_code(
29
+ from: node.attr("from"),
30
+ to: node.attr("to") || node.attr("from")
31
+ )
32
+ )
23
33
  end
24
34
 
25
35
  def sidebar(node)
26
36
  return unless draft?
37
+
27
38
  noko do |xml|
28
- xml.review **(sidebar_attrs(node)) do |r|
39
+ xml.review **sidebar_attrs(node) do |r|
29
40
  wrap_in_para(node, r)
30
41
  end
31
42
  end
@@ -33,33 +44,34 @@ module Asciidoctor
33
44
 
34
45
  def todo_attrs(node)
35
46
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
36
- date += "T00:00:00Z" unless /T/.match date
47
+ date += "T00:00:00Z" unless /T/.match? date
37
48
  attr_code(
38
49
  id: ::Metanorma::Utils::anchor_or_uuid(node),
39
50
  reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
40
- date: date )
51
+ date: date
52
+ )
41
53
  end
42
54
 
43
55
  def todo(node)
44
56
  noko do |xml|
45
- xml.review **(todo_attrs(node)) do |r|
57
+ xml.review **todo_attrs(node) do |r|
46
58
  wrap_in_para(node, r)
47
59
  end
48
60
  end
49
61
  end
50
62
 
51
- def termnote(n)
63
+ def termnote(node)
52
64
  noko do |xml|
53
- xml.termnote **termnote_attrs(n) do |ex|
54
- wrap_in_para(n, ex)
65
+ xml.termnote **termnote_attrs(node) do |ex|
66
+ wrap_in_para(node, ex)
55
67
  end
56
68
  end.join("\n")
57
69
  end
58
70
 
59
- def note(n)
71
+ def note(node)
60
72
  noko do |xml|
61
- xml.note **note_attrs(n) do |c|
62
- wrap_in_para(n, c)
73
+ xml.note **note_attrs(node) do |c|
74
+ wrap_in_para(node, c)
63
75
  end
64
76
  end.join("\n")
65
77
  end
@@ -69,14 +81,19 @@ module Asciidoctor
69
81
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
70
82
  name = t if a.casecmp(t).zero?
71
83
  end
72
- attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node), type: name,
73
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
84
+ attr_code(
85
+ keep_attrs(node).merge(
86
+ id: Metanorma::Utils::anchor_or_uuid(node), type: name,
87
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
88
+ )
89
+ )
74
90
  end
75
91
 
76
92
  def admonition(node)
77
93
  return termnote(node) if in_terms?
78
94
  return note(node) if node.attr("name") == "note"
79
95
  return todo(node) if node.attr("name") == "todo"
96
+
80
97
  noko do |xml|
81
98
  xml.admonition **admonition_attrs(node) do |a|
82
99
  node.title.nil? or a.name { |name| name << node.title }
@@ -2,27 +2,29 @@ require "nokogiri"
2
2
  require "pathname"
3
3
  require "open-uri"
4
4
  require "html2doc"
5
- require_relative "./cleanup_block.rb"
6
- require_relative "./cleanup_footnotes.rb"
7
- require_relative "./cleanup_ref.rb"
8
- require_relative "./cleanup_ref_dl.rb"
9
- require_relative "./cleanup_boilerplate.rb"
10
- require_relative "./cleanup_section.rb"
11
- require_relative "./cleanup_terms.rb"
12
- require_relative "./cleanup_inline.rb"
13
- require_relative "./cleanup_amend.rb"
14
- require_relative "./cleanup_maths.rb"
5
+ require_relative "./cleanup_block"
6
+ require_relative "./cleanup_footnotes"
7
+ require_relative "./cleanup_ref"
8
+ require_relative "./cleanup_ref_dl"
9
+ require_relative "./cleanup_boilerplate"
10
+ require_relative "./cleanup_section"
11
+ require_relative "./cleanup_terms"
12
+ require_relative "./cleanup_inline"
13
+ require_relative "./cleanup_amend"
14
+ require_relative "./cleanup_maths"
15
+ require_relative "./cleanup_image"
16
+ require_relative "./cleanup_reqt"
15
17
  require "relaton_iev"
16
18
 
17
19
  module Asciidoctor
18
20
  module Standoc
19
21
  module Cleanup
20
22
  def textcleanup(result)
21
- text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
23
+ text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
22
24
  !@keepasciimath and text = asciimath2mathml(text)
23
25
  text = text.gsub(/\s+<fn /, "<fn ")
24
26
  text.gsub(%r{<passthrough\s+formats="metanorma">([^<]*)
25
- </passthrough>}mx) { |m| HTMLEntities.new.decode($1) }
27
+ </passthrough>}mx) { HTMLEntities.new.decode($1) }
26
28
  end
27
29
 
28
30
  def cleanup(xmldoc)
@@ -31,6 +33,7 @@ module Asciidoctor
31
33
  obligations_cleanup(xmldoc)
32
34
  table_cleanup(xmldoc)
33
35
  formula_cleanup(xmldoc)
36
+ form_cleanup(xmldoc)
34
37
  sourcecode_cleanup(xmldoc)
35
38
  figure_cleanup(xmldoc)
36
39
  element_name_cleanup(xmldoc)
@@ -69,26 +72,43 @@ module Asciidoctor
69
72
  xmldoc
70
73
  end
71
74
 
75
+ IGNORE_DUMBQUOTES = "//pre | //pre//* | //tt | //tt//* | "\
76
+ "//sourcecode | //sourcecode//* | //bibdata//* | //stem | "\
77
+ "//stem//* | //figure[@class = 'pseudocode'] | "\
78
+ "//figure[@class = 'pseudocode']//*".freeze
79
+
72
80
  def smartquotes_cleanup(xmldoc)
73
81
  xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
74
- xmldoc.traverse do |n|
75
- next unless n.text?
76
- if @smartquotes
82
+ if @smartquotes then smartquotes_cleanup1(xmldoc)
83
+ else dumbquote_cleanup(xmldoc)
84
+ end
85
+ end
86
+
87
+ def smartquotes_cleanup1(xmldoc)
88
+ (xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
89
+ .each do |x|
90
+ x.children.each do |n|
91
+ next unless n.text?
92
+
77
93
  /[-'"(<>]|\.\.|\dx/.match(n) or next
78
- n.ancestors("pre, tt, sourcecode, bibdata, on, stem, figure[@class = 'pseudocode']").empty? or next
94
+
79
95
  n.replace(Metanorma::Utils::smartformat(n.text))
80
- else
81
- n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
82
- #gsub(/</, "&lt;").gsub(/>/, "&gt;"))
83
96
  end
84
97
  end
85
98
  end
86
99
 
87
- def docidentifier_cleanup(xmldoc)
100
+ def dumbquote_cleanup(xmldoc)
101
+ xmldoc.traverse do |n|
102
+ next unless n.text?
103
+
104
+ n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
105
+ end
88
106
  end
89
107
 
108
+ def docidentifier_cleanup(xmldoc); end
109
+
90
110
  TEXT_ELEMS =
91
- %w{status language script version author name callout phone email
111
+ %w{status language script version author name callout phone email
92
112
  street city state country postcode identifier referenceFrom surname
93
113
  referenceTo docidentifier docnumber prefix initial addition forename
94
114
  title draft secretariat title-main title-intro title-part}.freeze
@@ -110,57 +130,6 @@ module Asciidoctor
110
130
  xmldoc.traverse { |n| n.name = n.name.gsub(/_/, "-") }
111
131
  end
112
132
 
113
- def link_callouts_to_annotations(callouts, annotations)
114
- callouts.each_with_index do |c, i|
115
- c["target"] = "_" + UUIDTools::UUID.random_create
116
- annotations[i]["id"] = c["target"]
117
- end
118
- end
119
-
120
- def align_callouts_to_annotations(xmldoc)
121
- xmldoc.xpath("//sourcecode").each do |x|
122
- callouts = x.elements.select { |e| e.name == "callout" }
123
- annotations = x.elements.select { |e| e.name == "annotation" }
124
- callouts.size == annotations.size and
125
- link_callouts_to_annotations(callouts, annotations)
126
- end
127
- end
128
-
129
- def merge_annotations_into_sourcecode(xmldoc)
130
- xmldoc.xpath("//sourcecode").each do |x|
131
- while x&.next_element&.name == "annotation"
132
- x.next_element.parent = x
133
- end
134
- end
135
- end
136
-
137
- def callout_cleanup(xmldoc)
138
- merge_annotations_into_sourcecode(xmldoc)
139
- align_callouts_to_annotations(xmldoc)
140
- end
141
-
142
- def sourcecode_cleanup(xmldoc)
143
- xmldoc.xpath("//sourcecode").each do |x|
144
- x.traverse do |n|
145
- next unless n.text?
146
- next unless /#{Regexp.escape(@sourcecode_markup_start)}/.match(n.text)
147
- n.replace(sourcecode_markup(n))
148
- end
149
- end
150
- end
151
-
152
- def sourcecode_markup(n)
153
- acc = []
154
- n.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|#{Regexp.escape(@sourcecode_markup_end)})/).
155
- each_slice(4).map do |a|
156
- acc << Nokogiri::XML::Text.new(a[0], n.document).
157
- to_xml(encoding: "US-ASCII", save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
158
- next unless a.size == 4
159
- acc << Asciidoctor.convert(a[2], backend: (self&.backend&.to_sym || :standoc), doctype: :inline)
160
- end
161
- acc.join
162
- end
163
-
164
133
  # allows us to deal with doc relation localities,
165
134
  # temporarily stashed to "bpart"
166
135
  def bpart_cleanup(xmldoc)
@@ -170,28 +139,34 @@ module Asciidoctor
170
139
  end
171
140
  end
172
141
 
173
- def img_cleanup(xmldoc)
174
- return xmldoc unless @datauriimage
175
- xmldoc.xpath("//image").each { |i| i["src"] = Metanorma::Utils::datauri(i["src"], @localdir) }
176
- end
177
-
178
142
  def variant_cleanup(xmldoc)
143
+ variant_space_cleanup(xmldoc)
179
144
  xmldoc.xpath("//*[variant]").each do |c|
180
- c&.next&.text? && c&.next&.next&.name == "variant" && c.next.text.gsub(/\s/, "").empty? and
181
- c.next.remove
182
- end
183
- xmldoc.xpath("//*[variant]").each do |c|
184
- next unless c.children.any? { |n| n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?) }
145
+ next unless c.children.any? do |n|
146
+ n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
147
+ end
148
+
185
149
  c.xpath("./variant").each do |n|
186
- if n.at_xpath('preceding-sibling::node()[not(self::text()[not(normalize-space())])][1][self::variantwrap]')
150
+ if n.at_xpath("preceding-sibling::node()"\
151
+ "[not(self::text()[not(normalize-space())])][1]"\
152
+ "[self::variantwrap]")
187
153
  n.previous_element << n
188
154
  else
189
- n.replace('<variantwrap/>').first << n
155
+ n.replace("<variantwrap/>").first << n
190
156
  end
191
157
  end
192
158
  end
193
159
  xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
194
160
  end
161
+
162
+ def variant_space_cleanup(xmldoc)
163
+ xmldoc.xpath("//*[variant]").each do |c|
164
+ if c&.next&.text? && c&.next&.next&.name == "variant"
165
+ c.next.text.gsub(/\s/, "").empty? and
166
+ c.next.remove
167
+ end
168
+ end
169
+ end
195
170
  end
196
171
  end
197
172
  end