metanorma-standoc 1.10.5 → 1.11.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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +19 -23
  3. data/Rakefile +1 -1
  4. data/lib/asciidoctor/standoc/base.rb +14 -17
  5. data/lib/asciidoctor/standoc/basicdoc.rng +21 -4
  6. data/lib/asciidoctor/standoc/blocks.rb +26 -23
  7. data/lib/asciidoctor/standoc/blocks_notes.rb +17 -22
  8. data/lib/asciidoctor/standoc/cleanup.rb +46 -12
  9. data/lib/asciidoctor/standoc/cleanup_block.rb +5 -70
  10. data/lib/asciidoctor/standoc/cleanup_image.rb +6 -7
  11. data/lib/asciidoctor/standoc/cleanup_inline.rb +44 -102
  12. data/lib/asciidoctor/standoc/cleanup_maths.rb +5 -6
  13. data/lib/asciidoctor/standoc/cleanup_ref.rb +5 -0
  14. data/lib/asciidoctor/standoc/cleanup_reqt.rb +51 -33
  15. data/lib/asciidoctor/standoc/cleanup_section_names.rb +5 -5
  16. data/lib/asciidoctor/standoc/cleanup_symbols.rb +48 -0
  17. data/lib/asciidoctor/standoc/cleanup_table.rb +68 -0
  18. data/lib/asciidoctor/standoc/cleanup_terms.rb +38 -78
  19. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +162 -0
  20. data/lib/asciidoctor/standoc/cleanup_text.rb +5 -2
  21. data/lib/asciidoctor/standoc/cleanup_xref.rb +107 -0
  22. data/lib/asciidoctor/standoc/converter.rb +15 -0
  23. data/lib/asciidoctor/standoc/inline.rb +7 -5
  24. data/lib/asciidoctor/standoc/isodoc.rng +435 -78
  25. data/lib/asciidoctor/standoc/lists.rb +15 -15
  26. data/lib/asciidoctor/standoc/macros.rb +14 -43
  27. data/lib/asciidoctor/standoc/macros_note.rb +45 -0
  28. data/lib/asciidoctor/standoc/macros_plantuml.rb +29 -14
  29. data/lib/asciidoctor/standoc/macros_terms.rb +82 -20
  30. data/lib/asciidoctor/standoc/ref_sect.rb +24 -17
  31. data/lib/asciidoctor/standoc/reqt.rb +2 -2
  32. data/lib/asciidoctor/standoc/reqt.rng +23 -2
  33. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +50 -11
  34. data/lib/asciidoctor/standoc/terms.rb +21 -3
  35. data/lib/asciidoctor/standoc/utils.rb +36 -23
  36. data/lib/asciidoctor/standoc/validate.rb +45 -27
  37. data/lib/asciidoctor/standoc/validate_section.rb +5 -2
  38. data/lib/metanorma/standoc/version.rb +1 -1
  39. data/metanorma-standoc.gemspec +1 -1
  40. data/spec/asciidoctor/base_spec.rb +4 -36
  41. data/spec/asciidoctor/blank_spec.rb +37 -0
  42. data/spec/asciidoctor/blocks_spec.rb +296 -47
  43. data/spec/asciidoctor/cleanup_blocks_spec.rb +1018 -0
  44. data/spec/asciidoctor/cleanup_sections_spec.rb +153 -12
  45. data/spec/asciidoctor/cleanup_spec.rb +179 -1265
  46. data/spec/asciidoctor/cleanup_terms_spec.rb +990 -0
  47. data/spec/asciidoctor/inline_spec.rb +38 -2
  48. data/spec/asciidoctor/lists_spec.rb +6 -6
  49. data/spec/asciidoctor/macros_plantuml_spec.rb +37 -2
  50. data/spec/asciidoctor/macros_spec.rb +226 -138
  51. data/spec/asciidoctor/refs_spec.rb +4 -26
  52. data/spec/asciidoctor/section_spec.rb +18 -18
  53. data/spec/asciidoctor/validate_spec.rb +109 -1
  54. data/spec/assets/xref_error.adoc +1 -0
  55. data/spec/fixtures/datamodel_description_sections_tree.xml +327 -326
  56. data/spec/spec_helper.rb +6 -7
  57. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +51 -51
  58. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +13 -13
  59. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  60. data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
  61. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +34 -34
  62. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  63. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  64. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +16 -16
  65. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +51 -49
  66. metadata +13 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd98ba81df1c144552167e677b04d6152d838de0ea2d539a6bc7bde2a4b7f235
