metanorma-standoc 3.2.4 → 3.3.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/html/htmlstyle.css +6 -2
  3. data/lib/isodoc/html/htmlstyle.scss +1 -1
  4. data/lib/metanorma/cleanup/amend.rb +78 -0
  5. data/lib/metanorma/{standoc/cleanup_asciibib.rb → cleanup/asciibib.rb} +1 -1
  6. data/lib/metanorma/{standoc/cleanup_attachment.rb → cleanup/attachment.rb} +1 -1
  7. data/lib/metanorma/{standoc/cleanup_bibdata.rb → cleanup/bibdata.rb} +18 -9
  8. data/lib/metanorma/{standoc/cleanup_bibitem.rb → cleanup/bibitem.rb} +11 -9
  9. data/lib/metanorma/{standoc/cleanup_block.rb → cleanup/block.rb} +53 -66
  10. data/lib/metanorma/{standoc/cleanup_boilerplate.rb → cleanup/boilerplate.rb} +25 -77
  11. data/lib/metanorma/cleanup/boilerplate_liquid.rb +74 -0
  12. data/lib/metanorma/{standoc → cleanup}/cleanup.rb +133 -85
  13. data/lib/metanorma/{standoc/cleanup_dochistory.rb → cleanup/dochistory.rb} +17 -4
  14. data/lib/metanorma/{standoc/cleanup_footnotes.rb → cleanup/footnotes.rb} +1 -1
  15. data/lib/metanorma/{standoc/cleanup_image.rb → cleanup/image.rb} +2 -2
  16. data/lib/metanorma/cleanup/index.rb +63 -0
  17. data/lib/metanorma/{standoc/cleanup_inline.rb → cleanup/inline.rb} +1 -1
  18. data/lib/metanorma/cleanup/log.rb +41 -0
  19. data/lib/metanorma/{standoc/cleanup_maths.rb → cleanup/maths.rb} +2 -2
  20. data/lib/metanorma/{standoc/cleanup_mathvariant.rb → cleanup/mathvariant.rb} +1 -1
  21. data/lib/metanorma/{standoc → cleanup}/merge_bibitems.rb +1 -1
  22. data/lib/metanorma/cleanup/metadata.rb +54 -0
  23. data/lib/metanorma/{standoc/cleanup_ref.rb → cleanup/ref.rb} +13 -7
  24. data/lib/metanorma/{standoc/cleanup_reqt.rb → cleanup/reqt.rb} +2 -2
  25. data/lib/metanorma/{standoc/cleanup_review.rb → cleanup/review.rb} +1 -1
  26. data/lib/metanorma/{standoc/cleanup_section.rb → cleanup/section.rb} +2 -2
  27. data/lib/metanorma/{standoc/cleanup_section_names.rb → cleanup/section_names.rb} +1 -1
  28. data/lib/metanorma/{standoc → cleanup}/spans_to_bibitem.rb +5 -4
  29. data/lib/metanorma/{standoc → cleanup}/spans_to_bibitem_preprocessing.rb +3 -5
  30. data/lib/metanorma/{standoc/cleanup_symbols.rb → cleanup/symbols.rb} +2 -2
  31. data/lib/metanorma/{standoc/cleanup_table.rb → cleanup/table.rb} +4 -11
  32. data/lib/metanorma/{standoc/term_lookup_cleanup.rb → cleanup/term_lookup.rb} +1 -1
  33. data/lib/metanorma/{standoc/cleanup_terms.rb → cleanup/terms.rb} +3 -22
  34. data/lib/metanorma/{standoc/cleanup_terms_boilerplate.rb → cleanup/terms_boilerplate.rb} +3 -14
  35. data/lib/metanorma/{standoc/cleanup_terms_designations.rb → cleanup/terms_designations.rb} +1 -1
  36. data/lib/metanorma/{standoc/cleanup_text.rb → cleanup/text.rb} +1 -6
  37. data/lib/metanorma/{standoc/cleanup_toc.rb → cleanup/toc.rb} +10 -8
  38. data/lib/metanorma/{standoc/cleanup_xref.rb → cleanup/xref.rb} +47 -96
  39. data/lib/metanorma/cleanup/xref_localities.rb +119 -0
  40. data/lib/metanorma/{standoc → converter}/base.rb +40 -19
  41. data/lib/metanorma/{standoc → converter}/blocks.rb +24 -63
  42. data/lib/metanorma/converter/blocks_examples.rb +65 -0
  43. data/lib/metanorma/{standoc → converter}/blocks_image.rb +1 -1
  44. data/lib/metanorma/{standoc/blocks_notes.rb → converter/blocks_notes_examples.rb} +60 -0
  45. data/lib/metanorma/{standoc → converter}/converter.rb +12 -4
  46. data/lib/metanorma/converter/date_utils.rb +52 -0
  47. data/lib/metanorma/{standoc → converter}/front.rb +31 -40
  48. data/lib/metanorma/{standoc → converter}/front_committee.rb +24 -17
  49. data/lib/metanorma/{standoc → converter}/front_ext.rb +2 -1
  50. data/lib/metanorma/converter/front_title.rb +68 -0
  51. data/lib/metanorma/{standoc → converter}/init.rb +37 -11
  52. data/lib/metanorma/{standoc → converter}/isolated_converter.rb +1 -10
  53. data/lib/metanorma/{standoc → converter}/log.rb +12 -0
  54. data/lib/metanorma/converter/macros.rb +92 -0
  55. data/lib/metanorma/{standoc → converter}/macros_inline.rb +0 -39
  56. data/lib/metanorma/{standoc/macros.rb → converter/macros_nosub.rb} +63 -88
  57. data/lib/metanorma/converter/macros_number.rb +77 -0
  58. data/lib/metanorma/{standoc → converter}/ref.rb +1 -1
  59. data/lib/metanorma/{standoc → converter}/ref_queue.rb +10 -1
  60. data/lib/metanorma/{standoc → converter}/ref_utility.rb +6 -1
  61. data/lib/metanorma/{standoc → converter}/regex.rb +1 -1
  62. data/lib/metanorma/{standoc → converter}/render.rb +61 -48
  63. data/lib/metanorma/{standoc → converter}/terms.rb +1 -0
  64. data/lib/metanorma/{standoc → converter}/utils.rb +9 -16
  65. data/lib/metanorma/{standoc → converter}/version.rb +1 -1
  66. data/lib/metanorma/standoc.rb +1 -1
  67. data/lib/metanorma/{standoc → validate}/basicdoc.rng +5 -1
  68. data/lib/metanorma/validate/image.rb +190 -0
  69. data/lib/metanorma/{standoc → validate}/isodoc.rng +52 -16
  70. data/lib/metanorma/validate/schema.rb +149 -0
  71. data/lib/metanorma/validate/section.rb +81 -0
  72. data/lib/metanorma/validate/table.rb +97 -0
  73. data/lib/metanorma/validate/term.rb +137 -0
  74. data/lib/metanorma/{standoc → validate}/validate.rb +62 -17
  75. data/lib/metanorma-standoc.rb +2 -2
  76. data/lib/nokogiri/xml/builder.rb +16 -0
  77. data/metanorma-standoc.gemspec +2 -2
  78. metadata +106 -95
  79. data/lib/metanorma/standoc/cleanup_amend.rb +0 -56
  80. data/lib/metanorma/standoc/validate_image.rb +0 -138
  81. data/lib/metanorma/standoc/validate_schema.rb +0 -119
  82. data/lib/metanorma/standoc/validate_section.rb +0 -75
  83. data/lib/metanorma/standoc/validate_table.rb +0 -95
  84. data/lib/metanorma/standoc/validate_term.rb +0 -110
  85. /data/lib/metanorma/{standoc → converter}/anchor.rb +0 -0
  86. /data/lib/metanorma/{standoc → converter}/front_contributor.rb +0 -0
  87. /data/lib/metanorma/{standoc → converter}/front_organisation.rb +0 -0
  88. /data/lib/metanorma/{standoc → converter}/inline.rb +0 -0
  89. /data/lib/metanorma/{standoc → converter}/lists.rb +0 -0
  90. /data/lib/metanorma/{standoc → converter}/localbib.rb +0 -0
  91. /data/lib/metanorma/{standoc → converter}/macros_embed.rb +0 -0
  92. /data/lib/metanorma/{standoc → converter}/macros_form.rb +0 -0
  93. /data/lib/metanorma/{standoc → converter}/macros_link.rb +0 -0
  94. /data/lib/metanorma/{standoc → converter}/macros_note.rb +0 -0
  95. /data/lib/metanorma/{standoc → converter}/macros_terms.rb +0 -0
  96. /data/lib/metanorma/{standoc → converter}/processor.rb +0 -0
  97. /data/lib/metanorma/{standoc → converter}/ref_sect.rb +0 -0
  98. /data/lib/metanorma/{standoc → converter}/reqt.rb +0 -0
  99. /data/lib/metanorma/{standoc → converter}/section.rb +0 -0
  100. /data/lib/metanorma/{standoc → converter}/sectiontype.rb +0 -0
  101. /data/lib/metanorma/{standoc → converter}/table.rb +0 -0
  102. /data/lib/metanorma/{standoc → validate}/biblio-standoc.rng +0 -0
  103. /data/lib/metanorma/{standoc → validate}/biblio.rng +0 -0
  104. /data/lib/metanorma/{standoc → validate}/isodoc-compile.rng +0 -0
  105. /data/lib/metanorma/{standoc → validate}/reqt.rng +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec17f7140bc90f4bf870ab2ecf47e42adacc489e4e5dfc8802dbbea87a31973f
