isodoc 1.7.3 → 1.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +7 -4
  3. data/lib/isodoc/class_utils.rb +2 -2
  4. data/lib/isodoc/convert.rb +2 -0
  5. data/lib/isodoc/function/blocks_example_note.rb +85 -79
  6. data/lib/isodoc/function/cleanup.rb +181 -175
  7. data/lib/isodoc/function/inline.rb +110 -108
  8. data/lib/isodoc/function/inline_simple.rb +55 -55
  9. data/lib/isodoc/function/lists.rb +75 -71
  10. data/lib/isodoc/function/references.rb +165 -160
  11. data/lib/isodoc/function/section.rb +140 -190
  12. data/lib/isodoc/function/section_titles.rb +82 -0
  13. data/lib/isodoc/function/table.rb +90 -87
  14. data/lib/isodoc/function/terms.rb +58 -56
  15. data/lib/isodoc/function/to_word_html.rb +3 -1
  16. data/lib/isodoc/function/utils.rb +34 -14
  17. data/lib/isodoc/html_function/comments.rb +107 -111
  18. data/lib/isodoc/html_function/footnotes.rb +68 -67
  19. data/lib/isodoc/html_function/html.rb +113 -103
  20. data/lib/isodoc/html_function/mathvariant_to_plain.rb +5 -3
  21. data/lib/isodoc/presentation_function/block.rb +73 -78
  22. data/lib/isodoc/presentation_function/concept.rb +68 -0
  23. data/lib/isodoc/presentation_function/image.rb +112 -0
  24. data/lib/isodoc/presentation_function/inline.rb +6 -39
  25. data/lib/isodoc/presentation_function/math.rb +9 -0
  26. data/lib/isodoc/presentation_function/section.rb +12 -1
  27. data/lib/isodoc/presentation_xml_convert.rb +3 -0
  28. data/lib/isodoc/version.rb +1 -1
  29. data/lib/isodoc/word_function/body.rb +176 -174
  30. data/lib/isodoc/word_function/comments.rb +117 -112
  31. data/lib/isodoc/word_function/footnotes.rb +88 -86
  32. data/lib/isodoc/word_function/inline.rb +42 -67
  33. data/lib/isodoc/word_function/postprocess_cover.rb +121 -110
  34. data/lib/isodoc/xref/xref_gen.rb +153 -150
  35. data/lib/isodoc/xslfo_convert.rb +2 -2
  36. data/lib/isodoc.rb +1 -1
  37. data/spec/assets/odf.svg +1 -4
  38. data/spec/isodoc/blocks_spec.rb +187 -32
  39. data/spec/isodoc/inline_spec.rb +300 -116
  40. data/spec/isodoc/postproc_spec.rb +38 -0
  41. data/spec/isodoc/presentation_xml_spec.rb +144 -0
  42. data/spec/isodoc/section_spec.rb +764 -0
  43. data/spec/isodoc/terms_spec.rb +116 -0
  44. metadata +63 -18
@@ -1,226 +1,232 @@
1
- module IsoDoc::Function
2
- module Cleanup
3
- def textcleanup(docxml)
4
- termref_cleanup(passthrough_cleanup(docxml))
5
- end
1
+ module IsoDoc
2
+ module Function
3
+ module Cleanup
4
+ def textcleanup(docxml)
5
+ termref_cleanup(passthrough_cleanup(docxml))
6
+ end
6
7
 
7
- def termref_cleanup(docxml)
8
- docxml
9
- .gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
10
- l10n(", #{@i18n.modified} [/TERMREF]"))
11
- .gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
12
- .gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
13
- .gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
14
- .gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} &mdash; "))
15
- end
8
+ def termref_cleanup(docxml)
9
+ docxml
10
+ .gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/,
11
+ l10n(", #{@i18n.modified} [/TERMREF]"))
12
+ .gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ")
13
+ .gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: "))
14
+ .gsub(%r{\s*\[/TERMREF\]\s*}, l10n("]"))
15
+ .gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} &mdash; "))
16
+ end
16
17
 