4
- data.tar.gz: 68d9afff164047bf12f97ac23735cc1d61503172ae8656795393314d127223b6
3
+ metadata.gz: 4c272a7b64955264d820737284d46d47a03d7baaf56d0a365396a5a2cb5455ac
4
+ data.tar.gz: b04e30dd2633c21853ff81aaa14ddff65ddca564e4878a1914507ba7f4d43294
5
5
  SHA512:
6
- metadata.gz: 611ba153c4160486b0ea51eb1564e09cd81d02f6ca6d5a075e3f38cf321321f2e019ba538341786bd4fe01eac9ef53e71ddc5cc19fdccb4e69189d9e7a720955
7
- data.tar.gz: 0acb358132209888abe3a276c16abcfdf142570fd271712960e64e02db487df9bb39081a1f4e08da7347777a71240b57b2d8f6dda7d980523981efe5a838495c
6
+ metadata.gz: 00117f839c229ac456a92d59ea8d7d17fbdb2dc680098126fc77c67696ae1c84cd70e3785a3b9e15c055588678a8d4a27fa1d2069431b38fa83c25fe20885d1d
7
+ data.tar.gz: 78bf3e8ef72cc04f40c3a98cfbf29e14176f04ff1cbade1f299c9a3c284e303d481574f7f1b07ba7fa8cd769a32f6d05b745f550c43ea648c0d354ef3ae8d5ad
data/README.adoc CHANGED
@@ -10,26 +10,24 @@ Gem for serialising the https://github.com/metanorma/metanorma-model-standoc[Met
10
10
 
11
11
  == Functionality
12
12
 
