metanorma-standoc 1.6.0 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +66 -0
  3. data/README.adoc +1 -3
  4. data/lib/asciidoctor/standoc/base.rb +8 -16
  5. data/lib/asciidoctor/standoc/basicdoc.rng +32 -0
  6. data/lib/asciidoctor/standoc/cleanup.rb +52 -4
  7. data/lib/asciidoctor/standoc/cleanup_block.rb +41 -4
  8. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
  9. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +25 -0
  10. data/lib/asciidoctor/standoc/cleanup_inline.rb +6 -2
  11. data/lib/asciidoctor/standoc/cleanup_ref.rb +18 -25
  12. data/lib/asciidoctor/standoc/cleanup_terms.rb +3 -0
  13. data/lib/asciidoctor/standoc/converter.rb +61 -3
  14. data/lib/asciidoctor/standoc/front.rb +9 -3
  15. data/lib/asciidoctor/standoc/front_contributor.rb +34 -10
  16. data/lib/asciidoctor/standoc/isodoc.rng +29 -44
  17. data/lib/asciidoctor/standoc/lists.rb +4 -2
  18. data/lib/asciidoctor/standoc/macros.rb +45 -63
  19. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  20. data/lib/asciidoctor/standoc/ref.rb +24 -36
  21. data/lib/asciidoctor/standoc/ref_sect.rb +16 -8
  22. data/lib/asciidoctor/standoc/section.rb +5 -9
  23. data/lib/asciidoctor/standoc/table.rb +12 -0
  24. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  25. data/lib/liquid/custom_blocks/with_json_nested_context.rb +18 -0
  26. data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +19 -0
  27. data/lib/metanorma/standoc/version.rb +1 -1
  28. data/metanorma-standoc.gemspec +6 -3
  29. data/spec/asciidoctor-standoc/base_spec.rb +127 -8
  30. data/spec/asciidoctor-standoc/blocks_spec.rb +8 -8
  31. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +1514 -0
  32. data/spec/asciidoctor-standoc/cleanup_spec.rb +450 -1554
  33. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +22 -31
  34. data/spec/asciidoctor-standoc/lists_spec.rb +10 -1
  35. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +1 -1
  36. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +80 -0
  37. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  38. data/spec/asciidoctor-standoc/macros_spec.rb +378 -169
  39. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +1 -1
  40. data/spec/asciidoctor-standoc/refs_dl_spec.rb +8 -8
  41. data/spec/asciidoctor-standoc/refs_spec.rb +350 -101
  42. data/spec/asciidoctor-standoc/section_spec.rb +11 -11
  43. data/spec/asciidoctor-standoc/table_spec.rb +86 -0
  44. data/spec/asciidoctor-standoc/validate_spec.rb +26 -0
  45. data/spec/fixtures/diagram_definitions.lutaml +22 -0
  46. data/spec/fixtures/test.exp +121 -0
  47. data/spec/spec_helper.rb +33 -0
  48. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +156 -4
  49. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -233
  50. data/spec/vcr_cassettes/isobib_get_123.yml +12 -58
  51. data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -119
  52. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
  53. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -58
  54. data/spec/vcr_cassettes/isobib_get_124.yml +11 -57
  55. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  56. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +276 -158
  57. metadata +61 -14
  58. data/.github/workflows/macos.yml +0 -41
  59. data/.github/workflows/ubuntu.yml +0 -45
  60. data/.github/workflows/windows.yml +0 -43
  61. data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +0 -123
  62. data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +0 -44
  63. data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a619338025bf24d56d382fde0bfcd3d7c5f2e5ecf5520d995d8c7d4986cb67d
4
- data.tar.gz: 1f8c10a80a5ada1b94c6216568eb11851fd081c9ae63bae2d8b9e3e080673b17
3
+ metadata.gz: 5f510c7d84985eb301f3bfe71f4ebe89f39961a6b9ec113a9e019537056e3933
4
+ data.tar.gz: a0844efae9739bfd19ab8263dd9a5b1edff6883b443f5c7fb399a056cd528bfa
5
5
  SHA512:
