metanorma-standoc 1.10.6 → 1.11.0.1

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 (63) 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 +10 -17
  5. data/lib/asciidoctor/standoc/basicdoc.rng +21 -4
  6. data/lib/asciidoctor/standoc/blocks.rb +23 -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 +3 -71
  10. data/lib/asciidoctor/standoc/cleanup_image.rb +6 -7
  11. data/lib/asciidoctor/standoc/cleanup_inline.rb +42 -106
  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 +5 -24
  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 +37 -77
  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 +14 -0
  23. data/lib/asciidoctor/standoc/inline.rb +7 -5
  24. data/lib/asciidoctor/standoc/isodoc.rng +419 -77
  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 +55 -8
  30. data/lib/asciidoctor/standoc/ref_sect.rb +26 -18
  31. data/lib/asciidoctor/standoc/reqt.rng +23 -2
  32. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +50 -11
  33. data/lib/asciidoctor/standoc/terms.rb +12 -2
  34. data/lib/asciidoctor/standoc/utils.rb +36 -23
  35. data/lib/asciidoctor/standoc/validate.rb +45 -27
  36. data/lib/asciidoctor/standoc/validate_section.rb +5 -2
  37. data/lib/metanorma/standoc/version.rb +1 -1
  38. data/metanorma-standoc.gemspec +1 -1
  39. data/spec/asciidoctor/base_spec.rb +4 -36
  40. data/spec/asciidoctor/blank_spec.rb +37 -0
  41. data/spec/asciidoctor/blocks_spec.rb +208 -49
  42. data/spec/asciidoctor/cleanup_sections_spec.rb +153 -12
  43. data/spec/asciidoctor/cleanup_spec.rb +104 -285
  44. data/spec/asciidoctor/cleanup_terms_spec.rb +990 -0
  45. data/spec/asciidoctor/inline_spec.rb +38 -2
  46. data/spec/asciidoctor/lists_spec.rb +6 -6
  47. data/spec/asciidoctor/macros_plantuml_spec.rb +37 -2
  48. data/spec/asciidoctor/macros_spec.rb +191 -114
  49. data/spec/asciidoctor/refs_spec.rb +12 -30
  50. data/spec/asciidoctor/section_spec.rb +18 -18
  51. data/spec/asciidoctor/validate_spec.rb +87 -2
  52. data/spec/fixtures/datamodel_description_sections_tree.xml +3 -2
  53. data/spec/spec_helper.rb +6 -7
  54. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +51 -51
  55. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +13 -13
  56. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  57. data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
  58. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +34 -34
  59. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  60. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  61. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +16 -16
  62. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +51 -49
  63. metadata +12 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5982aeb8f67b56ccf4da3cf8589b3855fda38e646650074f8804d8e94de9a791
4
- data.tar.gz: 6efa1a3eb9fce06dfcce893c835152a2ee642418cd35f06981d4a3d7e4408832
3
+ metadata.gz: 7cb09afdb6668a003d8ef2b58d6260631b7b8e068d3ca16baeee26535c8186d0
4
+ data.tar.gz: 76b254bc985ef940d8224c85202f001cd8660a681386b8b1e774bde626314ff5
5
5
  SHA512:
6
- metadata.gz: 4d4cd2f1c480899fe9221482e53bff2702d96cc1688937b15b993eddcddbca80cb7c5d931913ceaa5e06f9c0b6a70723fc3a84c275a259c5a9bb21fb8b3d42fe
7
- data.tar.gz: 61cf1ff021b2f6365ad83311478732ed431dc2f3328e11ec1a96ebfa264c463ded7198779a86928bb3a82ce4153f4934b96aeccccff5d136d3018cd9b6025173
6
+ metadata.gz: 893626c5998b7853394c39a0e4249f1a11346d0beb5cc00a9f76edc8ce129cf591ba6819ed6974b34a115f89b82c64b8acccf3c2dfcd71dcb20226c90653e62a
7
+ data.tar.gz: c10c585b0274e9be19b848c9dcc175a1ef9325ee0dc875bc1b1aafb057c3fcea1c235488c986093980bc5ce6710d293c053a68d3954aae40365def0071d244e6
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") || "}}}"
@@ -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)
@@ -43,10 +46,9 @@ module Asciidoctor
43
46
 