13
- This gem processes Metanorma documents following a template for generating standards documents, according
14
- to a range of standards classes. This gem provides underlying generic functionality; behaviour specific
15
- to each standards class is refined in the gem specific to that standards class (e.g. https://github.com/metanorma/metanorma-iso).
16
- The following outputs are generated.
17
-
18
- * Metanorma XML representation of the document, intended as a document model for
19
- Standards. The Metanorma XML representation is processed in turn, to generate one or more of
20
- the following outputs as end deliverables, depending on each standards class gem:
21
- * Microsoft Word output (`.doc`)
22
- * HTML output (`.html`)
23
- * PDF (`.pdf`)
13
+ This gem processes Metanorma AsciiDoc input into the Metanorma document model.
14
+ This gem provides underlying generic functionality; behaviour specific
15
+ to each standards class is refined in the gem specific to that standards class
16
+ (e.g. https://github.com/metanorma/metanorma-iso[Metanorma ISO]).
17
+
18
+ The following outputs are generated:
19
+
20
+ * Metanorma semantic XML
21
+ * Metanorma presentation XML
22
+
23
+ These Metanorma XML representations are processed downstream by the `isodoc` gem
24
+ to generate other end deliverables, depending on each standards class.
24
25
 
25
26
  The following input formats are supported:
26
27
 
27
- * http://asciidoctor.org/[Asciidoctor]
28
+ * Metanorma AsciiDoc
28
29
 
29
- This README provides an overview of the functionality of the gem; see also
30
- https://github.com/metanorma/metanorma-iso/blob/master/docs/guidance.adoc[Guidance for authoring].
31
- https://github.com/metanorma/metanorma-iso/blob/master/docs/quickstart.adoc[Quickstart guide]
32
- gives a summary overview.
30
+ See the https://www.metanorma.org[Metanorma website] for more information.
33
31
 
34
32
  NOTE: http://asciimath.org[AsciiMathML] is used for mathematical formatting.
35
33
  The gem uses the https://github.com/asciidoctor/asciimath[Ruby AsciiMath parser],
@@ -39,21 +37,19 @@ expressions.
39
37
 
40
38
  === Installation
41
39
 
42
- If you are using a Mac, the https://github.com/metanorma/metanorma-macos-setup
43
- repository has instructions on setting up your machine to run Metanorma
44
- scripts such as this one. You need only run the following in a Terminal console:
40
+ See the https://www.metanorma.org[Metanorma website] for instructions.
41
+
42
+ In the terminal:
45
43
 
46
44
  [source,console]
47
45
  ----
48
- $ bash <(curl -s https://raw.githubusercontent.com/metanorma/metanorma-macos-setup/master/metanorma-setup)
49
46
  $ gem install metanorma-standoc
50
47
  $ gem install metanorma-cli
51
48
  ----
52
49
 
53
- The metanorma-cli gem is the command-line interface for the Metanorma tool suite
50
+ `metanorma-cli` is the command-line interface for the Metanorma suite
54
51
  (incorporating the `metanorma` executable seen above).
55
52
 
56
53
  == Documentation
57
54
 
58
- See http://metanorma.com[]
59
-
55
+ See the https://www.metanorma.org[Metanorma website] for details.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require 'isodoc/gem_tasks'
3
+ require "isodoc/gem_tasks"
4
4
 
5
5
  IsoDoc::GemTasks.install
6
6
  RSpec::Core::RakeTask.new(:spec)
@@ -14,6 +14,7 @@ module Asciidoctor
14
14
  module Base
15
15
  XML_ROOT_TAG = "standard-document".freeze
16
16
  XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
17
+ FONTS_MANIFEST = "fonts-manifest".freeze
17
18
 
18
19
  def xml_root_tag
19
20
  self.class::XML_ROOT_TAG
@@ -23,17 +24,6 @@ module Asciidoctor
23
24
  self.class::XML_NAMESPACE
24
25
  end
25
26
 
26
- def content(node)
27
- node.content
28
- end
29
-
30
- def skip(node, name = nil)
31
- name = name || node.node_name
32
- w = "converter missing for #{name} node in Metanorma backend"
33
- @log.add("AsciiDoc Input", node, w)
34
- nil
35
- end
36
-
37
27
  def html_extract_attributes(node)
38
28
  {
39
29
  script: node.attr("script"),
@@ -49,13 +39,15 @@ module Asciidoctor
49
39
  scripts: node.attr("scripts"),
50
40
  scripts_override: node.attr("scripts-override"),
51
41
  scripts_pdf: node.attr("scripts-pdf"),
52
- datauriimage: node.attr("data-uri-image"),
42
+ datauriimage: node.attr("data-uri-image") != "false",
53
43
  htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
54
44
  doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
55
45
  break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
56
46
  suppressasciimathdup: node.attr("suppress-asciimath-dup"),
57
47
  bare: node.attr("bare"),
58
48
  sectionsplit: node.attr("sectionsplit"),
49
+ baseassetpath: node.attr("base-asset-path"),
50
+ aligncrosselements: node.attr("align-cross-elements"),
59
51
  }
60
52
  end
61
53
 
@@ -90,11 +82,13 @@ module Asciidoctor
90
82
  break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
91
83
  suppressasciimathdup: node.attr("suppress-asciimath-dup"),
92
84
  bare: node.attr("bare"),
85
+ baseassetpath: node.attr("base-asset-path"),
86
+ aligncrosselements: node.attr("align-cross-elements"),
93
87
  }
94
88
 
95
- if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
89
+ if fonts_manifest = node.attr(FONTS_MANIFEST)
96
90
  attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
97
- IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => font_manifest_file,
91
+ IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
98
92
  }
99
93
  end
100
94
 
@@ -124,8 +118,7 @@ module Asciidoctor
124
118
  @files_to_delete = []
125
119
  @filename = if node.attr("docfile")
126
120
  File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
127
- else
128
- ""
121
+ else ""
129
122
  end
130
123
  @localdir = Metanorma::Utils::localdir(node)
131
124
  @output_dir = outputdir node
@@ -135,7 +128,7 @@ module Asciidoctor
135
128
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
136
129
  @bibdb = nil
137
130
  @seen_headers = []
138
- @datauriimage = node.attr("data-uri-image")
131
+ @datauriimage = node.attr("data-uri-image") != "false"
139
132
  @boilerplateauthority = node.attr("boilerplate-authority")
140
133
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
141
134
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
@@ -174,6 +167,10 @@ module Asciidoctor
174
167
  outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
175
168
  clean_exit
176
169
  ret
170
+ rescue StandardError => e
171
+ @log.add("Fatal Error", nil, e.message)
172
+ clean_exit
173
+ raise e
177
174
  end
178
175
 
179
176
  def version
@@ -624,6 +624,9 @@
624
624
  <choice>
625
625
  <ref name="PureTextElement"/>
626
626
  <ref name="stem"/>
627
+ <ref name="eref"/>
628
+ <ref name="xref"/>
629
+ <ref name="hyperlink"/>
627
630
  </choice>
628
631
  </zeroOrMore>
629
632
  </element>
@@ -634,6 +637,9 @@
634
637
  <choice>
635
638
  <ref name="PureTextElement"/>
636
639
  <ref name="stem"/>
640
+ <ref name="eref"/>
641
+ <ref name="xref"/>
642
+ <ref name="hyperlink"/>
637
643
  </choice>
638
644
  </zeroOrMore>
639
645
  </element>
@@ -641,7 +647,12 @@
641
647
  <define name="tt">
642
648
  <element name="tt">
643
649
  <zeroOrMore>
644
- <ref name="PureTextElement"/>
650
+ <choice>
651
+ <ref name="PureTextElement"/>
652
+ <ref name="eref"/>
653
+ <ref name="xref"/>
654
+ <ref name="hyperlink"/>
655
+ </choice>
645
656
  </zeroOrMore>
646
657
  </element>
647
658
  </define>
@@ -822,7 +833,9 @@
822
833
  <attribute name="alt"/>
823
834
  </optional>
824
835
  <ref name="CitationType"/>
825
- <text/>
836
+ <oneOrMore>
837
+ <ref name="PureTextElement"/>
838
+ </oneOrMore>
826
839
  </define>
827
840
  <define name="hyperlink">
828
841
  <element name="link">
@@ -835,7 +848,9 @@
835
848
  <optional>
836
849
  <attribute name="alt"/>
837
850
  </optional>
838
- <text/>
851
+ <oneOrMore>
852
+ <ref name="PureTextElement"/>
853
+ </oneOrMore>
839
854
  </element>
840
855
  </define>
841
856
  <define name="xref">
@@ -849,7 +864,9 @@
849
864
  <optional>
850
865
  <attribute name="alt"/>
851
866
  </optional>
852
- <text/>
867
+ <oneOrMore>
868
+ <ref name="PureTextElement"/>
869
+ </oneOrMore>
853
870
  </element>
854
871
  </define>
855
872
  <define name="fn">
@@ -6,14 +6,17 @@ module Asciidoctor
6
6
  module Standoc
7
7
  module Blocks
8
8
  def id_attr(node = nil)
9
- { id: Metanorma::Utils::anchor_or_uuid(node) }
9
+ { id: Metanorma::Utils::anchor_or_uuid(node),
10
+ tag: node&.attr("tag"),
11
+ "multilingual-rendering": node&.attr("multilingual-rendering") }
10
12
  end
11
13
 
12
14
  def id_unnum_attrs(node)
13
- attr_code(id: Metanorma::Utils::anchor_or_uuid(node),
14
- unnumbered: node.option?("unnumbered") ? "true" : nil,
15
- number: node.attr("number"),
16
- subsequence: node.attr("subsequence"))
15
+ attr_code(id_attr(node).merge(
16
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
17
+ number: node.attr("number"),
18
+ subsequence: node.attr("subsequence"),
19
+ ))
17
20
  end
18
21
 
19
22
  def formula_attrs(node)
@@ -33,6 +36,7 @@ module Asciidoctor
33
36
  role = node.role || node.attr("style")
34
37
  reqt_subpart(role) and return requirement_subpart(node)
35
38
  role == "form" and return form(node)
39
+ role == "definition" and return termdefinition(node)
36
40
  result = []
37
41
  node.blocks.each do |b|
38
42
  result << send(b.context, b)
@@ -42,10 +46,9 @@ module Asciidoctor
42
46
 
43
47
  def form(node)
44
48
  noko do |xml|
45
- xml.form **attr_code(
46
- id: Metanorma::Utils::anchor_or_uuid, class: node.attr("class"),
47
- name: node.attr("name"), action: node.attr("action")
48
- ) do |f|
49
+ xml.form **attr_code(id_attr(node)
50
+ .merge(class: node.attr("class"),
51
+ name: node.attr("name"), action: node.attr("action"))) do |f|
49
52
  f << node.content
50
53
  end
51
54
  end
@@ -77,7 +80,7 @@ module Asciidoctor
77
80
 
78
81
  def term_example(node)
79
82
  noko do |xml|
80
- xml.termexample **id_attr(node) do |ex|
83
+ xml.termexample **attr_code(id_attr(node)) do |ex|
81
84
  wrap_in_para(node, ex)
82
85
  end
83
86
  end.join("\n")
@@ -92,15 +95,18 @@ module Asciidoctor
92
95
  return pseudocode_example(node) if role == "pseudocode"
93
96
  return svgmap_example(node) if role == "svgmap"
94
97
  return form(node) if role == "form"
98
+ return termdefinition(node) if role == "definition"
95
99
 
100
+ reqt_subpart(role) and return requirement_subpart(node)
96
101
  example_proper(node)
97
102
  end
98
103
 
99
104
  def svgmap_attrs(node)
100
- attr_code({ id: node.id,
101
- unnumbered: node.option?("unnumbered") ? "true" : nil,
102
- number: node.attr("number"),
103
- subsequence: node.attr("subsequence") }
105
+ attr_code(id_attr(node)
106
+ .merge(id: node.id,
107
+ unnumbered: node.option?("unnumbered") ? "true" : nil,
108
+ number: node.attr("number"),
109
+ subsequence: node.attr("subsequence"))
104
110
  .merge(keep_attrs(node)))
105
111
  end
106
112
 
@@ -159,11 +165,10 @@ module Asciidoctor
159
165
  end
160
166
 
161
167
  def para_attrs(node)
162
- attr_code(keep_attrs(node)
168
+ attr_code(id_attr(node).merge(keep_attrs(node)
163
169
  .merge(align: node.attr("align"),
164
170
  variant_title: node.role == "variant-title" ? true : nil,
165
- type: node.attr("type"),
166
- id: Metanorma::Utils::anchor_or_uuid(node)))
171
+ type: node.attr("type"))))
167
172
  end
168
173
 
169
174
  def paragraph(node)
@@ -177,9 +182,8 @@ module Asciidoctor
177
182
  end
178
183
 
179
184
  def quote_attrs(node)
180
- attr_code(keep_attrs(node)
181
- .merge(align: node.attr("align"),
182
- id: Metanorma::Utils::anchor_or_uuid(node)))
185
+ attr_code(id_attr(node).merge(keep_attrs(node))
186
+ .merge(align: node.attr("align")))
183
187
  end
184
188
 
185
189
  def quote_attribution(node, out)
@@ -203,12 +207,11 @@ module Asciidoctor
203
207
  end
204
208
 
205
209
  def listing_attrs(node)
206
- attr_code(keep_attrs(node)
210
+ attr_code(id_attr(node).merge(keep_attrs(node)
207
211
  .merge(lang: node.attr("language"),
208
- id: Metanorma::Utils::anchor_or_uuid(node),
209
212
  unnumbered: node.option?("unnumbered") ? "true" : nil,
210
213
  number: node.attr("number"),
211
- filename: node.attr("filename")))
214
+ filename: node.attr("filename"))))
212
215
  end
