metanorma-standoc 2.2.6 → 2.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/base.rb +3 -5
  3. data/lib/metanorma/standoc/biblio.rng +5 -0
  4. data/lib/metanorma/standoc/cleanup.rb +17 -17
  5. data/lib/metanorma/standoc/cleanup_amend.rb +2 -2
  6. data/lib/metanorma/standoc/cleanup_biblio.rb +2 -1
  7. data/lib/metanorma/standoc/cleanup_maths.rb +12 -4
  8. data/lib/metanorma/standoc/cleanup_section.rb +19 -9
  9. data/lib/metanorma/standoc/cleanup_symbols.rb +14 -7
  10. data/lib/metanorma/standoc/cleanup_text.rb +10 -4
  11. data/lib/metanorma/standoc/cleanup_toc.rb +1 -2
  12. data/lib/metanorma/standoc/cleanup_xref.rb +55 -14
  13. data/lib/metanorma/standoc/inline.rb +27 -12
  14. data/lib/metanorma/standoc/isodoc.rng +46 -12
  15. data/lib/metanorma/standoc/ref_utility.rb +1 -0
  16. data/lib/metanorma/standoc/render.rb +10 -1
  17. data/lib/metanorma/standoc/section.rb +10 -3
  18. data/lib/metanorma/standoc/utils.rb +6 -1
  19. data/lib/metanorma/standoc/validate.rb +1 -1
  20. data/lib/metanorma/standoc/version.rb +1 -1
  21. data/metanorma-standoc.gemspec +5 -2
  22. metadata +4 -128
  23. data/.github/workflows/automerge.yml +0 -31
  24. data/.github/workflows/rake.yml +0 -15
  25. data/.github/workflows/release.yml +0 -24
  26. data/Rakefile +0 -8
  27. data/bin/rspec +0 -18
  28. data/spec/assets/a1.adoc +0 -8
  29. data/spec/assets/a2.adoc +0 -10
  30. data/spec/assets/a3.adoc +0 -9
  31. data/spec/assets/a3a.adoc +0 -7
  32. data/spec/assets/a4.adoc +0 -4
  33. data/spec/assets/boilerplate.xml +0 -4
  34. data/spec/assets/codes.yml +0 -695
  35. data/spec/assets/correct.png +0 -0
  36. data/spec/assets/corrupt.png +0 -0
  37. data/spec/assets/header.html +0 -7
  38. data/spec/assets/html-override.css +0 -1
  39. data/spec/assets/html.scss +0 -13
  40. data/spec/assets/htmlcover.html +0 -4
  41. data/spec/assets/htmlintro.html +0 -5
  42. data/spec/assets/i18n.yaml +0 -17
  43. data/spec/assets/iso.adoc +0 -10
  44. data/spec/assets/iso.headless.html +0 -33
  45. data/spec/assets/iso.xml +0 -8
  46. data/spec/assets/iso123.rxl +0 -107
  47. data/spec/assets/rice_image1.png +0 -0
  48. data/spec/assets/scripts.html +0 -3
  49. data/spec/assets/std.css +0 -2
  50. data/spec/assets/word-override.css +0 -1
  51. data/spec/assets/word.scss +0 -13
  52. data/spec/assets/wordcover.html +0 -3
  53. data/spec/assets/wordintro.html +0 -4
  54. data/spec/assets/xref_error.adoc +0 -8
  55. data/spec/examples/103_01_02.html +0 -247
  56. data/spec/examples/codes_table.html +0 -3174
  57. data/spec/examples/datamodel/address_class_profile.adoc +0 -5
  58. data/spec/examples/datamodel/address_class_profile.presentation.xml +0 -14
  59. data/spec/examples/datamodel/address_component_profile.adoc +0 -5
  60. data/spec/examples/datamodel/blank_definition_profile.adoc +0 -5
  61. data/spec/examples/datamodel/common_models_diagram.adoc +0 -5
  62. data/spec/examples/datamodel/models/models/AddressClassProfile.yml +0 -90
  63. data/spec/examples/datamodel/models/models/AddressComponentProfile.yml +0 -63
  64. data/spec/examples/datamodel/models/models/AddressComponentSpecification.yml +0 -15
  65. data/spec/examples/datamodel/models/models/AddressProfile.yml +0 -36
  66. data/spec/examples/datamodel/models/models/AttributeProfile.yml +0 -32
  67. data/spec/examples/datamodel/models/models/InterchangeAddressClassProfile.yml +0 -79
  68. data/spec/examples/datamodel/models/models/Localization copy.yml +0 -23
  69. data/spec/examples/datamodel/models/models/Localization.yml +0 -23
  70. data/spec/examples/datamodel/models/models/ProfileCompliantAddress.yml +0 -36
  71. data/spec/examples/datamodel/models/models/ProfileCompliantAddressComponent.yml +0 -15
  72. data/spec/examples/datamodel/models/models/Signature.yml +0 -20
  73. data/spec/examples/datamodel/models/models/SignatureBlankDefinition.yml +0 -20
  74. data/spec/examples/datamodel/models/models/TextDirectionCode copy.yml +0 -16
  75. data/spec/examples/datamodel/models/models/TextDirectionCode.yml +0 -16
  76. data/spec/examples/datamodel/models/models/Validity.yml +0 -14
  77. data/spec/examples/datamodel/models/models/iso19160-1/Address.yml +0 -22
  78. data/spec/examples/datamodel/models/models/iso19160-1/AddressComponent.yml +0 -2
  79. data/spec/examples/datamodel/models/style.uml.inc +0 -37
  80. data/spec/examples/datamodel/models/views/CommonModels.yml +0 -9
  81. data/spec/examples/datamodel/models/views/TopDown.yml +0 -62
  82. data/spec/examples/datamodel/top_down_diagram.adoc +0 -5
  83. data/spec/examples/english.yaml +0 -69
  84. data/spec/examples/iso_123_.xml +0 -46
  85. data/spec/examples/iso_123_all_parts.xml +0 -46
  86. data/spec/examples/iso_123_no_year_note.xml +0 -47
  87. data/spec/examples/iso_124_.xml +0 -42
  88. data/spec/examples/iso_216_.xml +0 -48
  89. data/spec/examples/iso_iec_12382_.xml +0 -49
  90. data/spec/examples/rice.adoc +0 -715
  91. data/spec/examples/rice.preview.html +0 -1877
  92. data/spec/examples/rice.sh +0 -4
  93. data/spec/examples/rice_images/rice_image1.png +0 -0
  94. data/spec/examples/rice_images/rice_image2.png +0 -0
  95. data/spec/examples/rice_images/rice_image3_1.png +0 -0
  96. data/spec/examples/rice_images/rice_image3_2.png +0 -0
  97. data/spec/examples/rice_images/rice_image3_3.png +0 -0
  98. data/spec/fixtures/action_schemaexpg1.svg +0 -122
  99. data/spec/fixtures/datamodel_description_sections_tree.xml +0 -327
  100. data/spec/fixtures/diagram_definitions.lutaml +0 -22
  101. data/spec/fixtures/macros_datamodel/address_class_profile.xml +0 -149
  102. data/spec/fixtures/macros_datamodel/address_component_profile.xml +0 -71
  103. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +0 -51
  104. data/spec/fixtures/macros_datamodel/common_models_diagram.xml +0 -7
  105. data/spec/fixtures/macros_datamodel/top_down_diagram.xml +0 -7
  106. data/spec/fixtures/test.exp +0 -121
  107. data/spec/fixtures/test.xmi +0 -9250
  108. data/spec/metanorma/base_spec.rb +0 -1125
  109. data/spec/metanorma/biblio_spec.rb +0 -1012
  110. data/spec/metanorma/blank_spec.rb +0 -37
  111. data/spec/metanorma/blocks_spec.rb +0 -1784
  112. data/spec/metanorma/cleanup_blocks_spec.rb +0 -1099
  113. data/spec/metanorma/cleanup_sections_spec.rb +0 -1849
  114. data/spec/metanorma/cleanup_spec.rb +0 -1931
  115. data/spec/metanorma/cleanup_terms_spec.rb +0 -1543
  116. data/spec/metanorma/datamodel/attributes_table_preprocessor_spec.rb +0 -111
  117. data/spec/metanorma/datamodel/diagram_preprocessor_spec.rb +0 -72
  118. data/spec/metanorma/inline_spec.rb +0 -785
  119. data/spec/metanorma/isobib_cache_spec.rb +0 -742
  120. data/spec/metanorma/lists_spec.rb +0 -232
  121. data/spec/metanorma/macros_concept_spec.rb +0 -1052
  122. data/spec/metanorma/macros_json2text_spec.rb +0 -10
  123. data/spec/metanorma/macros_plantuml_spec.rb +0 -402
  124. data/spec/metanorma/macros_spec.rb +0 -1183
  125. data/spec/metanorma/macros_yaml2text_spec.rb +0 -10
  126. data/spec/metanorma/processor_spec.rb +0 -96
  127. data/spec/metanorma/refs_spec.rb +0 -2807
  128. data/spec/metanorma/reqt_spec.rb +0 -130
  129. data/spec/metanorma/section_spec.rb +0 -1325
  130. data/spec/metanorma/table_spec.rb +0 -474
  131. data/spec/metanorma/validate_spec.rb +0 -886
  132. data/spec/spec_helper.rb +0 -290
  133. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +0 -781
  134. data/spec/vcr_cassettes/bsi16341.yml +0 -486
  135. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +0 -611
  136. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +0 -149
  137. data/spec/vcr_cassettes/hide_refs.yml +0 -587
  138. data/spec/vcr_cassettes/isobib_get_123.yml +0 -149
  139. data/spec/vcr_cassettes/isobib_get_123_1.yml +0 -295
  140. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +0 -385
  141. data/spec/vcr_cassettes/isobib_get_123_2.yml +0 -295
  142. data/spec/vcr_cassettes/isobib_get_123_2001.yml +0 -149
  143. data/spec/vcr_cassettes/isobib_get_124.yml +0 -149
  144. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +0 -367
  145. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +0 -560
  146. data/spec/vcr_cassettes/std-link.yml +0 -149
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '033585c8aaadb0c5672e328edd9c30012ee330cb800cbf8a7f4e2a7e5498a61e'
4
- data.tar.gz: 07b1cba33ba7917f68429d91393c8795d787c63e06f60d3f8d00938088e13138
3
+ metadata.gz: c59c6e517b305ec3559d4948767575ba032d877714800712e883bc2a0a561e6b
4
+ data.tar.gz: eeb0aaf07ac2ea303921b2ed855981b834f9fb8de4e06b708611852fb7465123
5
5
  SHA512:
6
- metadata.gz: d163281f43172f6c1be2391bb923245f58270efd2f1eb482412b08e41ebdfeed91f6edeb4df61e4e5056feba0fd7c17b673b8d8d324f9837f93ac310052eda73
7
- data.tar.gz: 1a8dbeadcc05872bf5daadebf262204461e75f9e39ffd9a0d2b77ebaec68131cd04786cb22a8adfaccfdaf3cad3db3019a51a85b18d8be1a8d363381c7618045
6
+ metadata.gz: 7a91ae88a07c545c1c03f0845d94f38db34cc1128d7c7274eb49cbd2dd509ea8ca02da007e1de78b0d91d773c7eec6798206613eacda9e6322ebc3b0ab67f37b
7
+ data.tar.gz: 58af55addb78a590e2389dbce06cc29977bda866924c80e042047b85877f9374407dfb5f2b1679b8766bfd12ed0ce9e4fa7a339b88d333099666e5b169afcf09
@@ -41,6 +41,7 @@ module Metanorma
41
41
  def init_vars
42
42
  @fn_number ||= 0
43
43
  @refids = Set.new
44
+ @anchor_alias = {}
44
45
  @anchors = {}
45
46
  @internal_eref_namespaces = []
46
47
  @seen_headers = []
@@ -130,9 +131,7 @@ module Metanorma
130
131
 