44
47
  def form(node)
45
48
  noko do |xml|
46
- xml.form **attr_code(
47
- id: Metanorma::Utils::anchor_or_uuid, class: node.attr("class"),
48
- name: node.attr("name"), action: node.attr("action")
49
- ) 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|
50
52
  f << node.content
51
53
  end
52
54
  end
@@ -78,7 +80,7 @@ module Asciidoctor
78
80
 
79
81
  def term_example(node)
80
82
  noko do |xml|
81
- xml.termexample **id_attr(node) do |ex|
83
+ xml.termexample **attr_code(id_attr(node)) do |ex|
82
84
  wrap_in_para(node, ex)
83
85
  end
84
86
  end.join("\n")
@@ -100,10 +102,11 @@ module Asciidoctor
100
102
  end
101
103
 
102
104
  def svgmap_attrs(node)
103
- attr_code({ id: node.id,
104
- unnumbered: node.option?("unnumbered") ? "true" : nil,
105
- number: node.attr("number"),
106
- 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"))
107
110
  .merge(keep_attrs(node)))
108
111
  end
109
112
 
@@ -162,11 +165,10 @@ module Asciidoctor
162
165
  end
163
166
 
164
167
  def para_attrs(node)
165
- attr_code(keep_attrs(node)
168
+ attr_code(id_attr(node).merge(keep_attrs(node)
166
169
  .merge(align: node.attr("align"),
167
170
  variant_title: node.role == "variant-title" ? true : nil,
168
- type: node.attr("type"),
169
- id: Metanorma::Utils::anchor_or_uuid(node)))
171
+ type: node.attr("type"))))
170
172
  end
171
173
 
172
174
  def paragraph(node)
@@ -180,9 +182,8 @@ module Asciidoctor
180
182
  end
181
183
 
182
184
  def quote_attrs(node)
183
- attr_code(keep_attrs(node)
184
- .merge(align: node.attr("align"),
185
- id: Metanorma::Utils::anchor_or_uuid(node)))
185
+ attr_code(id_attr(node).merge(keep_attrs(node))
186
+ .merge(align: node.attr("align")))
186
187
  end
187
188
 
188
189
  def quote_attribution(node, out)
@@ -206,12 +207,11 @@ module Asciidoctor
206
207
  end
207
208
 
208
209
  def listing_attrs(node)
209
- attr_code(keep_attrs(node)
210
+ attr_code(id_attr(node).merge(keep_attrs(node)
210
211
  .merge(lang: node.attr("language"),
211
- id: Metanorma::Utils::anchor_or_uuid(node),
212
212
  unnumbered: node.option?("unnumbered") ? "true" : nil,
213
213
  number: node.attr("number"),
214
- filename: node.attr("filename")))
214
+ filename: node.attr("filename"))))
215
215
  end
216
216
 
217
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
@@ -9,9 +9,7 @@ module Asciidoctor
9
9
  "//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
10
10
  "//note[not(ancestor::bibitem or "\
11
11
  "ancestor::table or ancestor::bibdata)]"].each do |w|
12
- inject_id(
13
- xmldoc, w
14
- )
12
+ inject_id(xmldoc, w)
15
13
  end
16
14
  end
17
15
 
@@ -21,70 +19,6 @@ module Asciidoctor
21
19
  end
22
20
  end
23
21
 