213
216
 
214
217
  # NOTE: html escaping is performed by Nokogiri
@@ -2,24 +2,21 @@ module Asciidoctor
2
2
  module Standoc
3
3
  module Blocks
4
4
  def termnote_attrs(node)
5
- attr_code(
6
- id_attr(node).merge(
5
+ attr_code(id_attr(node).merge(keep_attrs(node)
6
+ .merge(
7
7
  unnumbered: node.attr("unnumbered"),
8
8
  number: node.attr("number"),
9
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
- )
10
+ "keep-separate": node.attr("keep-separate"),
11
+ )))
15
12
  end
16
13
 
17
14
  def note_attrs(node)
18
15
  attr_code(
19
16
  termnote_attrs(node).merge(
20
17
  type: node.attr("type"),
21
- beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
22
- )
18
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
19
+ ),
23
20
  )
24
21
  end
25
22
 
@@ -27,8 +24,8 @@ module Asciidoctor
27
24
  todo_attrs(node).merge(
28
25
  attr_code(
29
26
  from: node.attr("from"),
30
- to: node.attr("to") || node.attr("from")
31
- )
27
+ to: node.attr("to") || node.attr("from"),
28
+ ),
32
29
  )
33
30
  end
34
31
 
@@ -45,11 +42,10 @@ module Asciidoctor
45
42
  def todo_attrs(node)