6
- metadata.gz: 5d9fea4687d265c36099b30faa69893c10ec011e7d1a8b7e32b4e0df4ef9d892e5efe90bb8bd0767f51f3ec74f91b05dc3613532eeff247f1a2039b6094f15dc
7
- data.tar.gz: 2ccb181da62a4ca659c2f3915ffdbebbc88b501c97938244d65d780b241e05bd2f61870ac32cc8a3cef739ac7a36b8c714f2cc5027d9269e78c7e6f6bcabb12c
6
+ metadata.gz: f9fa2f578c9b742860c5464141a2efbe1d565061148e0aa701520cfe8cfe0ef0828c46ffa21883d893190af37efc7c31a792d4a11a6c8775a43ca6bae6b08aa9
7
+ data.tar.gz: 63a79d788f62977472a2ff3c21d1926dfb52b43722092f82f721cbcfb8748caba1adec96fb3062c02dab8fb7d74b9dc691bcb70dca9f91121d778122444158bc
@@ -0,0 +1,66 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
+ name: rake
4
+
5
+ on:
6
+ push:
7
+ branches: [ master, main ]
8
+ tags: [ v* ]
9
+ pull_request:
10
+
11
+ jobs:
12
+ rake:
13
+ name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
+ runs-on: ${{ matrix.os }}
15
+ continue-on-error: ${{ matrix.experimental }}
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [ '2.6', '2.5', '2.4' ]
20
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
21
+ experimental: [ false ]
22
+ include:
23
+ - ruby: '2.7'
24
+ os: 'ubuntu-latest'
25
+ experimental: true
26
+ - ruby: '2.7'
27
+ os: 'windows-latest'
28
+ experimental: true
29
+ - ruby: '2.7'
30
+ os: 'macos-latest'
31
+ experimental: true
32
+ steps:
33
+ - uses: actions/checkout@master
34
+
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+
39
+ - uses: actions/cache@v2
40
+ with:
41
+ path: vendor/bundle
42
+ key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
43
+ restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
44
+
45
+ - run: bundle config set path 'vendor/bundle'
46
+
47
+ - run: bundle install --jobs 4 --retry 3
48
+
49
+ - name: install plantuml ubuntu
50
+ if: matrix.os == 'ubuntu-latest'
51
+ uses: nick-invision/retry@v1
52
+ with:
53
+ polling_interval_seconds: 5
54
+ timeout_minutes: 5
55
+ max_attempts: 3
56
+ command: >
57
+ sudo apt-get update -y && sudo bash -c
58
+ "curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
59
+
60
+ - if: matrix.os == 'macos-latest'
61
+ run: brew install plantuml
62
+
63
+ - if: matrix.os == 'windows-latest'
64
+ run: cinst -y plantuml
65
+
66
+ - run: bundle exec rake
@@ -1,9 +1,7 @@
1
1
  = Metanorma-standoc
2
2
 
3
3
  image:https://img.shields.io/gem/v/metanorma-standoc.svg["Gem Version", link="https://rubygems.org/gems/metanorma-standoc"]
4
- image:https://github.com/metanorma/metanorma-standoc/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=macos"]
5
- image:https://github.com/metanorma/metanorma-standoc/workflows/ubuntu/badge.svg["Build Status (ubuntu)", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=ubuntu"]
6
- image:https://github.com/metanorma/metanorma-standoc/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=windows"]
4
+ image:https://github.com/metanorma/metanorma-standoc/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/metanorma-standoc/actions?workflow=rake"]
7
5
  image:https://codeclimate.com/github/metanorma/metanorma-standoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/metanorma-standoc"]
8
6
  image:https://img.shields.io/github/issues-pr-raw/metanorma/metanorma-standoc.svg["Pull Requests", link="https://github.com/metanorma/metanorma-standoc/pulls"]
9
7
  image:https://img.shields.io/github/commits-since/metanorma/metanorma-standoc/latest.svg["Commits since latest",link="https://github.com/metanorma/metanorma-standoc/releases"]
@@ -94,12 +94,10 @@ module Asciidoctor
94
94
  @draft = node.attributes.has_key?("draft")
95
95
  @novalid = node.attr("novalid")
96
96
  @smartquotes = node.attr("smartquotes") != "false"
97
- @keepasciimath = node.attr("mn-keep-asciimath") &&
98
- node.attr("mn-keep-asciimath") != "false"
97
+ @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false"
99
98
  @fontheader = default_fonts(node)
100
99
  @files_to_delete = []
101
- @filename = node.attr("docfile") ?
102
- File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
100
+ @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
103
101
  @localdir = Utils::localdir(node)
104
102
  @output_dir = outputdir node
105
103
  @no_isobib_cache = node.attr("no-isobib-cache")
@@ -119,11 +117,9 @@ module Asciidoctor
119
117
 
120
118
  def default_fonts(node)
121
119
  b = node.attr("body-font") ||