24
- def dl1_table_cleanup(xmldoc)
25
- q = "//table/following-sibling::*[1][self::dl]"
26
- xmldoc.xpath(q).each do |s|
27
- s["key"] == "true" and s.previous_element << s.remove
28
- end
29
- end
30
-
31
- # move Key dl after table footer
32
- def dl2_table_cleanup(xmldoc)
33
- q = "//table/following-sibling::*[1][self::p]"
34
- xmldoc.xpath(q).each do |s|
35
- if s.text =~ /^\s*key[^a-z]*$/i && s&.next_element&.name == "dl"
36
- s.next_element["key"] = "true"
37
- s.previous_element << s.next_element.remove
38
- s.remove
39
- end
40
- end
41
- end
42
-
43
- def insert_thead(table)
44
- thead = table.at("./thead")
45
- return thead unless thead.nil?
46
-
47
- if tname = table.at("./name")
48
- thead = tname.add_next_sibling("<thead/>").first
49
- return thead
50
- end
51
- table.children.first.add_previous_sibling("<thead/>").first
52
- end
53
-
54
- def header_rows_cleanup(xmldoc)
55
- xmldoc.xpath("//table[@headerrows]").each do |s|
56
- thead = insert_thead(s)
57
- (thead.xpath("./tr").size...s["headerrows"].to_i).each do
58
- row = s.at("./tbody/tr")
59
- row.parent = thead
60
- end
61
- thead.xpath(".//td").each { |n| n.name = "th" }
62
- s.delete("headerrows")
63
- end
64
- end
65
-
66
- def table_cleanup(xmldoc)
67
- dl1_table_cleanup(xmldoc)
68
- dl2_table_cleanup(xmldoc)
69
- notes_table_cleanup(xmldoc)
70
- header_rows_cleanup(xmldoc)
71
- end
72
-
73
- # move notes into table
74
- def notes_table_cleanup(xmldoc)
75
- nomatches = false
76
- until nomatches
77
- q = "//table/following-sibling::*[1]"\
78
- "[self::note[not(@keep-separate = 'true')]]"
79
- nomatches = true
80
- xmldoc.xpath(q).each do |n|
81
- n.delete("keep-separate")
82
- n.previous_element << n.remove
83
- nomatches = false
84
- end
85
- end
86
- end
87
-
88
22
  # include where definition list inside stem block
89
23
  def formula_cleanup(formula)
90
24
  formula_cleanup_where1(formula)
@@ -216,18 +150,16 @@ module Asciidoctor
216
150
  end
217
151
 
218
152
  def sourcecode_markup(node)
219
- acc = []
220
153
  node.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|
221
154
  #{Regexp.escape(@sourcecode_markup_end)})/x)
222
- .each_slice(4).map do |a|
155
+ .each_slice(4).map.with_object([]) do |a, acc|
223
156
  acc << safe_noko(a[0], node.document)
224
157
  next unless a.size == 4
225
158
 
226
159
  acc << Asciidoctor.convert(
227
160
  a[2], doctype: :inline, backend: (self&.backend&.to_sym || :standoc)
228
161
  )
229
- end
230
- acc.join
162
+ end.join
231
163
  end
232
164
 
233
165
  def form_cleanup(xmldoc)
@@ -15,9 +15,8 @@ module Asciidoctor
15
15
  def svgmap_moveattrs(xmldoc)
16
16
  xmldoc.xpath("//svgmap").each do |s|
17
17
  f = s.at(".//figure") or next
18
- if (t = s.at("./name")) && !f.at("./name")
18
+ (t = s.at("./name")) && !f.at("./name") and
19
19
  f.children.first.previous = t.remove
20
- end
21
20
  if s["id"] && guid?(f["id"])
22
21
  f["id"] = s["id"]
23
22
  s.delete("id")
@@ -26,13 +25,13 @@ module Asciidoctor
26
25
  end
27
26
  end
28
27
 
29
- def svgmap_moveattrs1(s, f)
28
+ def svgmap_moveattrs1(svgmap, figure)
30
29
  %w(unnumbered number subsequence keep-with-next
31
- keep-lines-together).each do |a|
32
- next if f[a] || !s[a]
30
+ keep-lines-together tag multilingual-rendering).each do |a|
31
+ next if figure[a] || !svgmap[a]
33
32
 
34
- f[a] = s[a]
35
- s.delete(a)
33
+ figure[a] = svgmap[a]
34
+ svgmap.delete(a)
36
35
  end
37
36
  end
38
37