17
- def passthrough_cleanup(docxml)
18
- docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4).map do |a|
19
- a.size > 2 and a[2] = HTMLEntities.new.decode(a[2])
20
- [a[0], a[2]]
21
- end.join
22
- end
18
+ def passthrough_cleanup(docxml)
19
+ docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4)
20
+ .map do |a|
21
+ a.size > 2 and a[2] = HTMLEntities.new.decode(a[2])
22
+ [a[0], a[2]]
23
+ end.join
24
+ end
23
25
 
24
- def cleanup(docxml)
25
- @i18n ||= i18n_init(@lang, @script)
26
- comment_cleanup(docxml)
27
- footnote_cleanup(docxml)
28
- inline_header_cleanup(docxml)
29
- figure_cleanup(docxml)
30
- table_cleanup(docxml)
31
- symbols_cleanup(docxml)
32
- example_cleanup(docxml)
33
- admonition_cleanup(docxml)
34
- end
26
+ def cleanup(docxml)
27
+ @i18n ||= i18n_init(@lang, @script)
28
+ comment_cleanup(docxml)
29
+ footnote_cleanup(docxml)
30
+ inline_header_cleanup(docxml)
31
+ figure_cleanup(docxml)
32
+ table_cleanup(docxml)
33
+ symbols_cleanup(docxml)
34
+ example_cleanup(docxml)
35
+ admonition_cleanup(docxml)
36
+ end
35
37
 
36
- def table_long_strings_cleanup(docxml)
37
- return unless @break_up_urls_in_tables == true
38
+ def table_long_strings_cleanup(docxml)
39
+ return unless @break_up_urls_in_tables == true
38
40
 
39
- docxml.xpath("//td | //th").each do |d|
40
- d.traverse do |n|
41
- next unless n.text?
41
+ docxml.xpath("//td | //th").each do |d|
42
+ d.traverse do |n|
43
+ next unless n.text?
42
44
 
43
- n.replace(HTMLEntities.new.encode(
44
- break_up_long_strings(n.text),
45
- ))
45
+ n.replace(HTMLEntities.new.encode(
46
+ break_up_long_strings(n.text),
47
+ ))
48
+ end
46
49
  end
47
50
  end
48
- end
49
51
 
50
- def break_up_long_strings(text)
51
- return text if /^\s*$/.match?(text)
52
+ def break_up_long_strings(text)
53
+ return text if /^\s*$/.match?(text)
54
+
55
+ text.split(/(?=\s)/).map do |w|
56
+ if /^\s*$/.match(text) || (w.size < 30) then w
57
+ else
58
+ w.scan(/.{,30}/).map do |w1|
59
+ w1.size < 30 ? w1 : break_up_long_strings1(w1)
60
+ end.join
61
+ end
62
+ end.join
63
+ end
52
64
 
53
- text.split(/(?=\s)/).map do |w|
54
- if /^\s*$/.match(text) || (w.size < 30) then w
65
+ def break_up_long_strings1(text)
66
+ s = text.split(%r{(?<=[,.?+;/=])})
67
+ if s.size == 1 then "#{text} "
55
68
  else
56
- w.scan(/.{,30}/).map do |w1|
57
- w1.size < 30 ? w1 : break_up_long_strings1(w1)
58
- end.join
69
+ s[-1] = " #{s[-1]}"
70
+ s.join
59
71
  end
60
- end.join
61
- end
62
-
63
- def break_up_long_strings1(text)
64
- s = text.split(%r{(?<=[,.?+;/=])})
65
- if s.size == 1 then "#{text} "
66
- else
67
- s[-1] = " #{s[-1]}"
68
- s.join
69
72
  end
70
- end
71
73
 