122
- (node.attr("script") == "Hans" ? '"SimSun",serif' :
123
- '"Cambria",serif')
120
+ (node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif')
124
121
  h = node.attr("header-font") ||
125
- (node.attr("script") == "Hans" ? '"SimHei",sans-serif' :
126
- '"Cambria",serif')
122
+ (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif')
127
123
  m = node.attr("monospace-font") || '"Courier New",monospace'
128
124
  "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
129
125
  end
@@ -154,8 +150,7 @@ module Asciidoctor
154
150
  end
155
151
 
156
152
  def makexml1(node)
157
- result = ["<?xml version='1.0' encoding='UTF-8'?>",
158
- "<#{xml_root_tag} type='semantic' version='#{version}'>"]
153
+ result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag} type='semantic' version='#{version}'>"]
159
154
  result << noko { |ixml| front node, ixml }
160
155
  result << noko { |ixml| middle node, ixml }
161
156
  result << "</#{xml_root_tag}>"
@@ -192,16 +187,14 @@ module Asciidoctor
192
187
 
193
188
  def term_source_attrs(seen_xref)
194
189
  { bibitemid: seen_xref.children[0]["target"],
195
- format: seen_xref.children[0]["format"],
196
- type: "inline" }
190
+ format: seen_xref.children[0]["format"], type: "inline" }
197
191
  end
198
192
 
199
193
  def add_term_source(xml_t, seen_xref, m)
200
194
  if seen_xref.children[0].name == "concept"
201
195
  xml_t.origin { |o| o << seen_xref.children[0].to_xml }
202
196
  else
203
- xml_t.origin seen_xref.children[0].content,
204
- **attr_code(term_source_attrs(seen_xref))
197
+ xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
205
198
  end
206
199
  m[:text] && xml_t.modification do |mod|
207
200
  mod.p { |p| p << m[:text].sub(/^\s+/, "") }
@@ -219,8 +212,7 @@ module Asciidoctor
219
212
 
220
213
  def extract_termsource_refs(text, node)
221
214
  matched = TERM_REFERENCE_RE.match text
222
- matched.nil? and
223
- @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
215
+ matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
224
216
  matched
225
217
  end
226
218
 
@@ -596,6 +596,7 @@
596
596
  <ref name="bookmark"/>
597
597
  <ref name="image"/>
598
598
  <ref name="index"/>
599
+ <ref name="index-xref"/>
599
600
  </choice>
600
601
  </define>
601
602
  <define name="PureTextElement">
@@ -737,6 +738,37 @@
737
738
  </optional>
738
739
  </element>
739
740
  </define>
741
+ <define name="index-xref">
742
+ <element name="index-xref">
743
+ <attribute name="also">
744
+ <data type="boolean"/>
745
+ </attribute>
746
+ <element name="primary">
747
+ <oneOrMore>
748
+ <ref name="PureTextElement"/>
749
+ </oneOrMore>
750
+ </element>
751
+ <optional>
752
+ <element name="secondary">
753
+ <oneOrMore>
754
+ <ref name="PureTextElement"/>
755
+ </oneOrMore>
756
+ </element>
757
+ </optional>
758
+ <optional>
759
+ <element name="tertiary">
760
+ <oneOrMore>
761
+ <ref name="PureTextElement"/>
762
+ </oneOrMore>
763
+ </element>
764
+ </optional>
765
+ <element name="target">
766
+ <oneOrMore>
767
+ <ref name="PureTextElement"/>
768
+ </oneOrMore>
769
+ </element>
770
+ </element>
771
+ </define>
740
772
  <!-- bare ID element, used for referencing arbitrary spans of text -->
741
773
  <define name="bookmark">
742
774
  <element name="bookmark">
@@ -69,6 +69,7 @@ module Asciidoctor
69
69
  bibdata_cleanup(xmldoc)
70
70
  boilerplate_cleanup(xmldoc)
71
71
  smartquotes_cleanup(xmldoc)
72
+ variant_cleanup(xmldoc)
72
73
  para_cleanup(xmldoc)
73
74
  empty_element_cleanup(xmldoc)
74
75
  img_cleanup(xmldoc)
@@ -155,17 +156,42 @@ module Asciidoctor
155
156
  x.children = math
156
157
  end
157
158
 
159
+ MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
160
+
158
161
  def mathml_preserve_space(m)
159
- m.xpath(".//m:mtext",
160
- "m" => "http://www.w3.org/1998/Math/MathML").each do |x|
162
+ m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
161
163
  x.children = x.children.to_xml.gsub(/^\s/, "&#xA0;").
