metanorma-standoc 2.0.1 → 2.0.4

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/standoc/base.rb +61 -22
  3. data/lib/metanorma/standoc/basicdoc.rng +5 -3
  4. data/lib/metanorma/standoc/biblio.rng +7 -5
  5. data/lib/metanorma/standoc/blocks.rb +3 -3
  6. data/lib/metanorma/standoc/cleanup_boilerplate.rb +3 -3
  7. data/lib/metanorma/standoc/cleanup_image.rb +117 -3
  8. data/lib/metanorma/standoc/cleanup_ref.rb +32 -3
  9. data/lib/metanorma/standoc/cleanup_ref_dl.rb +20 -16
  10. data/lib/metanorma/standoc/cleanup_section.rb +2 -2
  11. data/lib/metanorma/standoc/cleanup_terms_designations.rb +4 -2
  12. data/lib/metanorma/standoc/cleanup_text.rb +0 -22
  13. data/lib/metanorma/standoc/cleanup_xref.rb +82 -13
  14. data/lib/metanorma/standoc/converter.rb +2 -0
  15. data/lib/metanorma/standoc/inline.rb +21 -12
  16. data/lib/metanorma/standoc/isodoc.rng +142 -4
  17. data/lib/metanorma/standoc/macros.rb +14 -1
  18. data/lib/metanorma/standoc/macros_embed.rb +72 -0
  19. data/lib/metanorma/standoc/ref.rb +11 -7
  20. data/lib/metanorma/standoc/ref_utility.rb +2 -1
  21. data/lib/metanorma/standoc/render.rb +7 -3
  22. data/lib/metanorma/standoc/table.rb +8 -10
  23. data/lib/metanorma/standoc/term_lookup_cleanup.rb +9 -6
  24. data/lib/metanorma/standoc/terms.rb +10 -7
  25. data/lib/metanorma/standoc/utils.rb +3 -1
  26. data/lib/metanorma/standoc/validate.rb +7 -2
  27. data/lib/metanorma/standoc/version.rb +1 -1
  28. data/spec/assets/a1.adoc +8 -0
  29. data/spec/assets/a2.adoc +8 -0
  30. data/spec/assets/a3.adoc +9 -0
  31. data/spec/assets/a4.adoc +4 -0
  32. data/spec/metanorma/base_spec.rb +1 -1
  33. data/spec/metanorma/cleanup_blocks_spec.rb +136 -0
  34. data/spec/metanorma/cleanup_spec.rb +13 -13
  35. data/spec/metanorma/cleanup_terms_spec.rb +1 -1
  36. data/spec/metanorma/inline_spec.rb +31 -0
  37. data/spec/metanorma/isobib_cache_spec.rb +2 -2
  38. data/spec/metanorma/macros_plantuml_spec.rb +41 -42
  39. data/spec/metanorma/macros_spec.rb +288 -2
  40. data/spec/metanorma/processor_spec.rb +17 -13
  41. data/spec/metanorma/refs_spec.rb +633 -461
  42. data/spec/metanorma/section_spec.rb +1 -1
  43. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
  44. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +13 -13
  45. data/spec/vcr_cassettes/hide_refs.yml +100 -100
  46. data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
  47. data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
  48. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
  49. data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
  50. data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
  51. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
  52. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +86 -66
  53. metadata +7 -2
@@ -3,11 +3,12 @@ module Metanorma
3
3
  module Cleanup
4
4
  # extending localities to cover ISO referencing
5
5
  LOCALITY_REGEX_STR = <<~REGEXP.freeze