72
- def admonition_cleanup(docxml)
73
- docxml.xpath("//div[@class = 'Admonition'][title]").each do |d|
74
- title = d.at("./title")
75
- n = title.next_element
76
- n&.children&.first&.add_previous_sibling(title.remove.text + "&mdash;")
74
+ def admonition_cleanup(docxml)
75
+ docxml.xpath("//div[@class = 'Admonition'][title]").each do |d|
76
+ title = d.at("./title")
77
+ n = title.next_element
78
+ n&.children&.first
79
+ &.add_previous_sibling("#{title.remove.text}&mdash;")
80
+ end
81
+ docxml
77
82
  end
78
- docxml
79
- end
80
83
 
81
- def example_cleanup(docxml)
82
- docxml.xpath("//table[@class = 'example']//p[not(@class)]").each do |p|
83
- p["class"] = "example"
84
+ def example_cleanup(docxml)
85
+ docxml.xpath("//table[@class = 'example']//p[not(@class)]").each do |p|
86
+ p["class"] = "example"
87
+ end
88
+ docxml
84
89
  end
85
- docxml
86
- end
87
90
 
88
- def figure_get_or_make_dl(elem)
89
- dl = elem.at(".//dl")
90
- if dl.nil?
91
- elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
91
+ def figure_get_or_make_dl(elem)
92
92
  dl = elem.at(".//dl")
93
+ if dl.nil?
94
+ elem.add_child("<p><b>#{@i18n.key}</b></p><dl></dl>")
95
+ dl = elem.at(".//dl")
96
+ end
97
+ dl
93
98
  end
94
- dl
95
- end
96
99
 
97
- FIGURE_WITH_FOOTNOTES =
98
- "//div[@class = 'figure'][descendant::aside]"\
99
- "[not(descendant::div[@class = 'figure'])]".freeze
100
-
101
- def figure_aside_process(elem, aside, key)
102
- # get rid of footnote link, it is in diagram
103
- elem&.at("./a[@class='TableFootnoteRef']")&.remove
104
- fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
105
- dt = key.add_child("<dt></dt>").first
106
- dd = key.add_child("<dd></dd>").first
107
- fnref.parent = dt
108
- aside.xpath(".//p").each do |a|
109
- a.delete("class")
110
- a.parent = dd
100
+ FIGURE_WITH_FOOTNOTES =
101
+ "//div[@class = 'figure'][descendant::aside]"\
102
+ "[not(descendant::div[@class = 'figure'])]".freeze
103
+
104
+ def figure_aside_process(elem, aside, key)
105
+ # get rid of footnote link, it is in diagram
106
+ elem&.at("./a[@class='TableFootnoteRef']")&.remove
107
+ fnref = elem.at(".//span[@class='TableFootnoteRef']/..")
108
+ dt = key.add_child("<dt></dt>").first
109
+ dd = key.add_child("<dd></dd>").first
110
+ fnref.parent = dt
111
+ aside.xpath(".//p").each do |a|
112
+ a.delete("class")
113
+ a.parent = dd
114
+ end
111
115
  end
112
- end
113
116
 
114
- # move footnotes into key, and get rid of footnote reference
115
- # since it is in diagram
116
- def figure_cleanup(docxml)
117
- docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
118
- next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
117
+ # move footnotes into key, and get rid of footnote reference
118
+ # since it is in diagram
119
+ def figure_cleanup(docxml)
120
+ docxml.xpath(FIGURE_WITH_FOOTNOTES).each do |f|
121
+ next unless f.at(".//aside[not(ancestor::p[@class = 'FigureTitle'])]")
119
122
 
120
- key = figure_get_or_make_dl(f)
121
- f.xpath(".//aside").each do |aside|
122
- figure_aside_process(f, aside, key)
123
+ key = figure_get_or_make_dl(f)
124
+ f.xpath(".//aside").each do |aside|
125
+ figure_aside_process(f, aside, key)
126
+ end
123
127
  end
128
+ docxml
124
129
  end