131
132
  def document1(node)
132
133
  init(node)
133
- ret = makexml(node)
134
- .to_xml(encoding: "UTF-8", indent: 2,
135
- save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
134
+ ret = to_xml(makexml(node))
136
135
  outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
137
136
  ret
138
137
  end
@@ -163,8 +162,7 @@ module Metanorma
163
162
 
164
163
  def clean_abort(msg, file = nil)
165
164
  if file
166
- doc = file.to_xml(encoding: "UTF-8", indent: 2,
167
- save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
165
+ doc = to_xml(file)
168
166
  File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(doc) }
169
167
  end
170
168
  clean_exit
@@ -188,6 +188,11 @@
188
188
  <value>adapter</value>
189
189
  <value>translator</value>
190
190
  <value>distributor</value>
191
+ <value>realizer</value>
192
+ <value>owner</value>
193
+ <value>authorizer</value>
194
+ <value>enabler</value>
195
+ <value>subject</value>
191
196
  </choice>
192
197
  </attribute>
193
198
  <zeroOrMore>
@@ -27,31 +27,33 @@ module Metanorma
27
27
  def cleanup(xmldoc)
28
28
  element_name_cleanup(xmldoc)
29
29
  passthrough_cleanup(xmldoc)
30
- sections_cleanup(xmldoc)
30
+ sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup
31
31
  obligations_cleanup(xmldoc)
32
32
  para_index_cleanup(xmldoc)
33
33
  block_index_cleanup(xmldoc)
34
34
  table_cleanup(xmldoc)
35
35
  formula_cleanup(xmldoc)
36
36
  form_cleanup(xmldoc)
37
- sourcecode_cleanup(xmldoc)
37
+ sourcecode_cleanup(xmldoc) # feeds: callout_cleanup
38
38
  figure_cleanup(xmldoc)
39
+ requirement_cleanup(xmldoc) # feeds: xref_cleanup
39
40
  element_name_cleanup(xmldoc)
40
- ref_cleanup(xmldoc)
41
+ ref_cleanup(xmldoc) # feeds: bibitem_cleanup
41
42
  note_cleanup(xmldoc)
42
43
  clausebefore_cleanup(xmldoc)
43
44
  floatingtitle_cleanup(xmldoc)
44
- bibitem_cleanup(xmldoc)
45
+ bibitem_cleanup(xmldoc) # feeds: normref_cleanup, biblio_cleanup,
46
+ # reference_names, bpart_cleanup
45
47
  normref_cleanup(xmldoc)
46
48
  biblio_cleanup(xmldoc)
47
49
  reference_names(xmldoc)
48
- symbols_cleanup(xmldoc)
49
- xref_cleanup(xmldoc)
50
- concept_cleanup(xmldoc)
51
- related_cleanup(xmldoc)
52
- origin_cleanup(xmldoc)
50
+ symbols_cleanup(xmldoc) # feeds: termdef_cleanup
51
+ xref_cleanup(xmldoc) # feeds: concept_cleanup, origin_cleanup
52
+ concept_cleanup(xmldoc) # feeds: related_cleanup, termdef_cleanup
53
+ related_cleanup(xmldoc) # feeds: termdef_cleanup
54
+ origin_cleanup(xmldoc) # feeds: termdef_cleanup
53
55
  bookmark_cleanup(xmldoc)
54
- termdef_cleanup(xmldoc)
56
+ termdef_cleanup(xmldoc) # feeds: iev_cleanup, term_index_cleanup
55
57
  RelatonIev::iev_cleanup(xmldoc, @bibdb)
56
58
  element_name_cleanup(xmldoc)
57
59
  term_index_cleanup(xmldoc)
@@ -61,10 +63,9 @@ module Metanorma
61
63
  footnote_cleanup(xmldoc)
62
64
  mathml_cleanup(xmldoc)
63
65
  script_cleanup(xmldoc)
64
- docidentifier_cleanup(xmldoc)
65
- requirement_cleanup(xmldoc)
66
+ docidentifier_cleanup(xmldoc) # feeds: bibdata_cleanup
66
67
  bibdata_cleanup(xmldoc)
67
- svgmap_cleanup(xmldoc)
68
+ svgmap_cleanup(xmldoc) # feeds: img_cleanup
68
69
  boilerplate_cleanup(xmldoc)
69
70
  toc_cleanup(xmldoc)
70
71
  metadata_cleanup(xmldoc)
@@ -128,8 +129,8 @@ module Metanorma
128
129
 
129
130
  def variant_cleanup1(elem)
130
131
  elem.xpath("./variant").each do |n|
131
- if n.at_xpath("preceding-sibling::node()"\
132
- "[not(self::text()[not(normalize-space())])][1]"\
132
+ if n.at_xpath("preceding-sibling::node()" \
133
+ "[not(self::text()[not(normalize-space())])][1]" \
133
134
  "[self::variantwrap]")
134
135
  n.previous_element << n
135
136
  else
@@ -152,8 +153,7 @@ module Metanorma
152
153
  def metadata_cleanup(xmldoc)
153
154
  return if @metadata_attrs.nil? || @metadata_attrs.empty?
154
155
 
155
- ins = xmldoc.at("//misc-container") ||
156
- xmldoc.at("//bibdata").after("<misc-container/>").next_element
156
+ ins = add_misc_container(xmldoc)
157
157
  ins << @metadata_attrs
158
158
  end
159
159
  end
@@ -31,8 +31,8 @@ module Metanorma
31
31
  amend.children = "<description>#{amend.children.to_xml}</description>"
32
32
  return
33
33
  end
34
- pre = q&.xpath("./preceding-sibling::*")&.remove
35
- post = q&.xpath("./following-sibling::*")&.remove
34
+ pre = q.xpath("./preceding-sibling::*")&.remove
35
+ post = q.xpath("./following-sibling::*")&.remove
36
36
  pre.empty? or amend << "<description>#{pre.to_xml}</description>"
37
37
  amend << q.remove
38
38
  post.empty? or amend << "<description>#{post.to_xml}</description>"
@@ -49,7 +49,8 @@ module Metanorma
49
49
  def span_preprocess1(span, ret)
50
50
  case span[:key]
51
51
  when "uri", "docid"
52
- ret[span[:key].to_sym] << { type: span[:type], val: span[:val] }
52
+ val = link_unwrap(Nokogiri::XML.fragment(span[:val])).to_xml
53
+ ret[span[:key].to_sym] << { type: span[:type], val: val }
53
54
  when "date"
54
55
  ret[span[:key].to_sym] << { type: span[:type] || "published",
55
56
  val: span[:val] }
@@ -8,16 +8,24 @@ module Metanorma
8
8
  "<amathstem>#{@c.decode($1)}</amathstem>"
9
9
  end
10
10
  text = Html2Doc.new({})
11
- .asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
12
- x = Nokogiri::XML(text)
11
+ .asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"],
12
+ retain_asciimath: true)
13
+ asciimath2mathml_wrap(text)
14
+ end
15
+
16
+ def asciimath2mathml_wrap(text)
17
+ x = Nokogiri::XML(text)
13
18
  x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
14
19
  y.wrap("<stem type='MathML'></stem>")
15
20
  end
16
- x.to_xml
21
+ x.xpath("//stem").each do |y|
22
+ y.next_element&.name == "asciimath" and y << y.next_element
23
+ end
24
+ to_xml(x)
17
25
  end
18
26
 
19
27
  def xml_unescape_mathml(xml)
20
- return if xml.children.any? { |y| y.element? }
28
+ return if xml.children.any?(&:element?)
21
29
 
22
30
  math = xml.text.gsub(/&lt;/, "<").gsub(/&gt;/, ">")
23
31
  .gsub(/&quot;/, '"').gsub(/&apos;/, "'").gsub(/&amp;/, "&")
@@ -8,7 +8,7 @@ module Metanorma
8
8
  module Standoc
9
9
  module Cleanup
10
10
  def make_preface(xml, sect)
11
- if xml.at("//foreword | //introduction | //acknowledgements | "\
11
+ if xml.at("//foreword | //introduction | //acknowledgements | " \
12
12
  "//*[@preface]")
13
13
  preface = sect.add_previous_sibling("<preface/>").first
14
14
  f = xml.at("//foreword") and preface.add_child f.remove
@@ -33,21 +33,24 @@ module Metanorma
33
33
  abstract = xml.at("//abstract[not(ancestor::bibitem)]").remove
34
34
  preface.prepend_child abstract.remove
35
35
  bibabstract = bibabstract_location(xml)
36
- dupabstract = abstract.dup
37
- dupabstract.traverse { |n| n.remove_attribute("id") }
38
- dupabstract.remove_attribute("language")
39
- dupabstract.remove_attribute("script")
40
- dupabstract&.at("./title")&.remove
41
- bibabstract.next = dupabstract
36
+ bibabstract.next = clean_abstract(abstract.dup)
42
37
  end
43
38
  end
44
39
 
40
+ def clean_abstract(dupabstract)
41
+ dupabstract.traverse { |n| n.remove_attribute("id") }
42
+ dupabstract.remove_attribute("language")
43
+ dupabstract.remove_attribute("script")
44
+ dupabstract.at("./title")&.remove
45
+ dupabstract
46
+ end
47
+
45
48
  def bibabstract_location(xml)
46
49
  xml.at("//bibdata/script") || xml.at("//bibdata/language") ||
47
50
  xml.at("//bibdata/contributor[not(following-sibling::contributor)]") ||
48
51
  xml.at("//bibdata/date[not(following-sibling::date)]") ||
49
52
  xml.at("//docnumber") ||
50
- xml.at("//bibdata/docidentifier"\
53
+ xml.at("//bibdata/docidentifier" \
51
54
  "[not(following-sibling::docidentifier)]") ||
52
55
  xml.at("//bibdata/uri[not(following-sibling::uri)]") ||
53
56
  xml.at("//bibdata/title[not(following-sibling::title)]")
@@ -111,6 +114,7 @@ module Metanorma
111
114
  end
112
115
 
113
116
  def sections_cleanup(xml)
117
+ misccontainer_cleanup(xml)
114
118
  sections_order_cleanup(xml)
115
119
  sections_level_cleanup(xml)
116
120
  sections_names_cleanup(xml)
@@ -118,6 +122,12 @@ module Metanorma
118
122
  change_clauses(xml)
119
123
  end
120
124
 
125
+ def misccontainer_cleanup(xml)
126
+ m = xml.at("//misc-container-clause") or return
127
+ ins = add_misc_container(xml)
128
+ ins << m.remove.children
129
+ end
130
+
121
131
  def single_clause_annex(xml)
122
132
  xml.xpath("//annex").each do |a|
123
133
  single_clause_annex1(a)
@@ -131,7 +141,7 @@ module Metanorma
131
141
  end
132
142
 
133
143
  def obligations_cleanup_info(xml)
134
- xml.xpath("//foreword | //introduction | //acknowledgements | "\
144
+ xml.xpath("//foreword | //introduction | //acknowledgements | " \
135
145
  "//references | //preface//clause").each do |r|
136
146
  r["obligation"] = "informative"
137
147
  end
@@ -5,18 +5,25 @@ module Metanorma
5
5
  # letter (x, x_m, x_1, xa); we use colon to force that sort order.
6
6
  # Numbers sort *after* letters; we use thorn to force that sort order.
7
7
  def symbol_key(sym)
8
- key = sym.dup
9
- key.traverse do |n|
10
- n.name == "math" and
11
- n.replace(grkletters(MathML2AsciiMath.m2a(n.to_xml)))
12
- end
13
- ret = Nokogiri::XML(key.to_xml)
14
- @c.decode(ret.text.downcase)
8
+ @c.decode(asciimath_key(sym).text.downcase)
15
9
  .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
16
10
  .gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
17
11
  .gsub(/[0-9]+/, "þ\\0")
18
12
  end
19
13
 
14
+ def asciimath_key(sym)
15
+ key = sym.dup
16
+ key.traverse do |n|
17
+ if n.name == "math"
18
+ n.children = @c.encode(
19
+ @c.decode(grkletters(MathML2AsciiMath.m2a(n.to_xml))), :basic
20
+ )
21
+ end
22
+ end
23
+ key.xpath(".//asciimath").each(&:remove)
24
+ Nokogiri::XML(key.to_xml)
25
+ end
26
+
20
27
  def grkletters(text)
21
28
  text.gsub(/\b(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|
22
29
  lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|
@@ -35,7 +35,8 @@ module Metanorma
35
35
  end
36
36
 
37
37
  IGNORE_QUOTES_ELEMENTS =
38
- %w(pre tt sourcecode stem figure bibdata passthrough identifier).freeze
38
+ %w(pre tt sourcecode stem asciimath figure bibdata passthrough
39
+ identifier).freeze
39
40
 
40
41
  def uninterrupt_quotes_around_xml_skip(elem)
41
42
  !(/\A['"]/.match?(elem.text) &&
@@ -100,9 +101,14 @@ module Metanorma
100
101
 
101
102
  def dumbquote_cleanup(xmldoc)
102
103
  xmldoc.traverse do |n|
103
- next unless n.text?
104
-
105
- n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
104
+ next unless n.text? && /\u2019/.match?(n.text)
105
+
106
+ # n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
107
+ n.replace(@c.encode(
108
+ @c.decode(n.text)
109
+ .gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"),
110
+ :basic, :hexadecimal
111
+ ))
106
112
  end
107
113
  end
108
114
  end
@@ -80,8 +80,7 @@ module Metanorma
80
80
  def toc_metadata(xmldoc)
81
81
  return unless @htmltoclevels || @doctoclevels || @toclevels
82
82
 
83
- ins = xmldoc.at("//misc-container") ||
84
- xmldoc.at("//bibdata").after("<misc-container/>").next_element
83
+ ins = add_misc_container(xmldoc)
85
84
  toc_metadata1(ins)
86
85
  end
87
86
 
@@ -20,10 +20,10 @@ module Metanorma
20
20
  end
21
21
 
22
22
  def extract_localities(elem)
23
- f = elem&.children&.first or return
23
+ f = elem.children&.first or return
24
24
  f.text? or return
25
25
  head = f.remove.text
26
- tail = elem&.children&.remove
26
+ tail = elem.children&.remove
27
27
  extract_localities1(elem, head)
28
28
  tail and elem << tail
29
29
  end
@@ -45,7 +45,7 @@ module Metanorma
45
45
  ref =
46
46
  match[:ref] ? "<referenceFrom>#{tq match[:ref]}</referenceFrom>" : ""
47
47
  refto = match[:to] ? "<referenceTo>#{tq match[:to]}</referenceTo>" : ""
48
- stack.add_child("<locality type='#{locality_label(match)}'>#{ref}"\
48
+ stack.add_child("<locality type='#{locality_label(match)}'>#{ref}" \
49
49
  "#{refto}</locality>")
50
50
  end
51
51
 
@@ -67,7 +67,8 @@ module Metanorma
67
67
  /^locality:/.match?(loc) ? loc : loc&.downcase
68
68
  end
69
69
 
70
- def xref_to_eref(elem)
70
+ def xref_to_eref(elem, name)
71
+ elem.name = name
71
72
  elem["bibitemid"] = elem["target"]
72
73
  if ref = @anchors&.dig(elem["target"], :xref)
73
74
  elem["citeas"] = @c.decode(ref)
@@ -82,14 +83,49 @@ module Metanorma
82
83
  def xref_to_eref1(elem)
83
84
  @internal_eref_namespaces.include?(elem["type"]) or
84
85
  @log.add("Crossreferences", elem,
85
- "#{elem['target']} does not have a corresponding "\
86
+ "#{elem['target']} does not have a corresponding " \
86
87
  "anchor ID in the bibliography!")
87
88
  end
88
89
 
89
90
  def xref_cleanup(xmldoc)
91
+ anchor_alias(xmldoc)
90
92
  xref_compound_cleanup(xmldoc)
91
93
  xref_cleanup1(xmldoc)
92
94
  xref_compound_wrapup(xmldoc)
95
+ eref_stack(xmldoc)
96
+ end
97
+
98
+ def eref_stack(xmldoc)
99
+ xmldoc.xpath("//eref[eref]").each do |e|
100
+ e.name = "erefstack"
101
+ e.delete("bibitemid")
102
+ e.delete("citeas")
103
+ e.xpath("./eref").each do |e1|
104
+ e1["type"] = e["type"]
105
+ end
106
+ e.delete("type")
107
+ end
108
+ end
109
+
110
+ def anchor_alias(xmldoc)
111
+ t = xmldoc.at("//misc-container/table[@id = " \
112
+ "'_misccontainer_anchor_aliases']") or return
113
+ key = ""
114
+ t.xpath("./tbody/tr").each do |tr|
115
+ tr.xpath("./td | ./th").each_with_index do |td, i|
116
+ if i.zero? then key = td.text
117
+ else anchor_alias1(key, td)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ def anchor_alias1(key, elem)
124
+ id = elem.text.strip
125
+ id.empty? and elem.at("./link") and
126
+ id = elem.at("./link/@target")&.text
127
+ (key && !id.empty?) or return
128
+ @anchor_alias[id] = key
93
129
  end
94
130
 
95
131
  def xref_compound_cleanup(xmldoc)
@@ -128,12 +164,12 @@ module Metanorma
128
164
 
129
165
  def xref_cleanup1(xmldoc)
130
166
  xmldoc.xpath("//xref").each do |x|
131
- /:/.match?(x["target"]) and xref_to_internal_eref(x)
167
+ %r{:(?!//)}.match?(x["target"]) and xref_to_internal_eref(x)
132
168
  next unless x.name == "xref"
133
169
 
134
170
  if refid? x["target"]
135
- x.name = "eref"
136
- xref_to_eref(x)
171
+ xref_to_eref(x, "eref")
172
+ elsif @anchor_alias[x["target"]] then xref_alias(x)
137
173
  else x.delete("type")
138
174
  end
139
175
  end
@@ -144,17 +180,22 @@ module Metanorma
144
180
  unless a.size < 2 || a[0].empty? || a[1].empty?
145
181
  elem["target"] = "#{a[0]}_#{a[1]}"
146
182
  a.size > 2 and
147
- elem.children = %{anchor="#{a[2..-1].join}",#{elem&.children&.text}}
183
+ elem.children = %{anchor="#{a[2..-1].join}",#{elem.children&.text}}
148
184
  elem["type"] = a[0]
149
185
  @internal_eref_namespaces << a[0]
150
- elem.name = "eref"
151
- xref_to_eref(elem)
186
+ xref_to_eref(elem, "eref")
152
187
  end
153
188
  end
154
189
 
190
+ def xref_alias(elem)
191
+ elem["style"] == "id" && elem.text.strip.empty? and
192
+ elem << elem["target"]
193
+ elem["target"] = @anchor_alias[elem["target"]]
194
+ end
195
+
155
196
  def quotesource_cleanup(xmldoc)
156
197
  xmldoc.xpath("//quote/source | //terms/source").each do |x|
157
- xref_to_eref(x)
198
+ xref_to_eref(x, "source")
158
199
  end
159
200
  end
160
201
 
@@ -165,9 +206,9 @@ module Metanorma
165
206
  xmldoc.xpath("//origin").each do |x|
166
207
  x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) or
167
208
  @log.add("Crossreferences", x,
168
- "#{x['bibitemid']} does not have a corresponding anchor "\
209
+ "#{x['bibitemid']} does not have a corresponding anchor " \
169
210
  "ID in the bibliography!")
170
- extract_localities(x) unless x.children.empty?
211
+ x.children.empty? or extract_localities(x)
171
212
  end
172
213
  end
173
214
  end
@@ -40,30 +40,44 @@ module Metanorma
40
40
  end
41
41
 
42
42
  def inline_anchor_xref_attrs(node)
43
- m = inline_anchor_xref_match(node)
43
+ text = concatenate_attributes_to_xref_text(node)
44
+ m = inline_anchor_xref_match(text)
44
45
  t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
45
- m.nil? and return { target: t, type: "inline", text: node.text }
46
- { target: t, type: m[:fn].nil? ? "inline" : "footnote",
47
- case: m[:case]&.sub(/%$/, ""),
48
- style: m[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle,
49
- droploc: m[:drop].nil? && m[:drop2].nil? ? nil : true,
50
- text: inline_anchor_xref_text(m, node),
51
- hidden: m[:hidden] }
46
+ m.nil? and return { target: t, type: "inline", text: text }
47
+ inline_anchor_xref_attrs1(m, t, text)
52
48
  end
53
49
 
54
- def inline_anchor_xref_match(node)
50
+ def concatenate_attributes_to_xref_text(node)
51
+ node.attributes.each_with_object([]) do |(k, v), m|
52
+ next if %w(path fragment refid).include?(k)
53
+
54
+ m << "#{k}=#{v}%"
55
+ end.map { |x| x.sub(/%+/, "%") }.join + (node.text || "")
56
+ end
57
+
58
+ def inline_anchor_xref_attrs1(match, target, text)
59
+ { target: target,
60
+ type: match[:fn].nil? ? "inline" : "footnote",
61
+ case: match[:case]&.sub(/%$/, ""),
62
+ style: match[:style]&.sub(/^style=/, "")&.sub(/%$/, "") || @xrefstyle,
63
+ droploc: match[:drop].nil? && match[:drop2].nil? ? nil : true,
64
+ text: inline_anchor_xref_text(match, text),
65
+ hidden: match[:hidden] }
66
+ end
67
+
68
+ def inline_anchor_xref_match(text)
55
69
  /^(?:hidden%(?<hidden>[^,]+),?)?
56
70
  (?<style>style=[^%]+%)?
57
71
  (?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
58
- (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
72
+ (?<fn>fn:?\s*)?(?<text>.*)$/x.match text
59
73
  end
60
74
 
61
- def inline_anchor_xref_text(match, node)
75
+ def inline_anchor_xref_text(match, text)
62
76
  if %i[case fn drop drop2 hidden style].any? do |x|
63
77
  !match[x].nil?
64
78
  end
65
79
  match[:text]
66
- else node.text
80
+ else text
67
81
  end
68
82
  end
69
83
 
@@ -160,6 +174,7 @@ module Metanorma
160
174
  .elements[0]
161
175
  math.delete("alttext")
162
176
  s.parent.children = math
177
+ s << "<latexmath>#{text}</latexmath>"
163
178
  end
164
179
  end
165
180