46
43
  date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
47
44
  date += "T00:00:00Z" unless /T/.match? date
48
- attr_code(
49
- id: ::Metanorma::Utils::anchor_or_uuid(node),
50
- reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
51
- date: date
52
- )
45
+ attr_code(id_attr(node)
46
+ .merge(reviewer: node.attr("reviewer") || node.attr("source") ||
47
+ "(Unknown)",
48
+ date: date))
53
49
  end
54
50
 
55
51
  def todo(node)
@@ -81,12 +77,11 @@ module Asciidoctor
81
77
  a = node.attr("type") and ["danger", "safety precautions"].each do |t|
82
78
  name = t if a.casecmp(t).zero?
83
79
  end
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
- )
80
+ attr_code(keep_attrs(node).merge(id_attr(node)
81
+ .merge(
82
+ type: name,
83
+ beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
84
+ )))
90
85
  end
91
86
 
92
87
  def admonition(node)
@@ -2,12 +2,15 @@ require "nokogiri"
2
2
  require "pathname"
3
3
  require "html2doc"
4
4
  require_relative "./cleanup_block"
5
+ require_relative "./cleanup_table"
5
6
  require_relative "./cleanup_footnotes"
6
7
  require_relative "./cleanup_ref"
7
8
  require_relative "./cleanup_ref_dl"