125
- docxml
126
- end
127
130
 
128
- def inline_header_cleanup(docxml)
129
- docxml.xpath('//span[@class="zzMoveToFollowing"]').each do |x|
130
- x.delete("class")
131
- n = x.next_element
132
- if n.nil?
133
- x.name = "p"
134
- else
135
- n.children.first.previous = x.remove
131
+ def inline_header_cleanup(docxml)
132
+ docxml.xpath('//span[@class="zzMoveToFollowing"]').each do |x|
133
+ x.delete("class")
134
+ n = x.next_element
135
+ if n.nil?
136
+ x.name = "p"
137
+ else
138
+ n.children.first.previous = x.remove
139
+ end
136
140
  end
141
+ docxml
137
142
  end
138
- docxml
139
- end
140
143
 
141
- def footnote_cleanup(docxml)
142
- docxml.xpath('//a[@class = "FootnoteRef"]/sup').each_with_index do |x, i|
143
- x.content = (i + 1).to_s
144
+ def footnote_cleanup(docxml)
145
+ docxml.xpath('//a[@class = "FootnoteRef"]/sup')
146
+ .each_with_index do |x, i|
147
+ x.content = (i + 1).to_s
148
+ end
149
+ docxml
144
150
  end
145
- docxml
146
- end
147
151
 
148
- def merge_fnref_into_fn_text(elem)
149
- fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
150
- n = fn.next_element
151
- n&.children&.first&.add_previous_sibling(fn.remove)
152
- end
152
+ def merge_fnref_into_fn_text(elem)
153
+ fn = elem.at('.//span[@class="TableFootnoteRef"]/..')
154
+ n = fn.next_element
155
+ n&.children&.first&.add_previous_sibling(fn.remove)
156
+ end
153
157
 
154
- # preempt html2doc putting MsoNormal under TableFootnote class
155
- def table_footnote_cleanup(docxml)
156
- docxml.xpath("//table[descendant::aside]").each do |t|
157
- t.xpath(".//aside").each do |a|
158
- merge_fnref_into_fn_text(a)
159
- a.name = "div"
160
- a["class"] = "TableFootnote"
161
- t << a.remove
158
+ # preempt html2doc putting MsoNormal under TableFootnote class
159
+ def table_footnote_cleanup(docxml)
160
+ docxml.xpath("//table[descendant::aside]").each do |t|
161
+ t.xpath(".//aside").each do |a|
162
+ merge_fnref_into_fn_text(a)
163
+ a.name = "div"
164
+ a["class"] = "TableFootnote"
165
+ t << a.remove
166
+ end
167
+ end
168
+ docxml.xpath("//p[not(self::*[@class])]"\
169
+ "[ancestor::*[@class = 'TableFootnote']]").each do |p|
170
+ p["class"] = "TableFootnote"
162
171
  end
163
172
  end
164
- docxml.xpath("//p[not(self::*[@class])]"\
165
- "[ancestor::*[@class = 'TableFootnote']]").each do |p|
166
- p["class"] = "TableFootnote"
167
- end
168
- end
169
173
 
170
- def remove_bottom_border(cell)
171
- cell["style"] =
172
- cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
173
- end
174
+ def remove_bottom_border(cell)
175
+ cell["style"] =
176
+ cell["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;")
177
+ end
174
178
 
175
- def table_get_or_make_tfoot(table)
176
- tfoot = table.at(".//tfoot")
177
- if tfoot.nil?
178
- table.add_child("<tfoot></tfoot>")
179
+ def table_get_or_make_tfoot(table)
179
180
  tfoot = table.at(".//tfoot")
180
- else
181
- tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
181
+ if tfoot.nil?
182
+ table.add_child("<tfoot></tfoot>")
183
+ tfoot = table.at(".//tfoot")
184
+ else
185
+ tfoot.xpath(".//td | .//th").each { |td| remove_bottom_border(td) }
186
+ end
187
+ tfoot
182
188
  end