162
164
  gsub(/\s$/, "&#xA0;")
163
165
  end
164
166
  end
165
167
 
166
168
  def mathml_namespace(stem)
167
- stem.xpath("./math", ).each do |x|
168
- x.default_namespace = "http://www.w3.org/1998/Math/MathML"
169
+ stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
170
+ end
171
+
172
+ def mathml_mi_italics
173
+ { uppergreek: true, upperroman: true,
174
+ lowergreek: true, lowerroman: true }
175
+ end
176
+
177
+ # presuppose multichar mi upright, singlechar mi MathML default italic
178
+ def mathml_italicise(x)
179
+ x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
180
+ char = HTMLEntities.new.decode(i.text)
181
+ i["mathvariant"] = "normal" if mi_italicise?(char)
182
+ end
183
+ end
184
+
185
+ def mi_italicise?(c)
186
+ return false if c.length > 1
187
+ if /\p{Greek}/.match(c)
188
+ /\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
189
+ /\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
190
+ elsif /\p{Latin}/.match(c)
191
+ /\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
192
+ /\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
193
+ else
194
+ false
169
195
  end
170
196
  end
171
197
 
@@ -174,6 +200,7 @@ module Asciidoctor
174
200
  xml_unescape_mathml(x)
175
201
  mathml_namespace(x)
176
202
  mathml_preserve_space(x)
203
+ mathml_italicise(x)
177
204
  end
178
205
  end
179
206
 
@@ -192,6 +219,27 @@ module Asciidoctor
192
219
  i["src"] = datauri(i["src"])
193
220
  end
194
221
  end
222
+
223
+ def variant_cleanup(xmldoc)
224
+ xmldoc.xpath("//*[variant]").each do |c|
225
+ c&.next&.text? && c&.next&.next&.name == "variant" &&
226
+ c.next.text.gsub(/\s/, "").empty? and c.next.remove
227
+ end
228
+ xmldoc.xpath("//*[variant]").each do |c|
229
+ next unless c.children.any? do |n|
230
+ n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
231
+ end
232
+ c.xpath("./variant").each do |n|
233
+ if n.at_xpath('preceding-sibling::node()[not(self::text()'\
234
+ '[not(normalize-space())])][1][self::variantwrap]')
235
+ n.previous_element << n
236
+ else
237
+ n.replace('<variantwrap/>').first << n
238
+ end
239
+ end
240
+ end
241
+ xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
242
+ end
195
243
  end
196
244
  end
197
245
  end
@@ -19,12 +19,22 @@ module Asciidoctor
19
19
  end
20
20
  end
21
21
 
22
+ def dl1_table_cleanup(xmldoc)
23
+ q = "//table/following-sibling::*[1][self::dl]"
24
+ xmldoc.xpath(q).each do |s|
25
+ if s["key"] == "true"
26
+ s.previous_element << s.remove
27
+ end
28
+ end
29
+ end
30
+
22
31
  # move Key dl after table footer
23
- def dl_table_cleanup(xmldoc)
32
+ def dl2_table_cleanup(xmldoc)
24
33
  q = "//table/following-sibling::*[1][self::p]"
25
34
  xmldoc.xpath(q).each do |s|
26
35
  if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
27
36
  s.next_element.name == "dl"
37
+ s.next_element["key"] = "true"
28
38
  s.previous_element << s.next_element.remove
29
39
  s.remove
30
40
  end
@@ -54,7 +64,8 @@ module Asciidoctor
54
64
  end
55
65
 
56
66
  def table_cleanup(xmldoc)
57
- dl_table_cleanup(xmldoc)
67
+ dl1_table_cleanup(xmldoc)
68
+ dl2_table_cleanup(xmldoc)
58
69
  notes_table_cleanup(xmldoc)
59
70
  header_rows_cleanup(xmldoc)
60
71
  end
@@ -74,22 +85,47 @@ module Asciidoctor
74
85
 
75
86
  # include where definition list inside stem block
76
87
  def formula_cleanup(x)
88
+ formula_cleanup_where1(x)
89
+ formula_cleanup_where2(x)
90
+ end
91
+
92
+ def formula_cleanup_where1(x)
93
+ q = "//formula/following-sibling::*[1][self::dl]"
94
+ x.xpath(q).each do |s|
95
+ if s["key"] == "true"
96
+ s.previous_element << s.remove
97
+ end
98
+ end
99
+ end
100
+
101
+ def formula_cleanup_where2(x)
77
102
  q = "//formula/following-sibling::*[1][self::p]"