4
- data.tar.gz: 3da2d1e8a995ebc3d5fb5fe10694cd1094343261e58667007250ed07dde5ea1b
3
+ metadata.gz: 8ebe9c752511841d783fa0d9820ee7bd26448703e6990bbd406ae0d92ab35417
4
+ data.tar.gz: b6e82ef1d270969216902f745314145917cbdc376fe92fe11b76964cdd8bb6f1
5
5
  SHA512:
6
- metadata.gz: 44afc48d384a6c8685b223feaa5905a56cc1d3ee9b572abd221b839be690698d73bb253539abe8f4ece2810185ebd6dc64321a0aa7335007a6384ad4fbea2f18
7
- data.tar.gz: dc1ef34776bca5944dec22bad965498970de309848b4fb9c9370dfe303490d57b5dceedae26bac8f0b5cce7642318a607c613fa0044ba10e5fd6b58972ed9a3e
6
+ metadata.gz: 7b35e03b90cf332d1c100003d1e5bd72a524ffb085eb3b85428ebaac975f51d69562404e31f761894b22d51a9245be804f27a6e230299ed904ab497ebfc1d3c5
7
+ data.tar.gz: 29a42e39bbc67f18b07d557f32da4dbd3a6747f913108b4cfa2a74f610484cfd114d127e78fe8b21e4bf45ef255de955947967402f78d4f4cf3bfb07b77a6694
@@ -624,7 +624,7 @@ body pre * {
624
624
  }