183
- tfoot
184
- end
185
189
 
186
- def new_fullcolspan_row(table, tfoot)
187
- # how many columns in the table?
188
- cols = 0
189
- table.at(".//tr").xpath("./td | ./th").each do |td|
190
- cols += (td["colspan"] ? td["colspan"].to_i : 1)
190
+ def new_fullcolspan_row(table, tfoot)
191
+ # how many columns in the table?
192
+ cols = 0
193
+ table.at(".//tr").xpath("./td | ./th").each do |td|
194
+ cols += (td["colspan"] ? td["colspan"].to_i : 1)
195
+ end
196
+ style =
197
+ %{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
198
+ tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
199
+ tfoot.xpath(".//td").last
191
200
  end
192
- style =
193
- %{border-top:0pt;border-bottom:#{IsoDoc::Function::Table::SW} 1.5pt;}
194
- tfoot.add_child("<tr><td colspan='#{cols}' style='#{style}'/></tr>")
195
- tfoot.xpath(".//td").last
196
- end
197
201
 
198
- def table_note_cleanup(docxml)
199
- docxml.xpath("//table[div[@class = 'Note' or "\
200
- "@class = 'TableFootnote']]").each do |t|
201
- tfoot = table_get_or_make_tfoot(t)
202
- insert_here = new_fullcolspan_row(t, tfoot)
203
- t.xpath("div[@class = 'Note' or @class = 'TableFootnote']").each do |d|
204
- d.parent = insert_here
202
+ def table_note_cleanup(docxml)
203
+ docxml.xpath("//table[div[@class = 'Note' or "\
204
+ "@class = 'TableFootnote']]").each do |t|
205
+ tfoot = table_get_or_make_tfoot(t)
206
+ insert_here = new_fullcolspan_row(t, tfoot)
207
+ t.xpath("div[@class = 'Note' or @class = 'TableFootnote']")
208
+ .each do |d|
209
+ d.parent = insert_here
210
+ end
205
211
  end
206
212
  end
207
- end
208
213
 
209
- def table_cleanup(docxml)
210
- table_footnote_cleanup(docxml)
211
- table_note_cleanup(docxml)
212
- table_long_strings_cleanup(docxml)
213
- docxml
214
- end
214
+ def table_cleanup(docxml)
215
+ table_footnote_cleanup(docxml)
216
+ table_note_cleanup(docxml)
217
+ table_long_strings_cleanup(docxml)
218
+ docxml
219
+ end
215
220
 
216
- def symbols_cleanup(docxml); end
221
+ def symbols_cleanup(docxml); end
217
222
 
218
- def table_footnote_reference_format(link)
219
- link
220
- end
223
+ def table_footnote_reference_format(link)
224
+ link
225
+ end
221
226
 
222
- def footnote_reference_format(link)
223
- link
227
+ def footnote_reference_format(link)
228
+ link
229
+ end
224
230
  end
225
231
  end
226
232
  end
@@ -1,147 +1,149 @@
1
1
  require_relative "inline_simple"
2
2
 
3
- module IsoDoc::Function
4
- module Inline
5
- def link_parse(node, out)
6
- url = node["target"]
7
- node["updatetype"] == "true" and url = suffix_url(url)
8
- out.a **attr_code(href: url, title: node["alt"]) do |l|
9
- if node.text.empty?
10
- l << node["target"].sub(/^mailto:/, "")
11
- else node.children.each { |n| parse(n, l) }
3
+ module IsoDoc
4
+ module Function
5
+ module Inline
6
+ def link_parse(node, out)
7
+ url = node["target"]
8
+ node["updatetype"] == "true" and url = suffix_url(url)
9
+ out.a **attr_code(href: url, title: node["alt"]) do |l|
10
+ if node.text.empty?
11
+ l << node["target"].sub(/^mailto:/, "")
12
+ else node.children.each { |n| parse(n, l) }
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- def callout_parse(node, out)
17
- out << " &lt;#{node.text}&gt;"
18
- end
17
+ def callout_parse(node, out)
18
+ out << " &lt;#{node.text}&gt;"
19
+ end
19
20
 
20
- def no_locality_parse(node, out)
21
- node.children.each do |n|
22
- parse(n, out) unless %w{locality localityStack}.include? n.name
21
+ def no_locality_parse(node, out)
22
+ node.children.each do |n|
23
+ parse(n, out) unless %w{locality localityStack}.include? n.name
24
+ end
23
25
  end
24
- end
25
26
 
26
- def xref_parse(node, out)
27
- target = if /#/.match?(node["target"])
28
- node["target"].sub(/#/, ".html#")
29
- else
30
- "##{node['target']}"
31
- end
32
- out.a(**{ "href": target }) { |l| no_locality_parse(node, l) }
33
- end
27
+ def xref_parse(node, out)
28
+ target = if /#/.match?(node["target"])
29
+ node["target"].sub(/#/, ".html#")
30
+ else
31
+ "##{node['target']}"
32
+ end
33
+ out.a(**{ href: target }) { |l| no_locality_parse(node, l) }
34
+ end
34
35
 
35
- def suffix_url(url)
36
- return url if %r{^https?://}.match?(url)
37
- return url unless File.extname(url).empty?
36
+ def suffix_url(url)
37
+ return url if %r{^https?://}.match?(url)
38
+ return url unless File.extname(url).empty?
38
39
 
39
- url.sub(/#{File.extname(url)}$/, ".html")
40
- end
40
+ url.sub(/#{File.extname(url)}$/, ".html")
41
+ end
41
42
 
42
- def eref_target(node)
43
- href = "##{node['bibitemid']}"
44
- url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
45
- "uri[@type = 'citation']"))
46
- return href unless url
43
+ def eref_target(node)
44
+ href = "##{node['bibitemid']}"
45
+ url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
46
+ "uri[@type = 'citation']"))
47
+ return href unless url
47
48
 
48
- href = suffix_url(url.text)
49
- anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
50
- anchor and href += "##{anchor}"
51
- href
52
- end
49
+ href = suffix_url(url.text)
50
+ anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
51
+ anchor and href += "##{anchor}"
52
+ href
53
+ end
53
54
 
54
- def eref_parse(node, out)
55
- href = eref_target(node)
56
- if node["type"] == "footnote"
57
- out.sup do |s|
58
- s.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
55
+ def eref_parse(node, out)
56
+ href = eref_target(node)
57
+ if node["type"] == "footnote"
58
+ out.sup do |s|
59
+ s.a(**{ href: href }) { |l| no_locality_parse(node, l) }
60
+ end
61
+ else
62
+ out.a(**{ href: href }) { |l| no_locality_parse(node, l) }
59
63
  end
60
- else
61
- out.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
62
64
  end
63
- end
64
65
 
65
- def origin_parse(node, out)
66
- if t = node.at(ns("./termref"))
67
- termrefelem_parse(t, out)
68
- else
69
- eref_parse(node, out)
66
+ def origin_parse(node, out)
67
+ if t = node.at(ns("./termref"))
68
+ termrefelem_parse(t, out)
69
+ else
70
+ eref_parse(node, out)
71
+ end
70
72
  end
71
- end
72
73
 
73
- def termrefelem_parse(node, out)
74
- if node.text.strip.empty?
75
- out << "Termbase #{node['base']}, term ID #{node['target']}"
76
- else
77
- node.children.each { |n| parse(n, out) }
74
+ def termrefelem_parse(node, out)
75
+ if node.text.strip.empty?
76
+ out << "Termbase #{node['base']}, term ID #{node['target']}"
77
+ else
78
+ node.children.each { |n| parse(n, out) }
79
+ end
78
80
  end
79
- end
80
81
 
81
- def stem_parse(node, out)
82
- ooml = case node["type"]
83
- when "AsciiMath"
84
- "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
82
+ def stem_parse(node, out)
83
+ ooml = case node["type"]
84
+ when "AsciiMath"
85
+ "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
85
86
  "#{@closemathdelim}"
86
- when "MathML" then node.first_element_child.to_s
87
- else HTMLEntities.new.encode(node.text)
88
- end
89
- out.span **{ class: "stem" } do |span|
90
- span.parent.add_child ooml
87
+ when "MathML" then node.first_element_child.to_s
88
+ else HTMLEntities.new.encode(node.text)
89
+ end
90
+ out.span **{ class: "stem" } do |span|
91
+ span.parent.add_child ooml
92
+ end
91
93
  end
92
- end
93
94
 
94
- def image_title_parse(out, caption)
95
- unless caption.nil?
96
- out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
97
- p.b { |b| b << caption.to_s }
95
+ def image_title_parse(out, caption)
96
+ unless caption.nil?
97
+ out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
98
+ p.b { |b| b << caption.to_s }
99
+ end
98
100
  end
99
101
  end
100
- end
101
102
 
102
- def image_parse(node, out, caption)
103
- attrs = { src: node["src"],
104
- height: node["height"] || "auto",
105
- width: node["width"] || "auto",
106
- title: node["title"],
107
- alt: node["alt"] }
108
- out.img **attr_code(attrs)
109
- image_title_parse(out, caption)
110
- end
103
+ def image_parse(node, out, caption)
104
+ attrs = { src: node["src"],
105
+ height: node["height"] || "auto",
106
+ width: node["width"] || "auto",
107
+ title: node["title"],
108
+ alt: node["alt"] }
109
+ out.img **attr_code(attrs)
110
+ image_title_parse(out, caption)
111
+ end
111
112
 
112
- def smallcap_parse(node, xml)
113
- xml.span **{ style: "font-variant:small-caps;" } do |s|
114
- node.children.each { |n| parse(n, s) }
113
+ def smallcap_parse(node, xml)
114
+ xml.span **{ style: "font-variant:small-caps;" } do |s|
115
+ node.children.each { |n| parse(n, s) }
116
+ end
115
117
  end
116
- end
117
118
 
118
- def text_parse(node, out)
119
- return if node.nil? || node.text.nil?
119
+ def text_parse(node, out)
120
+ return if node.nil? || node.text.nil?
120
121
 
121
- text = node.to_s
122
- if in_sourcecode
123
- text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;")
124
- .gsub(/ (?= )/, "&nbsp;")
122
+ text = node.to_s
123
+ if in_sourcecode
124
+ text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;")
125
+ .gsub(/ (?= )/, "&nbsp;")
126
+ end
127
+ out << text
125
128
  end
126
- out << text
127
- end
128
129
 
129
- def add_parse(node, out)
130
- out.span **{ class: "addition" } do |e|
131
- node.children.each { |n| parse(n, e) }
130
+ def add_parse(node, out)
131
+ out.span **{ class: "addition" } do |e|
132
+ node.children.each { |n| parse(n, e) }
133
+ end
132
134
  end
133
- end
134
135
 
135
- def del_parse(node, out)
136
- out.span **{ class: "deletion" } do |e|
137
- node.children.each { |n| parse(n, e) }
136
+ def del_parse(node, out)
137
+ out.span **{ class: "deletion" } do |e|
138
+ node.children.each { |n| parse(n, e) }
139
+ end
138
140
  end
139
- end
140
141
 
141
- def error_parse(node, out)
142
- text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
143
- out.para do |p|
144
- p.b(**{ role: "strong" }) { |e| e << text }
142
+ def error_parse(node, out)
143
+ text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
144
+ out.para do |p|
145
+ p.b(**{ role: "strong" }) { |e| e << text }
146
+ end
145
147
  end
146
148
  end
147
149
  end