8
9
  require_relative "./cleanup_boilerplate"
9
10
  require_relative "./cleanup_section"
10
11
  require_relative "./cleanup_terms"
12
+ require_relative "./cleanup_symbols"
13
+ require_relative "./cleanup_xref"
11
14
  require_relative "./cleanup_inline"
12
15
  require_relative "./cleanup_amend"
13
16
  require_relative "./cleanup_maths"
@@ -39,6 +42,7 @@ module Asciidoctor
39
42
  symbols_cleanup(xmldoc)
40
43
  xref_cleanup(xmldoc)
41
44
  concept_cleanup(xmldoc)
45
+ related_cleanup(xmldoc)
42
46
  origin_cleanup(xmldoc)
43
47
  bookmark_cleanup(xmldoc)
44
48
  termdef_cleanup(xmldoc)
@@ -71,7 +75,8 @@ module Asciidoctor
71
75
  %w{status language script version author name callout phone email
72
76
  street city state country postcode identifier referenceFrom surname
73
77
  referenceTo docidentifier docnumber prefix initial addition forename
74
- title draft secretariat title-main title-intro title-part}.freeze
78
+ title draft secretariat title-main title-intro title-part
79
+ verbaldefinition nonverbalrepresentation}.freeze
75
80
 
76
81
  # it seems Nokogiri::XML is treating the content of <script> as cdata,
