metanorma-standoc 1.10.7 → 1.11.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 (58) 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 +7 -4
  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 +20 -11
  9. data/lib/asciidoctor/standoc/cleanup_image.rb +6 -7
  10. data/lib/asciidoctor/standoc/cleanup_inline.rb +45 -7
  11. data/lib/asciidoctor/standoc/cleanup_maths.rb +5 -6
  12. data/lib/asciidoctor/standoc/cleanup_ref.rb +5 -0
  13. data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -21
  14. data/lib/asciidoctor/standoc/cleanup_symbols.rb +48 -0
  15. data/lib/asciidoctor/standoc/cleanup_terms.rb +48 -77
  16. data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +162 -0
  17. data/lib/asciidoctor/standoc/cleanup_text.rb +23 -0
  18. data/lib/asciidoctor/standoc/converter.rb +2 -0
  19. data/lib/asciidoctor/standoc/inline.rb +7 -5
  20. data/lib/asciidoctor/standoc/isodoc.rng +420 -76
  21. data/lib/asciidoctor/standoc/lists.rb +14 -16
  22. data/lib/asciidoctor/standoc/macros_plantuml.rb +29 -14
  23. data/lib/asciidoctor/standoc/macros_terms.rb +55 -8
  24. data/lib/asciidoctor/standoc/ref.rb +1 -1
  25. data/lib/asciidoctor/standoc/ref_sect.rb +26 -18
  26. data/lib/asciidoctor/standoc/reqt.rng +23 -2
  27. data/lib/asciidoctor/standoc/section.rb +13 -12
  28. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +50 -11
  29. data/lib/asciidoctor/standoc/terms.rb +12 -2
  30. data/lib/asciidoctor/standoc/utils.rb +36 -23
  31. data/lib/asciidoctor/standoc/validate.rb +45 -27
  32. data/lib/asciidoctor/standoc/validate_section.rb +5 -2
  33. data/lib/metanorma/standoc/version.rb +1 -1
  34. data/metanorma-standoc.gemspec +1 -1
  35. data/spec/asciidoctor/base_spec.rb +4 -3
  36. data/spec/asciidoctor/blocks_spec.rb +230 -49
  37. data/spec/asciidoctor/cleanup_sections_spec.rb +7 -7
  38. data/spec/asciidoctor/cleanup_spec.rb +105 -286
  39. data/spec/asciidoctor/cleanup_terms_spec.rb +1020 -0
  40. data/spec/asciidoctor/inline_spec.rb +2 -2
  41. data/spec/asciidoctor/lists_spec.rb +6 -6
  42. data/spec/asciidoctor/macros_plantuml_spec.rb +36 -1
  43. data/spec/asciidoctor/macros_spec.rb +190 -113
  44. data/spec/asciidoctor/refs_dl_spec.rb +4 -4
  45. data/spec/asciidoctor/refs_spec.rb +268 -108
  46. data/spec/asciidoctor/section_spec.rb +18 -18
  47. data/spec/asciidoctor/validate_spec.rb +87 -2
  48. data/spec/spec_helper.rb +8 -8
  49. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +50 -50
  50. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
  51. data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
  52. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  53. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +31 -31
  54. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
  55. data/spec/vcr_cassettes/isobib_get_124.yml +11 -11
  56. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  57. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
  58. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90fb9b89f2c7070b763519843f307f4d3ecebb8ee462d7017afb886a397de8a8
4
- data.tar.gz: b6f2e8253577f05a76e833d3a1e5d9f64fd47a7de48d8ec6703056b04965096a
3
+ metadata.gz: 25f4c5a4250a14fb1499512d51f25cf8ea7b1cc6dc7da44560dc442342a54773
4
+ data.tar.gz: 10dd5ba69da52963c0e9310834212fc5e74743f660a4cf533efdd721037f5f5d
5
5
  SHA512:
6
- metadata.gz: 17eb330f74f079b78db600f8030c15e497b6e0b1251157b9499cf532974280e6d4bb61ebe7d4c52cc443ca4d407371b575f6425783aa384e4c977733de528c5e
7
- data.tar.gz: f3063d8116e77c1e00cf6f9ba12668e5bfbb581d41e02e9d4c4fee2dc21884754f8102a718d7318d3b0619abaf1715528162e9aebcb97895a7ab85bbeb6fccd4
6
+ metadata.gz: dbc30f8112130ea49edcfabf97fedc1d3934f41a09163369fb74ba754eb5d11e861e040df17b15e2f865b7f5bb43d8513a76f859bc192eb2f30f23e4dea67232
7
+ data.tar.gz: 2ce49c90d894757b2964c4922b702bfb54c24f5e8d53a530a399692f6003042d8c9d44f5ebbc57110d6c56bc3d18fc17650e2511c8b102e38dce2a0d7b85fd41
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
@@ -38,7 +39,7 @@ module Asciidoctor
38
39
  scripts: node.attr("scripts"),
39
40
  scripts_override: node.attr("scripts-override"),
40
41
  scripts_pdf: node.attr("scripts-pdf"),