6
- ^((?<locality>section|clause|part|paragraph|chapter|page|
6
+ ^(((?<conn>and|or|from|to)!)?
7
+ (?<locality>section|clause|part|paragraph|chapter|page|
7
8
  table|annex|figure|example|note|formula|list|time|anchor|
8
9
  locality:[^ \\t\\n\\r:,;=]+)(\\s+|=)
9
- (?<ref>[^"][^ \\t\\n,:-]*|"[^"]+")
10
- (-(?<to>[^"][^ \\t\\n,:-]*|"[^"]"))?|
10
+ (?<ref>[^"][^ \\t\\n,:;-]*|"[^"]+")
11
+ (-(?<to>[^"][^ \\t\\n,:;-]*|"[^"]"))?|
11
12
  (?<locality2>whole|locality:[^ \\t\\n\\r:,;=]+))(?<punct>[,:;]?)\\s*
12
13
  (?<text>.*)$
13
14
  REGEXP
@@ -30,16 +31,37 @@ module Metanorma
30
31
  def extract_localities1(elem, text)
31
32
  b = elem.add_child("<localityStack/>").first if LOCALITY_RE.match text
32
33
  while (m = LOCALITY_RE.match text)
33
- ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
34
- refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
35
- b.add_child("<locality type='#{locality_label(m)}'>#{ref}#{refto}"\
36
- "</locality>")
34
+ add_locality(b, m)
37
35
  text = m[:text]
38
36
  b = elem.add_child("<localityStack/>").first if m[:punct] == ";"
39
37
  end
38
+ fill_in_eref_connectives(elem)
40
39
  elem.add_child(text) if text
41
40
  end
42
41
 
42
+ def add_locality(stack, match)
43
+ stack.children.empty? && match[:conn] and
44
+ stack["connective"] = match[:conn]
45
+ ref =
46
+ match[:ref] ? "<referenceFrom>#{tq match[:ref]}</referenceFrom>" : ""
47
+ refto = match[:to] ? "<referenceTo>#{tq match[:to]}</referenceTo>" : ""
48
+ stack.add_child("<locality type='#{locality_label(match)}'>#{ref}"\
49
+ "#{refto}</locality>")
50
+ end
51
+
52
+ def fill_in_eref_connectives(elem)
53
+ return if elem.xpath("./localityStack").size < 2
54
+
55
+ elem.xpath("./localityStack[not(@connective)]").each do |l|
56
+ n = l.next_element
57
+ l["connective"] = if n && n.name == "localityStack" &&
58
+ n["connective"] == "to"
59
+ "from"
60
+ else "and"
61
+ end
62
+ end
63
+ end
64
+
43
65
  def locality_label(match)
44
66
  loc = match[:locality] || match[:locality2]
45
67
  /^locality:/.match?(loc) ? loc : loc&.downcase
@@ -47,19 +69,66 @@ module Metanorma
47
69
 
48
70
  def xref_to_eref(elem)
49
71
  elem["bibitemid"] = elem["target"]
50
- unless elem["citeas"] = @anchors&.dig(elem["target"], :xref)
51
- @internal_eref_namespaces.include?(elem["type"]) or
52
- @log.add("Crossreferences", elem,
53
- "#{elem['target']} does not have a corresponding "\
54
- "anchor ID in the bibliography!")
72
+ if ref = @anchors&.dig(elem["target"], :xref)
73
+ elem["citeas"] = HTMLEntities.new.encode(ref, :hexadecimal)
74
+ else
75
+ elem["citeas"] = ""
76
+ xref_to_eref1(elem)
55
77
  end
56
78
  elem.delete("target")
57
79
  extract_localities(elem) unless elem.children.empty?
58
80
  end
59
81
 
82
+ def xref_to_eref1(elem)
83
+ @internal_eref_namespaces.include?(elem["type"]) or
84
+ @log.add("Crossreferences", elem,
85
+ "#{elem['target']} does not have a corresponding "\
86
+ "anchor ID in the bibliography!")
87
+ end
88
+
60
89
  def xref_cleanup(xmldoc)
90
+ xref_compound_cleanup(xmldoc)
91
+ xref_cleanup1(xmldoc)
92
+ xref_compound_wrapup(xmldoc)
93
+ end
94
+
95
+ def xref_compound_cleanup(xmldoc)
96
+ xmldoc.xpath("//xref").each do |x|
97
+ /;/.match?(x["target"]) or next
98
+ locations = x["target"].split(";")
99
+ x["target"] = locations.first.sub(/^[^!]*!/, "")
100
+ xref_compound_cleanup1(x, locations)
101
+ end
102
+ end
103
+
104
+ def xref_compound_cleanup1(xref, locations)
105
+ xref.children.empty? and xref.children = "<sentinel/>"
106
+ xref_parse_compound_locations(locations).reverse.each do |y|
107
+ xref.children.first.previous =
108
+ "<xref target='#{y[1]}' connective='#{y[0]}'/>"
109
+ end
110
+ xref&.at("./sentinel")&.remove
111
+ end
112
+
113
+ def xref_parse_compound_locations(locations)
114
+ l = locations.map { |y| y.split("!", 2) }
115
+ l.map.with_index do |y, i|
116
+ if y.size == 1
117
+ y.unshift(l.dig(i + 1, 0) == "to" ? "from" : "and")
118
+ end
119
+ y
120
+ end
121
+ end
122
+
123
+ def xref_compound_wrapup(xmldoc)
124
+ xmldoc.xpath("//xref//xref").each do |x|
125
+ x.name = "location"
126
+ end
127
+ end
128
+
129
+ def xref_cleanup1(xmldoc)
61
130
  xmldoc.xpath("//xref").each do |x|
62
- /:/.match(x["target"]) and xref_to_internal_eref(x)
131
+ /:/.match?(x["target"]) and xref_to_internal_eref(x)
63
132
  next unless x.name == "xref"
64
133
 
65
134
  if refid? x["target"]
@@ -53,6 +53,7 @@ module Metanorma
53
53
  inline_macro Metanorma::Standoc::FormOptionMacro
54
54
  inline_macro Metanorma::Standoc::ToCInlineMacro
55
55
  inline_macro Metanorma::Standoc::PassInlineMacro
56
+ inline_macro Metanorma::Standoc::StdLinkInlineMacro
56
57
  inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
57
58
  inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
58
59
  block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
@@ -61,6 +62,7 @@ module Metanorma
61
62
  block Metanorma::Standoc::PlantUMLBlockMacro
62
63
  block Metanorma::Plugin::Lutaml::LutamlDiagramBlock
63
64
  block Metanorma::Standoc::PseudocodeBlockMacro
65
+ preprocessor Metanorma::Standoc::EmbedIncludeProcessor
64
66
  end
65
67
 
66
68
  include ::Asciidoctor::Converter
@@ -40,20 +40,29 @@ module Metanorma
40
40
  end
41
41
 
42
42
  def inline_anchor_xref_attrs(node)
43
- m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
44
- (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
43
+ m = inline_anchor_xref_match(node)
45
44
  t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
46
45
  m.nil? and return { target: t, type: "inline", text: node.text }
47
- droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
48
- f = m[:fn].nil? ? "inline" : "footnote"
49
- c = if %i[case fn drop drop2].any? do |x|
50
- !m[x].nil?
51
- end
52
- m[:text]
53
- else node.text
54
- end
55
- { target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
56
- text: c }
46
+ { target: t, type: m[:fn].nil? ? "inline" : "footnote",
47
+ case: m[:case]&.sub(/%$/, ""),
48
+ droploc: m[:drop].nil? && m[:drop2].nil? ? nil : true,
49
+ text: inline_anchor_xref_text(m, node),
50
+ hidden: m[:hidden] }
51
+ end
52
+
53
+ def inline_anchor_xref_match(node)
54
+ /^(hidden%(?<hidden>[^,]+),?)?
55
+ (?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
56
+ (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
57
+ end
58
+
59
+ def inline_anchor_xref_text(match, node)
60
+ if %i[case fn drop drop2 hidden].any? do |x|
61
+ !match[x].nil?
62
+ end
63
+ match[:text]
64
+ else node.text
65
+ end
57
66
  end
58
67
 
59
68
  def inline_anchor_link(node)
@@ -32,6 +32,43 @@
32
32
  <ref name="DocumentType"/>
33
33
  </element>
34
34
  </define>
35
+ <define name="index">
36
+ <element name="index">
37
+ <optional>
38
+ <attribute name="to">
39
+ <data type="IDREF"/>
40
+ </attribute>
41
+ </optional>
42
+ <element name="primary">
43
+ <oneOrMore>
44
+ <choice>
45
+ <ref name="PureTextElement"/>
46
+ <ref name="stem"/>
47
+ </choice>
48
+ </oneOrMore>
49
+ </element>
50
+ <optional>
51
+ <element name="secondary">
52
+ <oneOrMore>
53
+ <choice>
54
+ <ref name="PureTextElement"/>
55
+ <ref name="stem"/>
56
+ </choice>
57
+ </oneOrMore>
58
+ </element>
59
+ </optional>
60
+ <optional>
61
+ <element name="tertiary">
62
+ <oneOrMore>
63
+ <choice>
64
+ <ref name="PureTextElement"/>
65
+ <ref name="stem"/>
66
+ </choice>
67
+ </oneOrMore>
68
+ </element>
69
+ </optional>
70
+ </element>
71
+ </define>
35
72
  <define name="bibitem">
36
73
  <element name="bibitem">
37
74
  <attribute name="id">
@@ -115,9 +152,7 @@
115
152
  <data type="boolean"/>
116
153
  </attribute>
117
154
  </optional>
118
- <oneOrMore>
119
- <ref name="PureTextElement"/>
120
- </oneOrMore>
155
+ <ref name="XrefBody"/>
121
156
  </element>
122
157
  </define>
123
158
  <define name="erefType">
@@ -151,6 +186,42 @@
151
186
  <ref name="PureTextElement"/>
152
187
  </oneOrMore>
153
188
  </define>
189
+ <define name="localityStack">
190
+ <element name="localityStack">
191
+ <optional>
192
+ <attribute name="connective">
193
+ <choice>
194
+ <value>and</value>
195
+ <value>or</value>
196
+ <value>from</value>
197
+ <value>to</value>
198
+ <value/>
199
+ </choice>
200
+ </attribute>
201
+ </optional>
202
+ <zeroOrMore>
203
+ <ref name="locality"/>
204
+ </zeroOrMore>
205
+ </element>
206
+ </define>
207
+ <define name="sourceLocalityStack">
208
+ <element name="sourceLocalityStack">
209
+ <optional>
210
+ <attribute name="connective">
211
+ <choice>
212
+ <value>and</value>
213
+ <value>or</value>
214
+ <value>from</value>
215
+ <value>to</value>
216
+ <value/>
217
+ </choice>
218
+ </attribute>
219
+ </optional>
220
+ <zeroOrMore>
221
+ <ref name="sourceLocality"/>
222
+ </zeroOrMore>
223
+ </element>
224
+ </define>
154
225
  <define name="ul">
155
226
  <element name="ul">
156
227
  <attribute name="id">
@@ -1027,6 +1098,26 @@
1027
1098
  </zeroOrMore>
1028
1099
  </element>
1029
1100
  </define>
1101
+ <define name="sub">
1102
+ <element name="sub">
1103
+ <zeroOrMore>
1104
+ <choice>
1105
+ <ref name="PureTextElement"/>
1106
+ <ref name="stem"/>
1107
+ </choice>
1108
+ </zeroOrMore>
1109
+ </element>
1110
+ </define>
1111
+ <define name="sup">
1112
+ <element name="sup">
1113
+ <zeroOrMore>
1114
+ <choice>
1115
+ <ref name="PureTextElement"/>
1116
+ <ref name="stem"/>
1117
+ </choice>
1118
+ </zeroOrMore>
1119
+ </element>
1120
+ </define>
1030
1121
  <define name="pagebreak">
1031
1122
  <element name="pagebreak">
1032
1123
  <optional>
@@ -1041,6 +1132,16 @@
1041
1132
  </define>
1042
1133
  </include>
1043
1134
  <!-- end overrides -->
1135
+ <define name="image" combine="choice">
1136
+ <element name="svg">
1137
+ <oneOrMore>
1138
+ <choice>
1139
+ <text/>
1140
+ <ref name="AnyElement"/>
1141
+ </choice>
1142
+ </oneOrMore>
1143
+ </element>
1144
+ </define>
1044
1145
  <define name="MultilingualRenderingType">
1045
1146
  <choice>
1046
1147
  <value>common</value>
@@ -2216,7 +2317,18 @@
2216
2317
  <ref name="MultilingualRenderingType"/>
2217
2318
  </attribute>
2218
2319
  </optional>
2219
- <ref name="paragraph"/>
2320
+ <oneOrMore>
2321
+ <choice>
2322
+ <ref name="formula"/>
2323
+ <ref name="ul"/>
2324
+ <ref name="ol"/>
2325
+ <ref name="dl"/>
2326
+ <ref name="quote"/>
2327
+ <ref name="sourcecode"/>
2328
+ <ref name="paragraph"/>
2329
+ <ref name="figure"/>
2330
+ </choice>
2331
+ </oneOrMore>
2220
2332
  </element>
2221
2333
  </define>
2222
2334
  <define name="termsource">
@@ -2563,4 +2675,30 @@
2563
2675
  </zeroOrMore>
2564
2676
  </element>
2565
2677
  </define>
2678
+ <define name="XrefBody">
2679
+ <zeroOrMore>
2680
+ <ref name="XrefTarget"/>
2681
+ </zeroOrMore>
2682
+ <oneOrMore>
2683
+ <ref name="PureTextElement"/>
2684
+ </oneOrMore>
2685
+ </define>
2686
+ <define name="XrefTarget">
2687
+ <element name="location">
2688
+ <attribute name="target">
2689
+ <data type="string">
2690
+ <param name="pattern">\i\c*|\c+#\c+</param>
2691
+ </data>
2692
+ </attribute>
2693
+ <attribute name="connective">
2694
+ <choice>
2695
+ <value>and</value>
2696
+ <value>or</value>
2697
+ <value>from</value>
2698
+ <value>to</value>
2699
+ <value/>
2700
+ </choice>
2701
+ </attribute>
2702
+ </element>
2703
+ </define>
2566
2704
  </grammar>
@@ -7,6 +7,7 @@ require_relative "./macros_plantuml"
7
7
  require_relative "./macros_terms"
8
8
  require_relative "./macros_form"
9
9
  require_relative "./macros_note"
10
+ require_relative "./macros_embed"
10
11
  require_relative "./datamodel/attributes_table_preprocessor"
11
12
  require_relative "./datamodel/diagram_preprocessor"
12
13
  require "metanorma-plugin-datastruct"
@@ -81,7 +82,7 @@ module Metanorma
81
82
  .match(l) && (ignore = !ignore)
82
83
  next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) || ignore
83
84
  next if i == lines.size - 1 ||
84
- i < lines.size - 1 && lines[i + 1].empty?
85
+ (i < lines.size - 1 && lines[i + 1].empty?)
85
86
 
86
87
  lines[i] += " +"
87
88
  end
@@ -200,5 +201,17 @@ module Metanorma
200
201
  %{<passthrough formats="#{format}">#{out}</passthrough>}
201
202
  end
202
203
  end
204
+
205
+ class StdLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
206
+ use_dsl
207
+ named :"std-link"
208
+ parse_content_as :text
209
+ using_format :short
210
+
211
+ def process(parent, _target, attrs)
212
+ create_anchor(parent, "hidden%#{attrs['text']}",
213
+ type: :xref, target: "_#{UUIDTools::UUID.random_create}")
214
+ end
215
+ end
203
216
  end
204
217
  end
@@ -0,0 +1,72 @@
1
+ module Metanorma
2
+ module Standoc
3
+ class EmbedIncludeProcessor < Asciidoctor::Extensions::Preprocessor
4
+ def process(doc, reader)
5
+ return reader if reader.eof?
6
+
7
+ lines = reader.readlines
8
+ while !lines.grep(/^embed::/).empty?
9
+ headings = lines.grep(/^== /).map(&:strip)
10
+ lines = lines.map do |line|
11
+ /^embed::/.match?(line) ? embed(line, doc, reader, headings) : line
12
+ end.flatten
13
+ end
14
+ ::Asciidoctor::Reader.new lines
15
+ end
16
+
17
+ def filename(line, doc, reader)
18
+ m = /^embed::([^\[]+)\[/.match(line)
19
+ f = doc.normalize_system_path m[1], reader.dir, nil,
20
+ target_name: "include file"
21
+ File.exist?(f) ? f : nil
22
+ end
23
+
24
+ def readlines_safe(file)
25
+ if file.eof? then []
26
+ else file.readlines
27
+ end
28
+ end
29
+
30
+ def embed(line, doc, reader, headings)
31
+ inc_path = filename(line, doc, reader) or return line
32
+ lines = filter_sections(read(inc_path), headings)
33
+ doc = Asciidoctor::Document.new [], { safe: :safe }
34
+ reader = ::Asciidoctor::PreprocessorReader.new doc, lines
35
+ strip_header(reader.read_lines)
36
+ end
37
+
38
+ def read(inc_path)
39
+ ::File.open inc_path, "r" do |fd|
40
+ readlines_safe(fd).map(&:chomp)
41
+ end
42
+ end
43
+
44
+ def strip_header(lines)
45
+ return lines unless !lines.empty? && lines.first.start_with?("= ")
46
+
47
+ skip = true
48
+ lines.each_with_object([]) do |l, m|
49
+ m << l unless skip
50
+ skip = false if !/\S/.match?(l)
51
+ end
52
+ end
53
+
54
+ def filter_sections(lines, headings)
55
+ skip = false
56
+ lines.each_with_index.with_object([]) do |(l, i), m|
57
+ if headings.include?(l.strip)
58
+ skip = true
59
+ m.pop while !m.empty? && /^\S/.match?(m[-1])
60
+ elsif skip && /^== |^embed::|^include::/.match?(l)
61
+ skip = false
62
+ j = i
63
+ j -= 1 while j >= 0 && /^\S/.match?(m[j])
64
+ lines[j..i].each { |n| m << n }
65
+ else
66
+ skip or m << l
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -131,6 +131,7 @@ module Metanorma
131
131
  # TODO: alternative where only title is available
132
132
  def refitemcode(item, node)
133
133
  m = NON_ISO_REF.match(item) and return refitem1code(item, m).compact
134
+ m = NON_ISO_REF1.match(item) and return refitem1code(item, m).compact
134
135
  @log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
135
136
  {}
136
137
  end
@@ -180,7 +181,11 @@ module Metanorma
180
181
  (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
181
182
 
182
183
  NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
183
- \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)\]</ref>,?\s*(?<text>.*)$}xm
184
+ \[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
185
+ .freeze
186
+
187
+ NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
188
+ (?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
184
189
  .freeze
185
190
 
186
191
  def reference1_matches(item)
@@ -209,18 +214,17 @@ module Metanorma
209
214
  end
210
215
  end
211
216
 
212
- def reference_preproc(node)
217
+ def reference(node)
213
218
  refs = node.items.each_with_object([]) do |b, m|
214
219
  m << reference1code(b.text, node)
215
220
  end
221
+ reference_populate(refs)
222
+ end
223
+
224
+ def reference_populate(refs)
216
225
  results = refs.each_with_index.with_object(Queue.new) do |(ref, i), res|
217
226
  fetch_ref_async(ref.merge(ord: i), i, res)
218
227
  end
219
- [refs, results]
220
- end
221
-
222
- def reference(node)
223
- refs, results = reference_preproc(node)
224
228
  ret = reference_queue(refs, results)
225
229
  noko do |xml|
226
230
  ret.each { |b| reference1out(b, xml) }
@@ -75,7 +75,8 @@ module Metanorma
75
75
 
76
76
  def analyse_ref_repo_path(ret)
77
77
  return ret unless m =
78
- /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
78
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/
79
+ .match(ret[:id])
79
80
 
80
81
  id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
81
82
  ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
@@ -25,6 +25,9 @@ module Metanorma
25
25
  sectionsplit: node.attr("sectionsplit"),
26
26
  baseassetpath: node.attr("base-asset-path"),
27
27
  aligncrosselements: node.attr("align-cross-elements"),
28
+ tocfigures: @tocfigures,
29
+ toctables: @toctables,
30
+ tocrecommendations: @tocrecommendations,
28
31
  }
29
32
  end
30
33
 
@@ -61,12 +64,13 @@ module Metanorma
61
64
  bare: node.attr("bare"),
62
65
  baseassetpath: node.attr("base-asset-path"),
63
66
  aligncrosselements: node.attr("align-cross-elements"),
67
+ tocfigures: @tocfigures,
68
+ toctables: @toctables,
69
+ tocrecommendations: @tocrecommendations,
64
70
  }
65
71
 
66
72
  if fonts_manifest = node.attr(FONTS_MANIFEST)
67
- attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
68
- IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => fonts_manifest,
69
- }
73
+ attrs[IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST] = fonts_manifest
70
74
  end
71
75
 
72
76
  attrs
@@ -19,9 +19,7 @@ module Metanorma
19
19
  xml.table **attr_code(table_attrs(node)) do |xml_table|
20
20
  colgroup(node, xml_table)
21
21
  table_name(node, xml_table)
22
- %i(head body foot).reject do |tblsec|
23
- node.rows[tblsec].empty?
24
- end
22
+ %i(head body foot).reject { |tblsec| node.rows[tblsec].empty? }
25
23
  table_head_body_and_foot node, xml_table
26
24
  end
27
25
  end
@@ -50,12 +48,12 @@ module Metanorma
50
48
  end
51
49
  end
52
50
 
53
- def table_cell1(cell, thd)
54
- thd << if cell.style == :asciidoc
55
- cell.content
56
- else
57
- cell.text
58
- end
51
+ def table_cell1(cell)
52
+ if cell.style == :asciidoc
53
+ cell.content
54
+ else
55
+ cell.text
56
+ end
59
57
  end
60
58
 
61
59
  def table_cell(node, xml_tr, tblsec)
@@ -65,7 +63,7 @@ module Metanorma
65
63
  cell_tag = "td"
66
64
  cell_tag = "th" if tblsec == :head || node.style == :header
67
65
  xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
68
- table_cell1(node, thd)
66
+ thd << table_cell1(node)
69
67
  end
70
68
  end
71
69
 
@@ -58,7 +58,7 @@ module Metanorma
58
58
 
59
59
  def set_termxref_tags_target
60
60
  xmldoc.xpath("//termxref").each do |node|
61
- target = normalize_ref_id(node.text)
61
+ target = normalize_ref_id(node)
62
62
  if termlookup[:term][target].nil? && termlookup[:symbol][target].nil?
63
63
  remove_missing_ref(node, target)
64
64
  next
@@ -78,7 +78,7 @@ module Metanorma
78
78
 
79
79
  def remove_missing_ref_term(node, target)
80
80
  log.add("AsciiDoc Input", node,
81
- %(Error: Term reference in `term[#{target}]` missing: \
81
+ %(Error: Term reference to `#{target}` missing: \
82
82
  "#{target}" is not defined in document))
83
83
  node.name = "strong"
84
84
  node&.at("../xrefrender")&.remove
@@ -141,7 +141,7 @@ module Metanorma
141
141
  end
142
142
 
143
143
  def normalize_id_and_memorize_init(node, res_table, text_selector, prefix)
144
- term_text = normalize_ref_id(node.at(text_selector).text)
144
+ term_text = normalize_ref_id(node.at(text_selector))
145
145
  unless AUTOMATIC_GENERATED_ID_REGEXP.match(node["id"]).nil? &&
146
146
  !node["id"].nil?
147
147
  id = unique_text_id(term_text, prefix)
@@ -155,12 +155,15 @@ module Metanorma
155
155
  node.xpath(text_selector).each_with_index do |p, i|
156
156
  next unless i.positive?
157
157
 
158
- res_table[normalize_ref_id(p.text)] = node["id"]
158
+ res_table[normalize_ref_id(p)] = node["id"]
159
159
  end
160
160
  end
161
161
 
162
- def normalize_ref_id(text)
163
- Metanorma::Utils::to_ncname(text.downcase.gsub(/[[:space:]]/, "-"))
162
+ def normalize_ref_id(term)
163
+ t = term.dup
164
+ t.xpath(".//index").map(&:remove)
165
+ Metanorma::Utils::to_ncname(t.text.strip.downcase
166
+ .gsub(/[[:space:]]+/, "-"))
164
167
  end
165
168
 
166
169
  def unique_text_id(text, prefix)