77
82
  # because of its use in HTML. Bad nokogiri. Undoing that, since we use
@@ -81,7 +86,9 @@ module Asciidoctor
81
86
  end
82
87
 
83
88
  def empty_element_cleanup(xmldoc)
84
- xmldoc.xpath("//" + TEXT_ELEMS.join(" | //")).each do |x|
89
+ xmldoc.xpath("//#{TEXT_ELEMS.join(' | //')}").each do |x|
90
+ next if x.name == "name" && x.parent.name == "expression"
91
+
85
92
  x.remove if x.children.empty?
86
93
  end
87
94
  end
@@ -106,19 +113,23 @@ module Asciidoctor
106
113
  n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
107
114
  end
108
115
 
109
- c.xpath("./variant").each do |n|
110
- if n.at_xpath("preceding-sibling::node()"\
111
- "[not(self::text()[not(normalize-space())])][1]"\
112
- "[self::variantwrap]")
113
- n.previous_element << n
114
- else
115
- n.replace("<variantwrap/>").first << n
116
- end
117
- end
116
+ variant_cleanup1(c)
118
117
  end
119
118
  xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
120
119
  end
121
120
 
121
+ def variant_cleanup1(elem)
122
+ elem.xpath("./variant").each do |n|
123
+ if n.at_xpath("preceding-sibling::node()"\
124
+ "[not(self::text()[not(normalize-space())])][1]"\
125
+ "[self::variantwrap]")
126
+ n.previous_element << n
127
+ else
128
+ n.replace("<variantwrap/>").first << n
129
+ end
130
+ end
131
+ end
132
+
122
133
  def variant_space_cleanup(xmldoc)
123
134
  xmldoc.xpath("//*[variant]").each do |c|
124
135
  if c&.next&.text? && c&.next&.next&.name == "variant"
@@ -129,13 +140,18 @@ module Asciidoctor
129
140
  end
130
141
 
131
142
  def toc_cleanup(xmldoc)
143
+ toc_cleanup_para(xmldoc)
144
+ xmldoc.xpath("//toc").each { |t| toc_cleanup1(t, xmldoc) }
145
+ toc_cleanup_clause(xmldoc)
146
+ end
147
+
148
+ def toc_cleanup_para(xmldoc)
132
149
  xmldoc.xpath("//p[toc]").each do |x|
133
150
  x.xpath("./toc").reverse.each do |t|
134
151
  x.next = t
135
152
  end
136
153
  x.remove if x.text.strip.empty?
137
154
  end
138
- xmldoc.xpath("//toc").each { |t| toc_cleanup1(t, xmldoc) }
139
155
  end
140
156
 
141
157
  def toc_index(toc, xmldoc)
@@ -169,6 +185,24 @@ module Asciidoctor
169
185
  end
170
186
  toc.children = "<ul>#{ret}</ul>"
171
187
  end
188
+
189
+ def toc_cleanup_clause(xmldoc)
190
+ xmldoc
191
+ .xpath("//clause[@type = 'toc'] | //annex[@type = 'toc']").each do |c|
192
+ c.xpath(".//ul[not(ancestor::ul)]").each do |ul|
193
+ toc_cleanup_clause_entry(xmldoc, ul)
194
+ ul.replace("<toc>#{ul.to_xml}</toc>")
195
+ end
196
+ end
197
+ end
198
+
199
+ def toc_cleanup_clause_entry(xmldoc, list)
200
+ list.xpath(".//xref[not(text())]").each do |x|
201
+ c1 = xmldoc.at("//*[@id = '#{x['target']}']")
202
+ t = c1.at("./variant-title[@type = 'toc']") || c1.at("./title")
203
+ x << t.dup.children
204
+ end
205
+ end
172
206
  end