41
- datauriimage: node.attr("data-uri-image"),
42
+ datauriimage: node.attr("data-uri-image") != "false",
42
43
  htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
43
44
  doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
44
45
  break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
@@ -46,6 +47,7 @@ module Asciidoctor
46
47
  bare: node.attr("bare"),
47
48
  sectionsplit: node.attr("sectionsplit"),
48
49
  baseassetpath: node.attr("base-asset-path"),
50
+ aligncrosselements: node.attr("align-cross-elements"),
49
51
  }
50
52
  end
51
53
 
@@ -81,11 +83,12 @@ module Asciidoctor
81
83
  suppressasciimathdup: node.attr("suppress-asciimath-dup"),
82
84
  bare: node.attr("bare"),
83
85
  baseassetpath: node.attr("base-asset-path"),
86
+ aligncrosselements: node.attr("align-cross-elements"),
84
87
  }
85
88
 
86
- if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
89
+ if fonts_manifest = node.attr(FONTS_MANIFEST)
87
90
  attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
88
- IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => font_manifest_file,
91
+ IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
89
92
  }
90
93
  end
91
94
 
@@ -125,7 +128,7 @@ module Asciidoctor
125
128
  @sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
126
129
  @bibdb = nil
127
130
  @seen_headers = []
128
- @datauriimage = node.attr("data-uri-image")
131
+ @datauriimage = node.attr("data-uri-image") != "false"
129
132
  @boilerplateauthority = node.attr("boilerplate-authority")
130
133
  @sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
131
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)
@@ -9,6 +9,7 @@ require_relative "./cleanup_ref_dl"
9
9
  require_relative "./cleanup_boilerplate"
10
10
  require_relative "./cleanup_section"
11
11
  require_relative "./cleanup_terms"
12
+ require_relative "./cleanup_symbols"
12
13
  require_relative "./cleanup_xref"
13
14
  require_relative "./cleanup_inline"
14
15
  require_relative "./cleanup_amend"
@@ -41,6 +42,7 @@ module Asciidoctor
41
42
  symbols_cleanup(xmldoc)
42
43
  xref_cleanup(xmldoc)
43
44
  concept_cleanup(xmldoc)
45
+ related_cleanup(xmldoc)
44
46
  origin_cleanup(xmldoc)
45
47
  bookmark_cleanup(xmldoc)
46
48
  termdef_cleanup(xmldoc)
@@ -73,7 +75,8 @@ module Asciidoctor
73
75
  %w{status language script version author name callout phone email
74
76
  street city state country postcode identifier referenceFrom surname
75
77
  referenceTo docidentifier docnumber prefix initial addition forename
76
- title draft secretariat title-main title-intro title-part}.freeze
78
+ title draft secretariat title-main title-intro title-part
79
+ verbaldefinition nonverbalrepresentation}.freeze
77
80
 
78
81
  # it seems Nokogiri::XML is treating the content of <script> as cdata,
79
82
  # because of its use in HTML. Bad nokogiri. Undoing that, since we use
@@ -83,7 +86,9 @@ module Asciidoctor
83
86
  end
84
87
 
85
88
  def empty_element_cleanup(xmldoc)
86
- 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
+
87
92
  x.remove if x.children.empty?
88
93
  end
89
94
  end
@@ -108,19 +113,23 @@ module Asciidoctor
108
113
  n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
109
114
  end
110
115
 
111
- c.xpath("./variant").each do |n|
112
- if n.at_xpath("preceding-sibling::node()"\
113
- "[not(self::text()[not(normalize-space())])][1]"\
114
- "[self::variantwrap]")
115
- n.previous_element << n
116
- else
117
- n.replace("<variantwrap/>").first << n
118
- end
119
- end
116
+ variant_cleanup1(c)
120
117
  end
121
118
  xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
122
119
  end
123
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
+
124
133
  def variant_space_cleanup(xmldoc)
125
134
  xmldoc.xpath("//*[variant]").each do |c|
126
135
  if c&.next&.text? && c&.next&.next&.name == "variant"
@@ -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
 
@@ -1,4 +1,5 @@
1
1
  require "metanorma-utils"
2
+ require "digest"
2
3
 
3
4
  module Asciidoctor
4
5
  module Standoc
@@ -59,13 +60,26 @@ module Asciidoctor
59
60
  xmldoc.xpath("//concept[not(termxref)]").each do |x|
60
61
  term = x.at("./refterm")
61
62
  term&.remove if term&.text&.empty?
62
- x.children.remove if x&.children&.text&.strip&.empty?
63
- key_extract_locality(x)
64
- if /:/.match?(x["key"]) then concept_termbase_cleanup(x)
65
- elsif refid? x["key"] then concept_eref_cleanup(x)
66
- else concept_xref_cleanup(x)
67
- end
68
- x.delete("key")
63
+ concept_cleanup1(x)
64
+ end
65
+ end
66
+
67
+ def concept_cleanup1(elem)
68
+ elem.children.remove if elem&.children&.text&.strip&.empty?
69
+ key_extract_locality(elem)
70
+ if /:/.match?(elem["key"]) then concept_termbase_cleanup(elem)
71
+ elsif refid? elem["key"] then concept_eref_cleanup(elem)
72
+ else concept_xref_cleanup(elem)
73
+ end
74
+ elem.delete("key")
75
+ end
76
+
77
+ def related_cleanup(xmldoc)
78
+ xmldoc.xpath("//related[not(termxref)]").each do |x|
79
+ term = x.at("./refterm")
80
+ term.replace("<preferred>#{term_expr(term.children.to_xml)}"\
81
+ "</preferred>")
82
+ concept_cleanup1(x)
69
83
  end
