metanorma-standoc 1.9.2 → 1.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -6
- data/lib/asciidoctor/standoc/base.rb +3 -1
- data/lib/asciidoctor/standoc/biblio.rng +1 -0
- data/lib/asciidoctor/standoc/blocks.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup.rb +34 -15
- data/lib/asciidoctor/standoc/cleanup_block.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
- data/lib/asciidoctor/standoc/cleanup_maths.rb +0 -1
- data/lib/asciidoctor/standoc/cleanup_ref.rb +7 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +73 -137
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
- data/lib/asciidoctor/standoc/converter.rb +1 -0
- data/lib/asciidoctor/standoc/front.rb +1 -2
- data/lib/asciidoctor/standoc/front_contributor.rb +66 -42
- data/lib/asciidoctor/standoc/inline.rb +45 -34
- data/lib/asciidoctor/standoc/isodoc.rng +66 -10
- data/lib/asciidoctor/standoc/macros.rb +7 -5
- data/lib/asciidoctor/standoc/macros_plantuml.rb +21 -23
- data/lib/asciidoctor/standoc/macros_terms.rb +60 -23
- data/lib/asciidoctor/standoc/section.rb +19 -12
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +87 -33
- data/lib/asciidoctor/standoc/terms.rb +1 -1
- data/lib/asciidoctor/standoc/utils.rb +0 -1
- data/lib/asciidoctor/standoc/validate.rb +22 -8
- data/lib/isodoc/html/html_titlepage.html +81 -0
- data/lib/isodoc/html/htmlstyle.css +983 -0
- data/lib/isodoc/html/htmlstyle.scss +714 -0
- data/lib/isodoc/html/scripts.html +71 -0
- data/lib/metanorma/standoc/processor.rb +16 -7
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +3 -3
- data/spec/asciidoctor/base_spec.rb +697 -557
- data/spec/asciidoctor/blocks_spec.rb +6 -8
- data/spec/asciidoctor/cleanup_sections_spec.rb +14 -14
- data/spec/asciidoctor/cleanup_spec.rb +899 -688
- data/spec/asciidoctor/inline_spec.rb +62 -14
- data/spec/asciidoctor/isobib_cache_spec.rb +4 -6
- data/spec/asciidoctor/lists_spec.rb +149 -137
- data/spec/asciidoctor/macros_json2text_spec.rb +1 -1
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +646 -169
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +1527 -1532
- data/spec/asciidoctor/section_spec.rb +58 -22
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +352 -304
- data/spec/spec_helper.rb +2 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -49
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -27
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +44 -44
- metadata +12 -11
- data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
- data/lib/liquid/custom_filters/values.rb +0 -7
@@ -149,7 +149,14 @@ module Asciidoctor
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
def bibitem_nested_id(xmldoc)
|
153
|
+
xmldoc.xpath("//bibitem//bibitem").each do |b|
|
154
|
+
b.delete("id")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
152
158
|
def bibitem_cleanup(xmldoc)
|
159
|
+
bibitem_nested_id(xmldoc)
|
153
160
|
ref_dl_cleanup(xmldoc)
|
154
161
|
fetch_local_bibitem(xmldoc)
|
155
162
|
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
require "date"
|
2
2
|
require "htmlentities"
|
3
3
|
require "json"
|
4
|
-
require "open-uri"
|
5
4
|
require "mathml2asciimath"
|
5
|
+
require_relative "cleanup_section_names"
|
6
6
|
|
7
7
|
module Asciidoctor
|
8
8
|
module Standoc
|
9
9
|
module Cleanup
|
10
|
-
def make_preface(
|
11
|
-
if
|
10
|
+
def make_preface(xml, sect)
|
11
|
+
if xml.at("//foreword | //introduction | //acknowledgements | "\
|
12
12
|
"//*[@preface]")
|
13
|
-
preface =
|
14
|
-
f =
|
15
|
-
f =
|
16
|
-
move_clauses_into_preface(
|
17
|
-
f =
|
13
|
+
preface = sect.add_previous_sibling("<preface/>").first
|
14
|
+
f = xml.at("//foreword") and preface.add_child f.remove
|
15
|
+
f = xml.at("//introduction") and preface.add_child f.remove
|
16
|
+
move_clauses_into_preface(xml, preface)
|
17
|
+
f = xml.at("//acknowledgements") and preface.add_child f.remove
|
18
18
|
end
|
19
|
-
make_abstract(
|
19
|
+
make_abstract(xml, sect)
|
20
20
|
end
|
21
21
|
|
22
|
-
def move_clauses_into_preface(
|
23
|
-
|
22
|
+
def move_clauses_into_preface(xml, preface)
|
23
|
+
xml.xpath("//*[@preface]").each do |c|
|
24
24
|
c.delete("preface")
|
25
25
|
preface.add_child c.remove
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def make_abstract(
|
30
|
-
if
|
31
|
-
preface =
|
32
|
-
|
33
|
-
abstract =
|
29
|
+
def make_abstract(xml, sect)
|
30
|
+
if xml.at("//abstract[not(ancestor::bibitem)]")
|
31
|
+
preface = sect.at("//preface") ||
|
32
|
+
sect.add_previous_sibling("<preface/>").first
|
33
|
+
abstract = xml.at("//abstract[not(ancestor::bibitem)]").remove
|
34
34
|
preface.prepend_child abstract.remove
|
35
|
-
bibabstract = bibabstract_location(
|
35
|
+
bibabstract = bibabstract_location(xml)
|
36
36
|
dupabstract = abstract.dup
|
37
37
|
dupabstract.traverse { |n| n.remove_attribute("id") }
|
38
38
|
dupabstract.remove_attribute("language")
|
@@ -42,40 +42,43 @@ module Asciidoctor
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def bibabstract_location(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
def bibabstract_location(xml)
|
46
|
+
xml.at("//bibdata/script") || xml.at("//bibdata/language") ||
|
47
|
+
xml.at("//bibdata/contributor[not(following-sibling::contributor)]") ||
|
48
|
+
xml.at("//bibdata/date[not(following-sibling::date)]") ||
|
49
|
+
xml.at("//docnumber") ||
|
50
|
+
xml.at("//bibdata/docidentifier"\
|
51
|
+
"[not(following-sibling::docidentifier)]") ||
|
52
|
+
xml.at("//bibdata/uri[not(following-sibling::uri)]") ||
|
53
|
+
xml.at("//bibdata/title[not(following-sibling::title)]")
|
54
54
|
end
|
55
55
|
|
56
|
-
def make_bibliography(
|
57
|
-
if
|
58
|
-
biblio =
|
59
|
-
|
56
|
+
def make_bibliography(xml, sect)
|
57
|
+
if xml.at("//sections/references")
|
58
|
+
biblio = sect.add_next_sibling("<bibliography/>").first
|
59
|
+
xml.xpath("//sections/references").each do |r|
|
60
60
|
biblio.add_child r.remove
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
def make_indexsect(
|
66
|
-
|
65
|
+
def make_indexsect(xml, sect)
|
66
|
+
xml.xpath("//sections/indexsect").reverse_each do |r|
|
67
|
+
sect.next = r.remove
|
68
|
+
end
|
67
69
|
end
|
68
70
|
|
69
|
-
def sections_order_cleanup(
|
70
|
-
s =
|
71
|
-
make_preface(
|
72
|
-
make_annexes(
|
73
|
-
make_indexsect(
|
74
|
-
make_bibliography(
|
75
|
-
|
71
|
+
def sections_order_cleanup(xml)
|
72
|
+
s = xml.at("//sections")
|
73
|
+
make_preface(xml, s)
|
74
|
+
make_annexes(xml)
|
75
|
+
make_indexsect(xml, s)
|
76
|
+
make_bibliography(xml, s)
|
77
|
+
xml.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
|
76
78
|
end
|
77
|
-
|
78
|
-
|
79
|
+
|
80
|
+
def make_annexes(xml)
|
81
|
+
xml.xpath("//*[@annex]").each do |y|
|
79
82
|
y.delete("annex")
|
80
83
|
next if y.name == "annex" || !y.ancestors("annex").empty?
|
81
84
|
|
@@ -87,60 +90,61 @@ module Asciidoctor
|
|
87
90
|
end
|
88
91
|
end
|
89
92
|
|
90
|
-
def maxlevel(
|
93
|
+
def maxlevel(xml)
|
91
94
|
max = 5
|
92
|
-
|
95
|
+
xml.xpath("//clause[@level]").each do |c|
|
93
96
|
max = c["level"].to_i if max < c["level"].to_i
|
94
97
|
end
|
95
98
|
max
|
96
99
|
end
|
97
100
|
|
98
|
-
def sections_level_cleanup(
|
99
|
-
m = maxlevel(
|
101
|
+
def sections_level_cleanup(xml)
|
102
|
+
m = maxlevel(xml)
|
100
103
|
return if m < 6
|
101
104
|
|
102
105
|
m.downto(6).each do |l|
|
103
|
-
|
106
|
+
xml.xpath("//clause[@level = '#{l}']").each do |c|
|
104
107
|
c.delete("level")
|
105
108
|
c.previous_element << c.remove
|
106
109
|
end
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
110
|
-
def sections_cleanup(
|
111
|
-
sections_order_cleanup(
|
112
|
-
sections_level_cleanup(
|
113
|
-
sections_names_cleanup(
|
114
|
-
change_clauses(
|
113
|
+
def sections_cleanup(xml)
|
114
|
+
sections_order_cleanup(xml)
|
115
|
+
sections_level_cleanup(xml)
|
116
|
+
sections_names_cleanup(xml)
|
117
|
+
change_clauses(xml)
|
115
118
|
end
|
116
119
|
|
117
|
-
def obligations_cleanup(
|
118
|
-
obligations_cleanup_info(
|
119
|
-
obligations_cleanup_norm(
|
120
|
-
obligations_cleanup_inherit(
|
120
|
+
def obligations_cleanup(xml)
|
121
|
+
obligations_cleanup_info(xml)
|
122
|
+
obligations_cleanup_norm(xml)
|
123
|
+
obligations_cleanup_inherit(xml)
|
121
124
|
end
|
122
125
|
|
123
|
-
def obligations_cleanup_info(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
def obligations_cleanup_info(xml)
|
127
|
+
s = xml.at("//foreword") and s["obligation"] = "informative"
|
128
|
+
s = xml.at("//introduction") and s["obligation"] = "informative"
|
129
|
+
s = xml.at("//acknowledgements") and s["obligation"] = "informative"
|
130
|
+
xml.xpath("//references").each { |r| r["obligation"] = "informative" }
|
131
|
+
xml.xpath("//preface//clause").each do |r|
|
129
132
|
r["obligation"] = "informative"
|
130
133
|
end
|
131
134
|
end
|
132
135
|
|
133
|
-
def obligations_cleanup_norm(
|
134
|
-
|
135
|
-
|
136
|
-
|
136
|
+
def obligations_cleanup_norm(xml)
|
137
|
+
s = xml.at("//clause[@type = 'scope']") and
|
138
|
+
s["obligation"] = "normative"
|
139
|
+
xml.xpath("//terms").each { |r| r["obligation"] = "normative" }
|
140
|
+
xml.xpath("//definitions").each { |r| r["obligation"] = "normative" }
|
137
141
|
end
|
138
142
|
|
139
|
-
def obligations_cleanup_inherit(
|
140
|
-
|
143
|
+
def obligations_cleanup_inherit(xml)
|
144
|
+
xml.xpath("//annex | //clause[not(ancestor::boilerplate)]").each do |r|
|
141
145
|
r["obligation"] = "normative" unless r["obligation"]
|
142
146
|
end
|
143
|
-
|
147
|
+
xml.xpath(Utils::SUBCLAUSE_XPATH).each do |r|
|
144
148
|
o = r&.at("./ancestor::*/@obligation")&.text and r["obligation"] = o
|
145
149
|
end
|
146
150
|
end
|
@@ -150,7 +154,7 @@ module Asciidoctor
|
|
150
154
|
sections_clausebefore_cleanup(xmldoc)
|
151
155
|
end
|
152
156
|
|
153
|
-
|
157
|
+
def preface_clausebefore_cleanup(xmldoc)
|
154
158
|
return unless xmldoc.at("//preface")
|
155
159
|
|
156
160
|
unless ins = xmldoc.at("//preface").children.first
|
@@ -175,74 +179,6 @@ module Asciidoctor
|
|
175
179
|
ins.previous = x.remove
|
176
180
|
end
|
177
181
|
end
|
178
|
-
|
179
|
-
def get_or_make_title(node)
|
180
|
-
unless node.at("./title")
|
181
|
-
if node.children.empty?
|
182
|
-
node << "<title/>"
|
183
|
-
else
|
184
|
-
node.children.first.previous = "<title/>"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
node.at("./title")
|
188
|
-
end
|
189
|
-
|
190
|
-
def replace_title(doc, xpath, text, first = false)
|
191
|
-
return unless text
|
192
|
-
|
193
|
-
doc.xpath(xpath).each_with_index do |node, i|
|
194
|
-
next if first && !i.zero?
|
195
|
-
|
196
|
-
title = get_or_make_title(node)
|
197
|
-
fn = title.xpath("./fn")
|
198
|
-
fn.each { |n| n.remove }
|
199
|
-
title.content = text
|
200
|
-
fn.each { |n| title << n }
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def sections_names_cleanup(xml)
|
205
|
-
replace_title(xml, "//clause[@type = 'scope']", @i18n&.scope)
|
206
|
-
replace_title(xml, "//preface//abstract", @i18n&.abstract)
|
207
|
-
replace_title(xml, "//foreword", @i18n&.foreword)
|
208
|
-
replace_title(xml, "//introduction", @i18n&.introduction)
|
209
|
-
replace_title(xml, "//acknowledgements", @i18n&.acknowledgements)
|
210
|
-
section_names_refs_cleanup(xml)
|
211
|
-
section_names_terms_cleanup(xml)
|
212
|
-
end
|
213
|
-
|
214
|
-
def section_names_refs_cleanup(xml)
|
215
|
-
replace_title(xml, "//references[@normative = 'true']",
|
216
|
-
@i18n&.normref, true)
|
217
|
-
replace_title(xml, "//references[@normative = 'false']",
|
218
|
-
@i18n&.bibliography, true)
|
219
|
-
end
|
220
|
-
|
221
|
-
NO_SYMABBR = "[.//definitions[not(@type)]]".freeze
|
222
|
-
SYMABBR = "[.//definitions[@type = 'symbols']"\
|
223
|
-
"[@type = 'abbreviated_terms']]".freeze
|
224
|
-
SYMnoABBR = "[.//definitions[@type = 'symbols']"\
|
225
|
-
"[not(@type = 'abbreviated_terms')]]".freeze
|
226
|
-
ABBRnoSYM = "[.//definitions[not(@type = 'symbols')]"\
|
227
|
-
"[@type = 'abbreviated_terms']]".freeze
|
228
|
-
|
229
|
-
def section_names_terms_cleanup(x)
|
230
|
-
replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
|
231
|
-
replace_title(x, "//definitions[@type = 'abbreviated_terms']",
|
232
|
-
@i18n&.abbrev)
|
233
|
-
replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
|
234
|
-
replace_title(x, "//terms#{SYMnoABBR} | //clause[.//terms]#{SYMnoABBR}",
|
235
|
-
@i18n&.termsdefsymbols, true)
|
236
|
-
replace_title(x, "//terms#{ABBRnoSYM} | //clause[.//terms]#{ABBRnoSYM}",
|
237
|
-
@i18n&.termsdefabbrev, true)
|
238
|
-
replace_title(x, "//terms#{SYMABBR} | //clause[.//terms]#{SYMABBR}",
|
239
|
-
@i18n&.termsdefsymbolsabbrev, true)
|
240
|
-
replace_title(x, "//terms#{NO_SYMABBR} | //clause[.//terms]#{NO_SYMABBR}",
|
241
|
-
@i18n&.termsdefsymbolsabbrev, true)
|
242
|
-
replace_title(
|
243
|
-
x, "//terms[not(.//definitions)] | //clause[.//terms][not(.//definitions)]",
|
244
|
-
@i18n&.termsdef, true)
|
245
|
-
end
|
246
182
|
end
|
247
183
|
end
|
248
184
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def get_or_make_title(node)
|
5
|
+
unless node.at("./title")
|
6
|
+
if node.children.empty?
|
7
|
+
node << "<title/>"
|
8
|
+
else
|
9
|
+
node.children.first.previous = "<title/>"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
node.at("./title")
|
13
|
+
end
|
14
|
+
|
15
|
+
def replace_title(doc, xpath, text, first = false)
|
16
|
+
return unless text
|
17
|
+
|
18
|
+
doc.xpath(xpath).each_with_index do |node, i|
|
19
|
+
next if first && !i.zero?
|
20
|
+
|
21
|
+
title = get_or_make_title(node)
|
22
|
+
fn = title.xpath("./fn")
|
23
|
+
fn.each(&:remove)
|
24
|
+
title.content = text
|
25
|
+
fn.each { |n| title << n }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sections_names_cleanup(xml)
|
30
|
+
replace_title(xml, "//clause[@type = 'scope']", @i18n&.scope)
|
31
|
+
replace_title(xml, "//preface//abstract", @i18n&.abstract)
|
32
|
+
replace_title(xml, "//foreword", @i18n&.foreword)
|
33
|
+
replace_title(xml, "//introduction", @i18n&.introduction)
|
34
|
+
replace_title(xml, "//acknowledgements", @i18n&.acknowledgements)
|
35
|
+
section_names_refs_cleanup(xml)
|
36
|
+
section_names_terms_cleanup(xml)
|
37
|
+
end
|
38
|
+
|
39
|
+
def section_names_refs_cleanup(xml)
|
40
|
+
replace_title(xml, "//references[@normative = 'true']",
|
41
|
+
@i18n&.normref, true)
|
42
|
+
replace_title(xml, "//references[@normative = 'false']",
|
43
|
+
@i18n&.bibliography, true)
|
44
|
+
end
|
45
|
+
|
46
|
+
NO_SYMABBR = "[.//definitions[not(@type)]]".freeze
|
47
|
+
SYMABBR = "[.//definitions[@type = 'symbols']]"\
|
48
|
+
"[.//definitions[@type = 'abbreviated_terms']]".freeze
|
49
|
+
SYMnoABBR = "[.//definitions[@type = 'symbols']]"\
|
50
|
+
"[not(.//definitions[@type = 'abbreviated_terms'])]".freeze
|
51
|
+
ABBRnoSYM = "[.//definitions[@type = 'abbreviated_terms']]"\
|
52
|
+
"[not(.//definitions[@type = 'symbols'])]".freeze
|
53
|
+
|
54
|
+
def section_names_terms_cleanup(x)
|
55
|
+
replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
|
56
|
+
replace_title(x, "//definitions[@type = 'abbreviated_terms']",
|
57
|
+
@i18n&.abbrev)
|
58
|
+
replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
|
59
|
+
replace_title(x, "//terms#{SYMnoABBR} | //clause[.//terms]#{SYMnoABBR}",
|
60
|
+
@i18n&.termsdefsymbols, true)
|
61
|
+
replace_title(x, "//terms#{ABBRnoSYM} | //clause[.//terms]#{ABBRnoSYM}",
|
62
|
+
@i18n&.termsdefabbrev, true)
|
63
|
+
replace_title(x, "//terms#{SYMABBR} | //clause[.//terms]#{SYMABBR}",
|
64
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
65
|
+
replace_title(x, "//terms#{NO_SYMABBR} | //clause[.//terms]#{NO_SYMABBR}",
|
66
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
67
|
+
replace_title(
|
68
|
+
x,
|
69
|
+
"//terms[not(.//definitions)] | //clause[.//terms][not(.//definitions)]",
|
70
|
+
@i18n&.termsdef, true
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -60,15 +60,15 @@ module Asciidoctor
|
|
60
60
|
|
61
61
|
def term_children_cleanup(xmldoc)
|
62
62
|
xmldoc.xpath("//term").each do |t|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
%w(termnote termexample termsource).each do |w|
|
64
|
+
t.xpath("./#{w}").each { |n| t << n.remove }
|
65
|
+
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
68
68
|
|
69
69
|
def termdef_from_termbase(xmldoc)
|
70
70
|
xmldoc.xpath("//term").each do |x|
|
71
|
-
if c = x.at("./origin/termref")
|
71
|
+
if (c = x.at("./origin/termref")) && !x.at("./definition")
|
72
72
|
x.at("./origin").previous = fetch_termbase(c["base"], c.text)
|
73
73
|
end
|
74
74
|
end
|
@@ -93,33 +93,34 @@ module Asciidoctor
|
|
93
93
|
termdomain1_cleanup(xmldoc)
|
94
94
|
termnote_example_cleanup(xmldoc)
|
95
95
|
termdef_subclause_cleanup(xmldoc)
|
96
|
-
term_children_cleanup(xmldoc)
|
96
|
+
term_children_cleanup(xmldoc)
|
97
97
|
termdocsource_cleanup(xmldoc)
|
98
|
-
end
|
98
|
+
end
|
99
99
|
|
100
100
|
# Indices sort after letter but before any following
|
101
101
|
# letter (x, x_m, x_1, xa); we use colon to force that sort order.
|
102
102
|
# Numbers sort *after* letters; we use thorn to force that sort order.
|
103
|
-
def symbol_key(
|
104
|
-
key =
|
103
|
+
def symbol_key(sym)
|
104
|
+
key = sym.dup
|
105
105
|
key.traverse do |n|
|
106
106
|
next unless n.name == "math"
|
107
|
+
|
107
108
|
n.replace(grkletters(MathML2AsciiMath.m2a(n.to_xml)))
|
108
109
|
end
|
109
110
|
ret = Nokogiri::XML(key.to_xml)
|
110
|
-
HTMLEntities.new.decode(ret.text.downcase)
|
111
|
-
gsub(/[\[\]
|
112
|
-
gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
|
113
|
-
gsub(/[0-9]+/, "þ\\0")
|
111
|
+
HTMLEntities.new.decode(ret.text.downcase)
|
112
|
+
.gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
|
113
|
+
.gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
|
114
|
+
.gsub(/[0-9]+/, "þ\\0")
|
114
115
|
end
|
115
|
-
|
116
|
+
|
116
117
|
def grkletters(x)
|
117
118
|
x.gsub(/\b(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)\b/i, "&\\1;")
|
118
119
|
end
|
119
120
|
|
120
|
-
def extract_symbols_list(
|
121
|
+
def extract_symbols_list(dlist)
|
121
122
|
dl_out = []
|
122
|
-
|
123
|
+
dlist.xpath("./dt | ./dd").each do |dtd|
|
123
124
|
if dtd.name == "dt"
|
124
125
|
dl_out << { dt: dtd.remove, key: symbol_key(dtd) }
|
125
126
|
else
|
@@ -128,7 +129,7 @@ module Asciidoctor
|
|
128
129
|
end
|
129
130
|
dl_out
|
130
131
|
end
|
131
|
-
|
132
|
+
|
132
133
|
def symbols_cleanup(docxml)
|
133
134
|
docxml.xpath("//definitions/dl").each do |dl|
|
134
135
|
dl_out = extract_symbols_list(dl)
|
@@ -136,7 +137,7 @@ module Asciidoctor
|
|
136
137
|
dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n")
|
137
138
|
end
|
138
139
|
docxml
|
139
|
-
end
|
140
|
+
end
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|