173
207
  end
174
208
  end
@@ -7,10 +7,9 @@ module Asciidoctor
7
7
  def para_cleanup(xmldoc)
8
8
  ["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
9
9
  "//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
10
- "//note[not(ancestor::bibitem or ancestor::table or ancestor::bibdata)]"].each do |w|
11
- inject_id(
12
- xmldoc, w
13
- )
10
+ "//note[not(ancestor::bibitem or "\
11
+ "ancestor::table or ancestor::bibdata)]"].each do |w|
12
+ inject_id(xmldoc, w)
14
13
  end
15
14
  end
16
15
 
@@ -20,68 +19,6 @@ module Asciidoctor
20
19
  end
21
20
  end
22
21
 
23
- def dl1_table_cleanup(xmldoc)
24
- q = "//table/following-sibling::*[1][self::dl]"
25
- xmldoc.xpath(q).each do |s|
26
- s["key"] == "true" and s.previous_element << s.remove
27
- end
28
- end
29
-
30
- # move Key dl after table footer
31
- def dl2_table_cleanup(xmldoc)
32
- q = "//table/following-sibling::*[1][self::p]"
33
- xmldoc.xpath(q).each do |s|
34
- if s.text =~ /^\s*key[^a-z]*$/i && s&.next_element&.name == "dl"
35
- s.next_element["key"] = "true"
36
- s.previous_element << s.next_element.remove
37
- s.remove
38
- end
39
- end
40
- end
41
-
42
- def insert_thead(table)
43
- thead = table.at("./thead")
44
- return thead unless thead.nil?
45
-
46
- if tname = table.at("./name")
47
- thead = tname.add_next_sibling("<thead/>").first
48
- return thead
49
- end
50
- table.children.first.add_previous_sibling("<thead/>").first
51
- end
52
-
53
- def header_rows_cleanup(xmldoc)
54
- xmldoc.xpath("//table[@headerrows]").each do |s|
55
- thead = insert_thead(s)
56
- (thead.xpath("./tr").size...s["headerrows"].to_i).each do
57
- row = s.at("./tbody/tr")
58
- row.parent = thead
59
- end
60
- thead.xpath(".//td").each { |n| n.name = "th" }
61
- s.delete("headerrows")
62
- end
63
- end
64
-
65
- def table_cleanup(xmldoc)
66
- dl1_table_cleanup(xmldoc)
67
- dl2_table_cleanup(xmldoc)
68
- notes_table_cleanup(xmldoc)
69
- header_rows_cleanup(xmldoc)
70
- end
71
-
72
- # move notes into table
73
- def notes_table_cleanup(xmldoc)
74
- nomatches = false
75
- until nomatches
76
- q = "//table/following-sibling::*[1][self::note]"
77
- nomatches = true
78
- xmldoc.xpath(q).each do |n|
79
- n.previous_element << n.remove
80
- nomatches = false
81
- end
82
- end
83
- end
84
-
85
22
  # include where definition list inside stem block
86
23
  def formula_cleanup(formula)
87
24
  formula_cleanup_where1(formula)
@@ -213,18 +150,16 @@ module Asciidoctor
213
150
  end
214
151
 
215
152
  def sourcecode_markup(node)
216
- acc = []
217
153
  node.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|
218
154
  #{Regexp.escape(@sourcecode_markup_end)})/x)
219
- .each_slice(4).map do |a|
155
+ .each_slice(4).map.with_object([]) do |a, acc|
220
156
  acc << safe_noko(a[0], node.document)
221
157
  next unless a.size == 4
222
158
 
223
159
  acc << Asciidoctor.convert(
224
160
  a[2], doctype: :inline, backend: (self&.backend&.to_sym || :standoc)
225
161
  )
226
- end
227
- acc.join
162
+ end.join
228
163
  end
229
164
 
230
165
  def form_cleanup(xmldoc)