78
103
  x.xpath(q).each do |s|
79
104
  if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? &&
80
105
  s.next_element.name == "dl"
106
+ s.next_element["key"] = "true"
81
107
  s.previous_element << s.next_element.remove
82
108
  s.remove
83
109
  end
84
110
  end
85
111
  end
86
112
 
113
+ def figure_dl_cleanup1(xmldoc)
114
+ q = "//figure/following-sibling::*[self::dl]"
115
+ xmldoc.xpath(q).each do |s|
116
+ if s["key"] == "true"
117
+ s.previous_element << s.remove
118
+ end
119
+ end
120
+ end
121
+
87
122
  # include key definition list inside figure
88
- def figure_dl_cleanup(xmldoc)
123
+ def figure_dl_cleanup2(xmldoc)
89
124
  q = "//figure/following-sibling::*[self::p]"
90
125
  xmldoc.xpath(q).each do |s|
91
126
  if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
92
127
  s.next_element.name == "dl"
128
+ s.next_element["key"] = "true"
93
129
  s.previous_element << s.next_element.remove
94
130
  s.remove
95
131
  end
@@ -115,7 +151,8 @@ module Asciidoctor
115
151
 
116
152
  def figure_cleanup(xmldoc)
117
153
  figure_footnote_cleanup(xmldoc)
118
- figure_dl_cleanup(xmldoc)
154
+ figure_dl_cleanup1(xmldoc)
155
+ figure_dl_cleanup2(xmldoc)
119
156
  subfigure_cleanup(xmldoc)
120
157
  end
121
158
 
@@ -91,10 +91,24 @@ module Asciidoctor
91
91
  end
92
92
 
93
93
  def bibdata_cleanup(xmldoc)
94
+ bibdata_anchor_cleanup(xmldoc)
95
+ bibdata_docidentifier_cleanup(xmldoc)
96
+ end
97
+
98
+ def bibdata_anchor_cleanup(xmldoc)
94
99
  xmldoc.xpath("//bibdata//bibitem | //bibdata//note").each do |b|
95
100
  b.delete("id")
96
101
  end
97
102
  end
103
+
104
+ def bibdata_docidentifier_cleanup(xmldoc)
105
+ ins = xmldoc.at("//bibdata/docidentifier")
106
+ xmldoc.xpath("//bibdata/docidentifier").each_with_index do |b, i|
107
+ next if i == 0
108
+ ins.next = b.remove
109
+ ins = ins.next
110
+ end
111
+ end
98
112
  end
99
113
  end
100
114
  end
@@ -72,7 +72,32 @@ module Asciidoctor
72
72
  end
73
73
  end
74
74
 
75
+ def title_footnote_move(xmldoc)
76
+ ins = xmldoc.at("//bibdata/language")
77
+ xmldoc.xpath("//bibdata/title//fn").each do |f|
78
+ f.name = "note"
79
+ f["type"] = "title-footnote"
80
+ f.delete("reference")
81
+ ins.previous = f.remove
82
+ end
83
+ end
84
+
85
+ def footnote_block_cleanup(xmldoc)
86
+ xmldoc.xpath("//footnoteblock").each do |f|
87
+ f.name = 'fn'
88
+ if id = xmldoc.at("//*[@id = '#{f.text}']")
89
+ f.children = id.remove.children
90
+ else
91
+ @log.add("Crossreferences", f,
92
+ "Could not resolve footnoteblock:[#{f.text}]")
93
+ f.children = "[ERROR]"
94
+ end
95
+ end
96
+ end
97
+
75
98
  def footnote_cleanup(xmldoc)
99
+ footnote_block_cleanup(xmldoc)
100
+ title_footnote_move(xmldoc)
76
101
  table_footnote_renumber(xmldoc)
77
102
  other_footnote_renumber(xmldoc)
78
103
  xmldoc.xpath("//fn").each do |fn|
@@ -49,8 +49,12 @@ module Asciidoctor
49
49
  end
50
50
 
51
51
  def extract_localities(x)
52
- text = x&.children&.first&.remove&.text
53
- extract_localities1(x, text)
52
+ f = x&.children&.first or return
53
+ f.text? or return
54
+ head = f.remove.text
55
+ tail = x&.children&.remove
56
+ extract_localities1(x, head)
57
+ tail and x << tail
54
58
  end
55
59
 
56
60
  def extract_localities1(x, text)