70
84
  end
71
85
 
@@ -112,6 +126,7 @@ module Asciidoctor
112
126
  def anchor_cleanup(elem)
113
127
  anchor_cleanup1(elem)
114
128
  xreftarget_cleanup(elem)
129
+ contenthash_id_cleanup(elem)
115
130
  end
116
131
 
117
132
  def anchor_cleanup1(elem)
@@ -137,6 +152,29 @@ module Asciidoctor
137
152
  end
138
153
  end
139
154
  end
155
+
156
+ def guid?(str)
157
+ /^_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
158
+ .match?(str)
159
+ end
160
+
161
+ def contenthash_id_cleanup(doc)
162
+ ids = doc.xpath("//*[@id]").each_with_object({}) do |x, m|
163
+ next unless guid?(x["id"])
164
+
165
+ m[x["id"]] = contenthash(x)
166
+ x["id"] = m[x["id"]]
167
+ end
168
+ [%w(review from), %(review to), %(callout target), %(eref bibitemid),
169
+ %(citation bibitemid), %(xref target), %(xref to)].each do |a|
170
+ doc.xpath("//#{a[0]}").each { |x| ids[a[1]] and x[a[1]] = ids[a[1]] }
171
+ end
172
+ end
173
+
174
+ def contenthash(elem)
175
+ Digest::MD5.hexdigest("#{elem.path}////#{elem.text}")
176
+ .sub(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "_\\1-\\2-\\3-\\4-\\5")
177
+ end
140
178
  end
141
179
  end
142
180
  end
@@ -69,13 +69,12 @@ module Asciidoctor
69
69
  return false if char.length > 1
70
70
 
71
71
  if /\p{Greek}/.match?(char)
72
- /\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek] ||
73
- /\p{Upper}/.match(char) && !mathml_mi_italics[:uppergreek]
72
+ (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowergreek]) ||
73
+ (/\p{Upper}/.match(char) && !mathml_mi_italics[:uppergreek])
74
74
  elsif /\p{Latin}/.match?(char)
75
- /\p{Lower}/.match(char) && !mathml_mi_italics[:lowerroman] ||
76
- /\p{Upper}/.match(char) && !mathml_mi_italics[:upperroman]
77
- else
78
- false
75
+ (/\p{Lower}/.match(char) && !mathml_mi_italics[:lowerroman]) ||
76
+ (/\p{Upper}/.match(char) && !mathml_mi_italics[:upperroman])
77
+ else false
79
78
  end
80
79
  end
81
80
 
@@ -84,6 +84,11 @@ module Asciidoctor
84
84
  biblio_reorder(xmldoc)
85
85
  biblio_nested(xmldoc)
86
86
  biblio_renumber(xmldoc)
87
+ biblio_no_ext(xmldoc)
88
+ end
89
+
90
+ def biblio_no_ext(xmldoc)
91
+ xmldoc.xpath("//bibitem/ext").each(&:remove)
87
92
  end
88
93
 
89
94
  def biblio_nested(xmldoc)
@@ -86,33 +86,14 @@ module Asciidoctor
86
86
  ins = reqt.children.first
87
87
  end
88
88
  %w(obligation model type).each do |a|
89
- reqt_dl_to_attrs(reqt, dlist, a)
89
+ dl_to_attrs(reqt, dlist, a)
90
90
  end
91
91
  requirement_metadata1_tags.each do |a|
92
- ins = reqt_dl_to_elems(ins, reqt, dlist, a)
92
+ ins = dl_to_elems(ins, reqt, dlist, a)
93
93
  end
94
94
  reqt_dl_to_classif(ins, reqt, dlist)
95
95
  end
96
96
 
97
- def reqt_dl_to_attrs(reqt, dlist, name)
98
- e = dlist.at("./dt[text()='#{name}']") or return
99
- val = e.at("./following::dd/p") || e.at("./following::dd") or return
100
- reqt[name] = val.text
101
- end
102
-
103
- def reqt_dl_to_elems(ins, reqt, dlist, name)
104
- if a = reqt.at("./#{name}[last()]")
105
- ins = a
106
- end
107
- dlist.xpath("./dt[text()='#{name}']").each do |e|
108
- val = e.at("./following::dd/p") || e.at("./following::dd")
109
- val.name = name
110
- ins.next = val
111
- ins = ins.next
112
- end
113
- ins
114
- end
115
-
116
97
  def reqt_dl_to_classif(ins, reqt, dlist)
117
98
  if a = reqt.at("./classification[last()]") then ins = a end
118
99
  dlist.xpath("./dt[text()='classification']").each do |e|