625
625
  }
626
626
 
627
- div.figure .FigureTitle, div.figure .figure-title {
627
+ div.figure figcaption {
628
628
  font-weight: 700;
629
629
  font-size: 1em;
630
630
  text-align: center;
@@ -1066,8 +1066,12 @@ table th, table td {
1066
1066
  table td.header {
1067
1067
  font-weight: 400;
1068
1068
  }
1069
+ table table.plain, table table.plain th, table table.plain td {
1070
+ border: none !important;
1071
+ font-size: 0.95em;
1072
+ }
1069
1073
 
1070
- p.TableTitle {
1074
+ table > caption {
1071
1075
  text-align: center;
1072
1076
  margin-top: 2.5em;
1073
1077
  font-weight: 400;
@@ -368,7 +368,7 @@ table {
368
368
  @include table(1px solid black);
369
369
  }
370
370
 
371
- p.TableTitle {
371
+ table > caption {
372
372
  text-align: center;
373
373
  margin-top: 2.5em;
374
374
  font-weight: 400;
@@ -0,0 +1,78 @@
1
+ module Metanorma
2
+ module Standoc
3
+ module Amend
4
+ def change_clauses(docxml)
5
+ docxml.xpath("//clause[@change]").each do |c|
6
+ create_amend(c)
7
+ end
8
+ end
9
+
10
+ def create_amend(clause)
11
+ a = clause.add_child("<amend/>").first
12
+ add_id(a)
13
+ clause.elements.each do |e|
14
+ e.parent = a unless %w(amend title).include? e.name
15
+ end
16
+ create_amend1(clause, a)
17
+ end
18
+
19
+ def create_amend1(clause, amend)
20
+ create_amend2(clause, amend)
21
+ move_attrs_to_amend(clause, amend)
22
+ create_amend_autonum(amend)
23
+ amend
24
+ end
25
+
26
+ def create_amend_autonum(amend)
27
+ autonum = (amend.xpath(".//autonumber") -
28
+ amend.xpath(".//clause//autonumber")).map(&:remove)
29
+ amend.xpath(".//p[normalize-space(.)='']").each(&:remove)
30
+ ins = amend.children.first
31
+ autonum.each { |a| ins.previous = a }
32
+ (amend.xpath(".//clause") - amend.xpath(".//clause/clause")).each do |c|
33
+ create_amend_autonum(c)
34
+ end
35
+ end
36
+
37
+ # possible formats: DESC? BLOCKQUOTE DESC?; DESC? BLOCKQUOTE? SUBCLAUSES+
38
+ def create_amend2(clause, amend)
39
+ q, pre, post = create_amend2_prep(clause, amend)
40
+ if q.empty?
41
+ amend.children = "<description>#{amend.children.to_xml}</description>"
42
+ return
43
+ end
44
+ ins = amend.add_child("<newcontent/>").first
45
+ q.each { |n| ins << n.remove }
46
+ pre.empty? or ins.previous = "<description>#{pre.to_xml}</description>"
47
+ post.empty? or ins.next = "<description>#{post.to_xml}</description>"
48
+ end
49
+
50
+ def create_amend2_prep(_clause, amend)
51
+ ret = amend.xpath("./quote[1]")
52
+ ret += amend.xpath("./clause")
53
+ ret.empty? and return [[], nil, nil]
54
+ pre = ret[0].xpath("./preceding-sibling::*").each(&:remove)
55
+ post = ret[-1].xpath("./following-sibling::*").each(&:remove)
56
+ ret[0].name == "quote" and ret = ret[0].remove.children + ret[1..]
57
+ [ret, pre, post]
58
+ end
59
+
60
+ def move_attrs_to_amend(clause, amend)
61
+ %w(change path path_end title).each do |e|
62
+ clause[e] or next
63
+ amend[e] = clause[e]
64
+ clause.delete(e)
65
+ end
66
+ move_attrs_to_amend_locality(clause, amend)
67
+ end
68
+
69
+ def move_attrs_to_amend_locality(_clause, amend)
70
+ amend["locality"] or return
71
+ loc = amend.children.add_previous_sibling("<location/>")
72
+ extract_localities1(loc, amend["locality"])
73
+ loc1 = loc.at("./localityStack") and loc.replace(loc1.elements)
74
+ amend.delete("locality")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -2,7 +2,7 @@ require "relaton_bib"
2
2
 
3
3
  module Metanorma
4
4
  module Standoc
5
- module Cleanup
5
+ module Asciibib
6
6
  def ref_dl_cleanup(xmldoc)
7
7
  xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
8
8
  bib = dl_bib_extract(c) or next
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- module Cleanup
3
+ module Attachment
4
4
  def attachment_cleanup(xmldoc)
5
5
  xmldoc.xpath("//bibitem[uri/@type = 'attachment']").each do |b|
6
6
  b["hidden"] = "true"
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- module Cleanup
3
+ module Bibdata
4
4
  def bibdata_cleanup(xmldoc)
5
5
  bibdata_anchor_cleanup(xmldoc)
6
6
  bibdata_docidentifier_cleanup(xmldoc)
@@ -16,8 +16,8 @@ module Metanorma
16
16
  backpage-image).each do |n|
17
17
  xmldoc.xpath("//bibdata/ext/#{n}").each do |x|
18
18
  ins = add_misc_container(xmldoc)
19
- ins << "<presentation-metadata><name>#{n}</name>" \
20
- "<value>#{x.remove.children.to_xml}</value>" \
19
+ ins << "<presentation-metadata><#{n}>" \
20
+ "#{x.remove.children.to_xml}</#{n}>" \
21
21
  "</presentation-metadata>"
22
22
  end
23
23
  end
@@ -42,8 +42,8 @@ module Metanorma
42
42
  def gather_indirect_erefs(xmldoc, prefix)
43
43
  xmldoc.xpath("//eref[@type = '#{prefix}']")
44
44
  .each_with_object({}) do |e, m|
45
- e.delete("type")
46
- m[e["bibitemid"]] = true
45
+ e.delete("type")
46
+ m[e["bibitemid"]] = true
47
47
  end.keys
48
48
  end
49
49
 
@@ -96,7 +96,7 @@ module Metanorma
96
96
  # (which is what bibitemid currently points to)
97
97
  id_map = xmldoc.xpath("//*[@anchor]")
98
98
  .each_with_object({}) do |node, map|
99
- map[node["anchor"]] = node
99
+ map[node["anchor"]] = node
100
100
  end
101
101
  # Pre-index all <eref> elements by bibitemid
102
102
  eref_map = xmldoc.xpath("//eref[@bibitemid]")
@@ -120,7 +120,7 @@ module Metanorma
120
120
  end
121
121
 
122
122
  def hdr2bibitem(hdr)
123
- xml = isolated_asciidoctor_convert(hdr[:text],
123
+ xml = @conv.isolated_asciidoctor_convert(hdr[:text],
124
124
  backend: hdr2bibitem_type(hdr),
125
125
  header_footer: true)
126
126
  b = Nokogiri::XML(xml).at("//xmlns:bibdata")
@@ -154,7 +154,7 @@ module Metanorma
154
154
  bibdata.at("./docidentifier")
155
155
  xmldoc.xpath("//xref[@target = '#{d}'][normalize-space(.//text()) = '']")
156
156
  .each do |x|
157
- x << ident.text
157
+ x << ident.text
158
158
  end
159
159
  end
160
160
  end
@@ -190,12 +190,19 @@ module Metanorma
190
190
  ins = add_misc_container(xmldoc)
191
191
  ins ||= add_misc_container(xmldoc)
192
192
  ins.at("./semantic-metadata/stage-published") and return
193
- p = published?(xmldoc.at("bibdata/status/stage")&.text, xmldoc)
193
+ p = published_base?(xmldoc.at("bibdata/status/stage")&.text, xmldoc)
194
194
  ins << <<~XML
195
195
  <semantic-metadata><stage-published>#{p}</stage-published></semantic-metadata>
196
196
  XML
197
197
  end
198
198
 
199
+ def published_base?(stage, _xmldoc)
200
+ if @stage_published
201
+ @stage_published == "true"
202
+ else published?(stage, _xmldoc)
203
+ end
204
+ end
205
+
199
206
  def published?(stage, _xmldoc)
200
207
  stage.casecmp("published").zero?
201
208
  end
@@ -215,6 +222,8 @@ module Metanorma
215
222
  p.nil? || p.text.strip.empty? and c.remove
216
223
  end
217
224
  end
225
+
226
+ def docidentifier_cleanup(xmldoc); end
218
227
  end
219
228
  end
220
229
  end
@@ -1,8 +1,10 @@
1
- require_relative "cleanup_attachment"
1
+ require_relative "attachment"
2
2
 
3
3
  module Metanorma
4
4
  module Standoc
5
- module Cleanup
5
+ module Bibitem
6
+ include Attachment
7
+
6
8
  def formattedref_spans(xmldoc)
7
9
  xmldoc.xpath("//bibitem[formattedref//span]").each do |b|
8
10
  ret = new_bibitem_from_formattedref_spans(b)
@@ -14,7 +16,7 @@ module Metanorma
14
16
  end
15
17
 
16
18
  def new_bibitem_from_formattedref_spans(bib)
17
- ret = SpansToBibitem.new(bib).convert
19
+ ret = Metanorma::Standoc::Cleanup::SpansToBibitem.new(bib).convert
18
20
  ret.err.each do |e|
19
21
  @log.add(e[:fatal] ? "STANDOC_52" : "STANDOC_53",
20
22
  bib, params: [e[:msg]])
@@ -26,7 +28,7 @@ module Metanorma
26
28
  merge_bibitem_from_formattedref_span_attrs(bib, new)
27
29
  if bib.at("./title") && bib["amend"]
28
30
  # there already is a fetched record here: merge
29
- bib.children = MergeBibitems
31
+ bib.children = Metanorma::Standoc::Cleanup::MergeBibitems
30
32
  .new(bib.to_xml, new.to_xml).merge.to_noko.children
31
33
  elsif bib.at("./title") # replace record
32
34
  bib.children = new.children.to_xml
@@ -135,11 +137,11 @@ module Metanorma
135
137
  def fetch_local_bibitem(xmldoc)
136
138
  xmldoc.xpath("//bibitem[formattedref][uri[@type = 'citation']]")
137
139
  .each do |b|
138
- uri = b&.at("./uri[@type = 'citation']")&.text
139
- bibitem = read_local_bibitem(uri) or next
140
- bibitem["id"] = b["id"]
141
- bibitem["anchor"] = b["anchor"]
142
- b.replace(bibitem)
140
+ uri = b&.at("./uri[@type = 'citation']")&.text
141
+ bibitem = read_local_bibitem(uri) or next
142
+ bibitem["id"] = b["id"]
143
+ bibitem["anchor"] = b["anchor"]
144
+ b.replace(bibitem)
143
145
  end
144
146
  end
145
147
 
@@ -3,7 +3,7 @@ require "htmlentities"
3
3
 
4
4
  module Metanorma
5
5
  module Standoc
6
- module Cleanup
6
+ module Block
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)]",
@@ -21,6 +21,23 @@ module Metanorma
21
21
  end
22
22
  end
23
23
 
24
+ def key_cleanup(xmldoc)
25
+ xmldoc.xpath("//*[@key = 'true']").each do |x|
26
+ x.delete("key")
27
+ x.replace("<key>#{to_xml(x)}</key>")
28
+ end
29
+ key_concatenate(xmldoc)
30
+ xmldoc.xpath("//key//key").each { |x| x.replace(x.children) }
31
+ end
32
+
33
+ def key_concatenate(xmldoc)
34
+ xmldoc.xpath("//key").each do |x|
35
+ while x.next_element&.name == "key"
36
+ x << x.next_element.remove.children
37
+ end
38
+ end
39
+ end
40
+
24
41
  # include where definition list inside stem block
25
42
  def formula_cleanup(formula)
26
43
  formula_cleanup_where1(formula)
@@ -28,49 +45,44 @@ module Metanorma
28
45
  end
29
46
 
30
47
  def formula_cleanup_where1(formula)
31
- q = "//formula/following-sibling::*[1][self::dl]"
48
+ q = "//formula/following-sibling::*[1][self::key]"
32
49
  formula.xpath(q).each do |s|
33
- s["key"] == "true" and s.previous_element << s.remove
50
+ s.previous_element << s.remove
34
51
  end
35
52
  end
36
53
 
37
54
  def formula_cleanup_where2(formula)
38
- q = "//formula/following-sibling::*[1][self::p]"
39
- formula.xpath(q).each do |s|
40
- if s.text =~ /^\s*where[^a-z]*$/i && s&.next_element&.name == "dl"
41
- s.next_element["key"] = "true"
42
- s.previous_element << s.next_element.remove
55
+ text_key_extract(formula, "formula", "where")
56
+ end
57
+
58
+ def text_key_extract(elem, tag, keywd)
59
+ q = "//#{tag}/following-sibling::*[1][self::p]"
60
+ elem.xpath(q).each do |s|
61
+ if s.text =~ /^\s*#{keywd}[^a-z]*$/i && s&.next_element&.name == "dl"
62
+ s.previous_element << "<key>#{to_xml(s.next_element.remove)}</key>"
43
63
  s.remove
44
64
  end
45
65
  end
46
66
  end
47
67
 
48
68
  def figure_dl_cleanup1(xmldoc)
49
- q = "//figure/following-sibling::*[self::dl]"
50
- q1 = "//figure/figure/following-sibling::*[self::dl]"
69
+ q = "//figure/following-sibling::*[self::key]"
70
+ q1 = "//figure/figure/following-sibling::*[self::key]"
51
71
  (xmldoc.xpath(q) - xmldoc.xpath(q1)).each do |s|
52
- s["key"] == "true" and s.previous_element << s.remove
72
+ s.previous_element << s.remove
53
73
  end
54
74
  end
55
75
 
56
76
  # include key definition list inside figure
57
77
  def figure_dl_cleanup2(xmldoc)
58
- q = "//figure/following-sibling::*[self::p]"
59
- xmldoc.xpath(q).each do |s|
60
- if s.text =~ /^\s*key[^a-z]*$/i && s&.next_element&.name == "dl"
61
- s.next_element["key"] = "true"
62
- s.previous_element << s.next_element.remove
63
- s.remove
64
- end
65
- end
78
+ text_key_extract(xmldoc, "figure", "key")
66
79
  end
67
80
 
68
81
  # examples containing only figures become subfigures of figures
69
82
  def subfigure_cleanup(xmldoc)
70
83
  xmldoc.xpath("//example[figure]").each do |e|
71
84
  e.elements.reject do |m|
72
- %w(name figure index note).include?(m.name) ||
73
- (m.name == "dl" && m["key"] == "true")
85
+ %w(name figure index note key).include?(m.name)
74
86
  end.empty? or next
75
87
  e.name = "figure"
76
88
  end
@@ -115,7 +127,7 @@ module Metanorma
115
127
  def note_cleanup(xmldoc)
116
128
  xmldoc.xpath("//note").each do |n|
117
129
  n["keep-separate"] == "true" || !n.ancestors("table").empty? and next
118
- prev = n.previous_element || next
130
+ prev = n.previous_element or next
119
131
  n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
120
132
  end
121
133
  xmldoc.xpath("//note[@keep-separate] | " \
@@ -172,61 +184,36 @@ module Metanorma
172
184
  end
173
185
 
174
186
  def sourcecode_markup(node)
175
- node.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|
176
- #{Regexp.escape(@sourcecode_markup_end)})/x)
177
- .each_slice(4).map.with_object([]) do |a, acc|
187
+ source_markup_prep(node).each_slice(4).map.with_object([]) do |a, acc|
178
188
  acc << safe_noko(a[0], node.document)
179
189
  a.size == 4 or next
180
- acc << isolated_asciidoctor_convert(
181
- a[2], doctype: :inline, backend: backend&.to_sym || :standoc
182
- )
190
+ acc << @conv.isolated_asciidoctor_convert(
191
+ "{blank} #{a[2]}", doctype: :inline,
192
+ backend: @conv.backend&.to_sym || :standoc
193
+ ).strip
183
194
  end.join
184
195
  end
185
196
 
186
- def form_cleanup(xmldoc)
187
- xmldoc.xpath("//select").each do |s|
188
- while s.next_element&.name == "option"
189
- s << s.next_element
190
- end
191
- end
197
+ def source_markup_prep(node)
198
+ ret = node.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|
199
+ #{Regexp.escape(@sourcecode_markup_end)})/x)
200
+ source_markup_validate(node, ret)
201
+ ret
192
202
  end
193
203
 
194
- def block_index_cleanup(xmldoc)
195
- xmldoc.xpath("//quote | //td | //th | //formula | //li | //dt | " \
196
- "//dd | //example | //note | //figure | //sourcecode | " \
197
- "//admonition | //termnote | //termexample | //form | " \
198
- "//requirement | //recommendation | //permission | " \
199
- "//imagemap | //svgmap").each do |b|
200
- b.xpath("./p[indexterm]").each do |p|
201
- indexterm_para?(p) or next
202
- p.replace(p.children)
203
- end
204
+ def source_markup_validate(node, ret)
205
+ ret.each_slice(4) do |a|
206
+ a.size == 4 or next
207
+ a[1] == @sourcecode_markup_start && a[3] == @sourcecode_markup_end or
208
+ @log.add("STANDOC_61", node, params: [a.join])
204
209
  end
205
210
  end
206
211
 
207
- def indexterm_para?(para)
208
- p = para.dup
209
- p.xpath("./index").each(&:remove)
210
- p.text.strip.empty?
211
- end
212
-
213
- def include_indexterm?(elem)
214
- elem.nil? and return false
215
- !%w(image literal sourcecode).include?(elem.name)
216
- end
217
-
218
- def para_index_cleanup(xmldoc)
219
- xmldoc.xpath("//p[index]").select { |p| indexterm_para?(p) }
220
- .each do |p|
221
- para_index_cleanup1(p, p.previous_element, p.next_element)
212
+ def form_cleanup(xmldoc)
213
+ xmldoc.xpath("//select").each do |s|
214
+ while s.next_element&.name == "option"
215
+ s << s.next_element
222
216
  end
223
- end
224
-
225
- def para_index_cleanup1(para, prev, foll)
226
- if include_indexterm?(prev)
227
- prev << para.remove.children
228
- elsif include_indexterm?(foll) # && !foll.children.empty?
229
- foll.add_first_child para.remove.children
230
217
  end
231
218
  end
232
219
 
@@ -1,8 +1,9 @@
1
- require_relative "cleanup_terms_boilerplate"
1
+ require_relative "terms_boilerplate"
2
+ require_relative "boilerplate_liquid"
2
3
 
3
4
  module Metanorma
4
5
  module Standoc
5
- module Cleanup
6
+ module Boilerplate
6
7
  def norm_ref_preface(ref, isodoc)
7
8
  ins = norm_ref_boilerplate_insert_location(ref)
8
9
  ins2 = norm_ref_process_boilerplate_note(ref)
@@ -36,13 +37,9 @@ module Metanorma
36
37
  ref.at("./title")
37
38
  end
38
39
 
39
- NORM_REF =
40
- "//bibliography/references[@normative = 'true'][not(@hidden)] | " \
41
- "//bibliography/clause[.//references[@normative = 'true']]".freeze
42
-
43
40
  def dup_with_namespace(elem)
44
41
  ret = elem.dup
45
- ret.add_namespace(nil, xml_namespace)
42
+ ret.add_namespace(nil, @conv.xml_namespace)
46
43
  ret
47
44
  end
48
45
 
@@ -51,7 +48,8 @@ module Metanorma
51
48
  # in termdef_boilerplate_insert and initial_boilerplate
52
49
  xmldoc.at("//metanorma-extension/semantic-metadata/" \
53
50
  "headless[text() = 'true']") and return nil
54
- @isodoc ||= isodoc(@lang, @script, @locale)
51
+ @isodoc ||= @conv.isodoc(@lang, @script, @locale)
52
+ @i18n = @isodoc.i18n
55
53
  isodoc_bibdata_parse(xmldoc)
56
54
  @isodoc
57
55
  end
@@ -75,7 +73,7 @@ module Metanorma
75
73
 
76
74
  def boilerplate_cleanup(xmldoc)
77
75
  isodoc = boilerplate_isodoc(xmldoc) or return
78
- # boilerplate_isodoc_values(isodoc)
76
+ docidentifier_boilerplate_isodoc(xmldoc, isodoc)
79
77
  termdef_boilerplate_cleanup(xmldoc)
80
78
  termdef_boilerplate_insert(xmldoc, isodoc)
81
79
  unwrap_boilerplate_clauses(xmldoc, self.class::TERM_CLAUSE)
@@ -86,6 +84,17 @@ module Metanorma
86
84
  initial_boilerplate(xmldoc, isodoc)
87
85
  end
88
86
 
87
+ def docidentifier_boilerplate_isodoc(xmldoc, isodoc)
88
+ xmldoc.xpath("//docidentifier[@boilerplate]").each do |d|
89
+ b = d["boilerplate"] == "true"
90
+ d.delete("boilerplate")
91
+ b or next
92
+ id = boilerplate_snippet_convert(to_xml(d.children), isodoc)
93
+ p = Nokogiri::XML(id).at("//p")
94
+ d.children = p ? to_xml(p&.children) : id
95
+ end
96
+ end
97
+
89
98
  def initial_boilerplate(xml, isodoc)
90
99
  xml.at("//boilerplate") and return
91
100
  preface = xml.at("//preface | //sections | //annex | //references") or
@@ -170,68 +179,6 @@ module Metanorma
170
179
  end
171
180
  end
172
181
 
173
- # The boilerplate file is in Liquid AsciiDoc format
174
- # (technically, `boilerplate.adoc.liquid`).
175
- #
176
- # This file is processed separately from the main Metanorma document and
177
- # therefore is oblivious of the `{{ concept-mention }}` syntax.
178
- #
179
- # Due to historic reasons, the Liquid objects being evaluated in the
180
- # boilerplate document are XML strings. Notably these are the document
181
- # metadata, that are extracted from the already generated Metanorma XML.
182
- #
183
- # These XML strings are then passed into the AsciiDoc macros such as
184
- # `span:publisher[...]`.
185
- #
186
- # Here, we need to interpolate the XML strings into the AsciiDoc macros
187
- # without breaking the AsciiDoc syntax.
188
- #
189
- # EXAMPLE 1: `mailto:{{ pub_email }}[]`, we need to
190
- # convert it to:
191
- # `mailto:{{ pass-format:metanorma[++pub_email_xml++] }}[]`
192
- #
193
- # EXAMPLE 2: `link:{{ pub_uri}}[{{ pub_address }}, {{ pub_uri }}]`
194
- # We need to convert it to:
195
- # `link:{{ pass-format:metanorma[++pub_uri_xml++] }}[{{
196
- # pass-format:metanorma[++pub_address_xml++] }}, {{
197
- # pass-format:metanorma[++pub_uri_xml++] }}]`
198
- #
199
- # NOTE: The boilerplate may use macros that contain one or more
200
- # `{{ ... }}` in the target, and can contain spaces in them.
201
- #
202
- # NOTE: The routine needs to handle cases where the content
203
- # contains an escaped closing bracket `\]`.
204
-
205
- ADOC_MACRO_PATTERN = /\S+:[^\[\n]*\[[^\]\\]*(?:\\.[^\]\\]*)*\]/
206
-
207
- # Replace {{ ... }} with {{ pass-format:metanorma:[...] }} to preserve any
208
- # XML markup provided by Metanorma XML Metadata content, through the
209
- # `pass-format:metanorma` command.
210
- #
211
- # * If `{{ ... }}` is inside an Asciidoc macro, we have to wrap with
212
- # pass-format:metanorma:[...\].
213
- # * If this is a macro target (e.g. `mailto:{{x}}[]`, body: mailto:[{{x}}])
214
- # then do not use pass-format:metanorma.
215
-
216
- def boilerplate_read(file)
217
- ret = File.read(file, encoding: "UTF-8")
218
- /\.adoc(\.liquid)?$/.match?(file) or return ret
219
-
220
- # Split content into macro and non-macro parts
221
- parts = ret.split(/(#{ADOC_MACRO_PATTERN})/o)
222
-
223
- parts.map.with_index do |part, index|
224
- if index.odd? && valid_macro?(part)
225
- # This is a macro - leave unchanged
226
- part
227
- else
228
- # Not a macro - wrap {{ }} patterns
229
- part.gsub(/(?<!\{)(\{\{[^{}]+\}\})(?!\})/,
230
- "pass-format:metanorma[++\\1++]")
231
- end
232
- end.join
233
- end
234
-
235
182
  # If Asciidoctor, convert top clauses to tags and wrap in <boilerplate>
236
183
  def boilerplate_file_convert(file)
237
184
  ret = Nokogiri::XML(file).root and return ret
@@ -239,20 +186,21 @@ module Metanorma
239
186
  end
240
187
 
241
188
  def boilerplate_file_restructure(file)
242
- ret = adoc2xml(file, backend.to_sym)
189
+ ret = adoc2xml(file, @conv.backend.to_sym)
243
190
  boilerplate_xml_cleanup(ret)
244
191
  ret.name = "boilerplate"
245
192
  boilerplate_top_elements(ret)
246
193
  ret
247
194
  end
248
195
 
249
- private
250
-
251
- def valid_macro?(text)
252
- # Simple validation - does it look like a macro?
253
- text.match?(/^\S+:[^\[]*\[.*\]$/)
196
+ def boilerplate_snippet_convert(adoc, isodoc)
197
+ b = isodoc.populate_template(adoc, nil)
198
+ ret = boilerplate_xml_cleanup(adoc2xml(b, @conv.backend.to_sym))
199
+ @i18n.l10n(ret.children.to_xml, @lang, @script).strip
254
200
  end
255
201
 
202
+ private
203
+
256
204
  # remove Metanorma namespace, so generated doc containing boilerplate
257
205
  # can be queried consistently
258
206
  # _\d+ anchor is assigned to titleless clauses, will clash with main doc