isodoc 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba10d3ff61b6c99d2251fd1d8e868bf09aea5dde1da505bc1745003778f8750d
4
- data.tar.gz: b758cac0f031d6a16c95ba8dd05c963bf227438d64d63f1f3146dd745d5c42e9
3
+ metadata.gz: 5f122ad0105340afb41607b8639eb00b7205328f9bddad0a5a3726e9644c912e
4
+ data.tar.gz: 04b386a592680a3315ed3d55e7c6716bc177fd628a8d67f520e224b1a4d4de5f
5
5
  SHA512:
6
- metadata.gz: 1ba1187b3202d8b8ef7d8c0376ba6cd100230a0cbe889cfaa729510f174cdbfba884b2ca2b5607525b53391b83a007313e21427539aa8c42d604d295b90feb3b
7
- data.tar.gz: 0b15b2d4bee5c08e2a0989eba6909d37827f67943eb8f0e86f9815f202ca7f408955b1905c7d041e32ae1433ddc1fa99e7fdecf4bf49c0174ee194731104135f
6
+ metadata.gz: 6fef982e2095471e35cc7235a3bc5712066845fd4302131e9760e8d10da548ec73b40f344816077b915b63d93d32cb5b459507ad2133ac52da257a6230e99353
7
+ data.tar.gz: cbbaa050b52517cf272d7d0da4d875075e094b3dcda074a89c55945ceedb6c357914f9e9be0cd09e45ac9d6ace9f61f71b8f9d2ccb5c8d3ebb5ba4fd9251e632
@@ -124,6 +124,35 @@ a.FootnoteRef + a.FootnoteRef:before {
124
124
  color: red;
125
125
  text-decoration: line-through; }
126
126
 
127
+ /* code highlighting with line numbers */
128
+ table.rouge-line-table td.rouge-gutter {
129
+ -moz-user-select: none;
130
+ -ms-user-select: none;
131
+ -webkit-user-select: none;
132
+ user-select: none;
133
+ padding-right: 1em; }
134
+
135
+ table.rouge-line-table td.rouge-code {
136
+ -moz-user-select: all;
137
+ -ms-user-select: all;
138
+ -webkit-user-select: all;
139
+ user-select: all; }
140
+
141
+ table.rouge-line-table,
142
+ table.rouge-line-table th,
143
+ table.rouge-line-table td {
144
+ width: auto;
145
+ border: none;
146
+ margin: 0;
147
+ padding: 0;
148
+ font-size: 100%; }
149
+
150
+ table.rouge-line-table pre {
151
+ margin: 0;
152
+ padding: 0;
153
+ overflow-x: visible;
154
+ font-size: 100%; }
155
+
127
156
  #standard-band {
128
157
  background-color: #0AC442; }
129
158
 
@@ -45,3 +45,12 @@ span.addition {
45
45
  span.deletion {
46
46
  color: red;
47
47
  text-decoration: line-through; }
48
+
49
+ table.rouge-line-table {
50
+ border: none;
51
+ mso-border-alt: none;
52
+ mso-border-insideh: none;
53
+ mso-border-insidev: none; }
54
+
55
+ td.rouge-code p.Sourcecode {
56
+ margin: 0px; }
@@ -42,3 +42,14 @@ span.deletion {
42
42
  color: red;
43
43
  text-decoration: line-through;
44
44
  }
45
+
46
+ table.rouge-line-table {
47
+ border:none;
48
+ mso-border-alt:none;
49
+ mso-border-insideh:none;
50
+ mso-border-insidev:none;
51
+ }
52
+
53
+ td.rouge-code p.Sourcecode {
54
+ margin: 0px;
55
+ }
@@ -123,3 +123,32 @@ a.FootnoteRef + a.FootnoteRef:before {
123
123
  .deletion {
124
124
  color: red;
125
125
  text-decoration: line-through; }
126
+
127
+ /* code highlighting with line numbers */
128
+ table.rouge-line-table td.rouge-gutter {
129
+ -moz-user-select: none;
130
+ -ms-user-select: none;
131
+ -webkit-user-select: none;
132
+ user-select: none;
133
+ padding-right: 1em; }
134
+
135
+ table.rouge-line-table td.rouge-code {
136
+ -moz-user-select: all;
137
+ -ms-user-select: all;
138
+ -webkit-user-select: all;
139
+ user-select: all; }
140
+
141
+ table.rouge-line-table,
142
+ table.rouge-line-table th,
143
+ table.rouge-line-table td {
144
+ width: auto;
145
+ border: none;
146
+ margin: 0;
147
+ padding: 0;
148
+ font-size: 100%; }
149
+
150
+ table.rouge-line-table pre {
151
+ margin: 0;
152
+ padding: 0;
153
+ overflow-x: visible;
154
+ font-size: 100%; }
@@ -152,3 +152,37 @@ a.FootnoteRef + a.FootnoteRef:before {
152
152
  color: red;
153
153
  text-decoration: line-through;
154
154
  }
155
+
156
+ /* code highlighting with line numbers */
157
+
158
+ table.rouge-line-table td.rouge-gutter {
159
+ -moz-user-select: none;
160
+ -ms-user-select: none;
161
+ -webkit-user-select: none;
162
+ user-select: none;
163
+ padding-right: 1em;
164
+ }
165
+
166
+ table.rouge-line-table td.rouge-code {
167
+ -moz-user-select: all;
168
+ -ms-user-select: all;
169
+ -webkit-user-select: all;
170
+ user-select: all;
171
+ }
172
+
173
+ table.rouge-line-table,
174
+ table.rouge-line-table th,
175
+ table.rouge-line-table td {
176
+ width: auto;
177
+ border: none;
178
+ margin: 0;
179
+ padding: 0;
180
+ font-size: 100%;
181
+ }
182
+
183
+ table.rouge-line-table pre {
184
+ margin: 0;
185
+ padding: 0;
186
+ overflow-x: visible;
187
+ font-size: 100%;
188
+ }
@@ -0,0 +1,39 @@
1
+ sourcecode table td { padding: 5px; }
2
+ sourcecode table pre { margin: 0; }
3
+ sourcecode, sourcecode .w {
4
+ color: #444444;
5
+ }
6
+ sourcecode .cp {
7
+ color: #CC00A3;
8
+ }
9
+ sourcecode .cs {
10
+ color: #CC00A3;
11
+ }
12
+ sourcecode .c, sourcecode .ch, sourcecode .cd, sourcecode .cm, sourcecode .cpf, sourcecode .c1 {
13
+ color: #FF0000;
14
+ }
15
+ sourcecode .kc {
16
+ color: #C34E00;
17
+ }
18
+ sourcecode .kd {
19
+ color: #0000FF;
20
+ }
21
+ sourcecode .kr {
22
+ color: #007575;
23
+ }
24
+ sourcecode .k, sourcecode .kn, sourcecode .kp, sourcecode .kt, sourcecode .kv {
25
+ color: #0000FF;
26
+ }
27
+ sourcecode .s, sourcecode .sb, sourcecode .sc, sourcecode .ld, sourcecode .sd, sourcecode .s2, sourcecode .se, sourcecode .sh, sourcecode .si, sourcecode .sx, sourcecode .sr, sourcecode .s1, sourcecode .ss {
28
+ color: #009C00;
29
+ }
30
+ sourcecode .sa {
31
+ color: #0000FF;
32
+ }
33
+ sourcecode .nb, sourcecode .bp {
34
+ color: #C34E00;
35
+ }
36
+ sourcecode .nt {
37
+ color: #0000FF;
38
+ }
39
+
@@ -65,6 +65,6 @@
65
65
  padding: 1em;
66
66
  }
67
67
  td.header {
68
- font-weigth: 400;
68
+ font-weight: 400;
69
69
  }
70
70
  }
@@ -6,19 +6,19 @@ module IsoDoc
6
6
  @annotation = false
7
7
 
8
8
  def middle_title(_isoxml, out)
9
- out.p(**{ class: "zzSTDTitle1" }) { |p| p << @meta.get[:doctitle] }
9
+ out.p(class: "zzSTDTitle1") { |p| p << @meta.get[:doctitle] }
10
10
  end
11
11
 
12
12
  def figure_name_parse(_node, div, name)
13
13
  return if name.nil?
14
14
 
15
- div.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
15
+ div.p class: "FigureTitle", style: "text-align:center;" do |p|
16
16
  name.children.each { |n| parse(n, p) }
17
17
  end
18
18
  end
19
19
 
20
20
  def figure_key(out)
21
- out.p **{ style: "page-break-after:avoid;" } do |p|
21
+ out.p style: "page-break-after:avoid;" do |p|
22
22
  p.b { |b| b << @i18n.key }
23
23
  end
24
24
  end
@@ -63,7 +63,7 @@ module IsoDoc
63
63
  def sourcecode_name_parse(_node, div, name)
64
64
  return if name.nil?
65
65
 
66
- div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
66
+ div.p class: "SourceTitle", style: "text-align:center;" do |p|
67
67
  name.children.each { |n| parse(n, p) }
68
68
  end
69
69
  end
@@ -75,13 +75,19 @@ module IsoDoc
75
75
  def sourcecode_parse(node, out)
76
76
  name = node.at(ns("./name"))
77
77
  out.p **sourcecode_attrs(node) do |div|
78
- @sourcecode = true unless node.at(ns(".//sourcecode"))
79
- node.children.each { |n| parse(n, div) unless n.name == "name" }
80
- @sourcecode = false
78
+ sourcecode_parse1(node, div)
81
79
  end
82
80
  sourcecode_name_parse(node, out, name)
83
81
  end
84
82
 
83
+ def sourcecode_parse1(node, div)
84
+ @sourcecode = "pre"
85
+ node.at(ns(".//table")) || !node.ancestors("table").empty? and
86
+ @sourcecode = "table"
87
+ node.children.each { |n| parse(n, div) unless n.name == "name" }
88
+ @sourcecode = false
89
+ end
90
+
85
91
  def pre_parse(node, out)
86
92
  out.pre node.text, **attr_code(id: node["id"])
87
93
  end
@@ -89,18 +95,22 @@ module IsoDoc
89
95
  def annotation_parse(node, out)
90
96
  @sourcecode = false
91
97
  @annotation = true
92
- node.at("./preceding-sibling::*[local-name() = 'annotation']") or
93
- out << "<br/>"
94
- callout = node.at(ns("//callout[@target='#{node['id']}']"))
95
- out << "<br/>&lt;#{callout.text}&gt; "
96
- out << node&.children&.text&.strip
97
- @annotation = false
98
+ out.div class: "annotation" do |div|
99
+ #node.at("./preceding-sibling::*[local-name() = 'annotation']") or
100
+ # div << "<br/>"
101
+ callout = node.at(ns("//callout[@target='#{node['id']}']"))
102
+ div << "<span class='c'>&lt;#{callout.text}&gt;</span> "
103
+ div << "<span class='c'>#{node.children&.text&.strip}</span>"
104
+ node.at("./following-sibling::*[local-name() = 'annotation']") and
105
+ div << "<br/>"
106
+ @annotation = false
107
+ end
98
108
  end
99
109
 
100
110
  def formula_where(dlist, out)
101
111
  return unless dlist
102
112
 
103
- out.p **{ style: "page-break-after:avoid;" } do |p|
113
+ out.p style: "page-break-after:avoid;" do |p|
104
114
  p << @i18n.where
105
115
  end
106
116
  parse(dlist, out)
@@ -168,7 +178,7 @@ module IsoDoc
168
178
  source = node.at(ns("./source"))
169
179
  return if author.nil? && source.nil?
170
180
 
171
- out.p **{ class: "QuoteAttribution" } do |p|
181
+ out.p class: "QuoteAttribution" do |p|
172
182
  p << "&#x2014; #{author.text}" if author
173
183
  p << ", " if author && source
174
184
  eref_parse(source, p) if source
@@ -198,7 +208,7 @@ module IsoDoc
198
208
  end
199
209
 
200
210
  def toc_parse(node, out)
201
- out.div **{ class: "toc" } do |div|
211
+ out.div class: "toc" do |div|
202
212
  node.children.each { |n| parse(n, div) }
203
213
  end
204
214
  end
@@ -42,7 +42,7 @@ module IsoDoc
42
42
  else
43
43
  "##{node['target']}"
44
44
  end
45
- out.a(**{ href: target }) { |l| no_locality_parse(node, l) }
45
+ out.a(href: target) { |l| no_locality_parse(node, l) }
46
46
  end
47
47
 
48
48
  def suffix_url(url)
@@ -77,10 +77,10 @@ module IsoDoc
77
77
  if href = eref_target(node)
78
78
  if node["type"] == "footnote"
79
79
  out.sup do |s|
80
- s.a(**{ href: href }) { |l| no_locality_parse(node, l) }
80
+ s.a(href: href) { |l| no_locality_parse(node, l) }
81
81
  end
82
82
  else
83
- out.a(**{ href: href }) { |l| no_locality_parse(node, l) }
83
+ out.a(href: href) { |l| no_locality_parse(node, l) }
84
84
  end
85
85
  else no_locality_parse(node, out)
86
86
  end
@@ -109,7 +109,7 @@ module IsoDoc
109
109
  when "LaTeX" then latexmath_parse(node)
110
110
  else HTMLEntities.new.encode(node.text)
111
111
  end
112
- out.span **{ class: "stem" } do |span|
112
+ out.span class: "stem" do |span|
113
113
  span.parent.add_child ooml
114
114
  end
115
115
  end
@@ -123,7 +123,7 @@ module IsoDoc
123
123
  def asciimath_parse(node)
124
124
  a = node.at(ns("./asciimath"))&.text || node.text
125
125
 
126
- "#{@openmathdelim}#{HTMLEntities.new.encode(a)}"\
126
+ "#{@openmathdelim}#{HTMLEntities.new.encode(a)}" \
127
127
  "#{@closemathdelim}"
128
128
  end
129
129
 
@@ -134,7 +134,7 @@ module IsoDoc
134
134
 
135
135
  def image_title_parse(out, caption)
136
136
  unless caption.nil?
137
- out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
137
+ out.p class: "FigureTitle", style: "text-align:center;" do |p|
138
138
  p.b { |b| b << caption.to_s }
139
139
  end
140
140
  end
@@ -151,7 +151,7 @@ module IsoDoc
151
151
  end
152
152
 
153
153
  def smallcap_parse(node, xml)
154
- xml.span **{ style: "font-variant:small-caps;" } do |s|
154
+ xml.span style: "font-variant:small-caps;" do |s|
155
155
  node.children.each { |n| parse(n, s) }
156
156
  end
157
157
  end
@@ -160,21 +160,21 @@ module IsoDoc
160
160
  return if node.nil? || node.text.nil?
161
161
 
162
162
  text = node.to_s
163
- if in_sourcecode
163
+ @sourcecode == "pre" and
164
164
  text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&#xa0;")
165
- .gsub(/ (?= )/, "&#xa0;")
166
- end
165
+ @sourcecode and
166
+ text = text.gsub(/ (?= )/, "&#xa0;")
167
167
  out << text
168
168
  end
169
169
 
170
170
  def add_parse(node, out)
171
- out.span **{ class: "addition" } do |e|
171
+ out.span class: "addition" do |e|
172
172
  node.children.each { |n| parse(n, e) }
173
173
  end
174
174
  end
175
175
 
176
176
  def del_parse(node, out)
177
- out.span **{ class: "deletion" } do |e|
177
+ out.span class: "deletion" do |e|
178
178
  node.children.each { |n| parse(n, e) }
179
179
  end
180
180
  end
@@ -182,7 +182,7 @@ module IsoDoc
182
182
  def error_parse(node, out)
183
183
  text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
184
184
  out.para do |p|
185
- p.b(**{ role: "strong" }) { |e| e << text }
185
+ p.b(role: "strong") { |e| e << text }
186
186
  end
187
187
  end
188
188
  end
@@ -103,7 +103,7 @@ module IsoDoc
103
103
  !header && cell.name == "th" and
104
104
  scope = (cell["rowspan"] ? "rowgroup" : "row")
105
105
  { rowspan: cell["rowspan"], colspan: cell["colspan"],
106
- style: style.gsub(/\n/, ""), scope: scope }
106
+ style: style.gsub(/\n/, ""), scope: scope, class: cell["class"] }
107
107
  end
108
108
 
109
109
  def make_tr_attr_style(row, rowmax, totalrows, _header, bordered)
@@ -8,10 +8,6 @@ module IsoDoc
8
8
  @termdomain = termdomain
9
9
  end
10
10
 
11
- def in_sourcecode
12
- @sourcecode
13
- end
14
-
15
11
  def note?
16
12
  @note
17
13
  end
@@ -37,10 +37,14 @@ module IsoDoc
37
37
  DOCTYPE_HDR = "<!DOCTYPE html SYSTEM " \
38
38
  '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.freeze
39
39
 
40
+ HUGESTRICT =
41
+ Nokogiri::XML::ParseOptions::HUGE |
42
+ Nokogiri::XML::ParseOptions::STRICT
43
+
40
44
  def to_xhtml(xml)
41
45
  xml = to_xhtml_prep(xml)
42
46
  begin
43
- Nokogiri::XML.parse(xml, &:strict)
47
+ Nokogiri::XML.parse(xml, nil, nil, HUGESTRICT)
44
48
  rescue Nokogiri::XML::SyntaxError => e
45
49
  File.open("#{@filename}.#{@format}.err", "w:UTF-8") do |f|
46
50
  f.write xml
@@ -7,7 +7,7 @@ module IsoDoc
7
7
  def convert1(docxml, filename, dir)
8
8
  bibitem_lookup(docxml)
9
9
  noko do |xml|
10
- xml.html **{ lang: @lang.to_s } do |html|
10
+ xml.html lang: @lang.to_s do |html|
11
11
  info docxml, nil
12
12
  populate_css
13
13
  html.head { |head| define_head head, filename, dir }
@@ -19,7 +19,7 @@ module IsoDoc
19
19
  def make_body1(body, _docxml)
20
20
  return if @bare
21
21
 
22
- body.div **{ class: "title-section" } do |div1|
22
+ body.div class: "title-section" do |div1|
23
23
  div1.p { |p| p << "&#xa0;" } # placeholder
24
24
  end
25
25
  section_break(body)
@@ -28,14 +28,14 @@ module IsoDoc
28
28
  def make_body2(body, _docxml)
29
29
  return if @bare
30
30
 
31
- body.div **{ class: "prefatory-section" } do |div2|
31
+ body.div class: "prefatory-section" do |div2|
32
32
  div2.p { |p| p << "&#xa0;" } # placeholder
33
33
  end
34
34
  section_break(body)
35
35
  end
36
36
 
37
37
  def make_body3(body, docxml)
38
- body.div **{ class: "main-section" } do |div3|
38
+ body.div class: "main-section" do |div3|
39
39
  boilerplate docxml, div3
40
40
  preface_block docxml, div3
41
41
  abstract docxml, div3
@@ -51,8 +51,8 @@ module IsoDoc
51
51
 
52
52
  def googlefonts
53
53
  <<~HEAD.freeze
54
- <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet">
55
- <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet">
54
+ <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet"/>
55
+ <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet"/>
56
56
  HEAD
57
57
  end
58
58
 
@@ -66,11 +66,11 @@ module IsoDoc
66
66
  <script type="text/javascript">#{toclevel}</script>
67
67
 
68
68
  <!--Google fonts-->
69
- <link rel="preconnect" href="https://fonts.gstatic.com">#{' '}
69
+ <link rel="preconnect" href="https://fonts.gstatic.com"/>
70
70
  #{googlefonts}
71
71
  <!--Font awesome import for the link icon-->
72
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous">
73
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous">
72
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous"/>
73
+ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous"/>
74
74
  <style class="anchorjs"></style>
75
75
  HEAD
76
76
  end
@@ -91,10 +91,10 @@ module IsoDoc
91
91
 
92
92
  def sourcecode_parse(node, out)
93
93
  name = node.at(ns("./name"))
94
- out.pre **sourcecode_attrs(node).merge(class: "sourcecode") do |div|
95
- @sourcecode = true unless node.at(ns(".//sourcecode"))
96
- node.children.each { |n| parse(n, div) unless n.name == "name" }
97
- @sourcecode = false
94
+ tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre"
95
+ attr = sourcecode_attrs(node).merge(class: "sourcecode")
96
+ out.send tag, **attr do |div|
97
+ sourcecode_parse1(node, div)
98
98
  end
99
99
  sourcecode_name_parse(node, out, name)
100
100
  end
@@ -27,7 +27,20 @@ module IsoDoc
27
27
  def html_cleanup(html)
28
28
  html = term_header(html_footnote_filter(html_preface(htmlstyle(html))))
29
29
  html = footnote_format(footnote_backlinks(html_toc(html)))
30
- mathml(html_list_clean(remove_placeholder_paras(html)))
30
+ html = mathml(html_list_clean(remove_placeholder_paras(html)))
31
+ sourcecode_cleanup(html)
32
+ end
33
+
34
+ def sourcecode_cleanup(html)
35
+ ann = ".//div[@class = 'annotation']"
36
+ html.xpath("//pre[#{ann}] | //div[@class = 'sourcecode'][#{ann}]")
37
+ .each do |p|
38
+ ins = p.after("<pre class='sourcecode'/>").next_element
39
+ p.xpath(ann).each do |d|
40
+ ins << d.remove.children
41
+ end
42
+ end
43
+ html
31
44
  end
32
45
 
33
46
  def remove_placeholder_paras(html)
@@ -1,4 +1,5 @@
1
1
  require_relative "./image"
2
+ require_relative "./sourcecode"
2
3
  require "rouge"
3
4
 
4
5
  module IsoDoc
@@ -26,104 +27,6 @@ module IsoDoc
26
27
  end
27
28
  end
28
29
 
29
- def sourcehighlighter_theme
30
- "igorpro"
31
- end
32
-
33
- def sourcehighlighter_css(docxml)
34
- @sourcehighlighter or return
35
- ins = docxml.at(ns("//misc-container")) ||
36
- docxml.at(ns("//bibdata")).after("<misc-container/>").next_element
37
- x = Rouge::Theme.find(sourcehighlighter_theme)
38
- .render(scope: "sourcecode")
39
- ins << "<source-highlighter-css>#{x}</source-highlighter-css>"
40
- end
41
-
42
- def sourcehighlighter
43
- @sourcehighlighter or return
44
- f = Rouge::Formatters::HTML.new
45
- { formatter: f,
46
- formatter_line: Rouge::Formatters::HTMLTable.new(f, {}) }
47
- end
48
-
49
- def sourcecode(docxml)
50
- sourcehighlighter_css(docxml)
51
- @highlighter = sourcehighlighter
52
- docxml.xpath(ns("//sourcecode")).each do |f|
53
- sourcecode1(f)
54
- end
55
- end
56
-
57
- def sourcecode1(elem)
58
- source_highlight(elem)
59
- source_label(elem)
60
- end
61
-
62
- def source_highlight(elem)
63
- @highlighter or return
64
- markup = source_remove_markup(elem)
65
- p = source_lex(elem)
66
- wrapper, code =
67
- if elem["linenums"] == "true" then sourcecode_table_to_elem(elem, p)
68
- else
69
- r = Nokogiri::XML.fragment(@highlighter[:formatter].format(p))
70
- [r, r]
71
- end
72
- elem.children = source_restore_markup(wrapper, code, markup)
73
- end
74
-
75
- def source_remove_markup(elem)
76
- ret = {}
77
- name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
78
- ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
79
- ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
80
- m << { xml: c.remove.to_xml, line: c.line - elem.line }
81
- end
82
- ret
83
- end
84
-
85
- def source_restore_markup(wrapper, code, markup)
86
- text = source_restore_callouts(code, markup[:call])
87
- ret = if code == wrapper
88
- text
89
- else
90
- code.replace(text)
91
- to_xml(wrapper)
92
- end
93
- "#{markup[:name]}#{ret}#{markup[:ann]}"
94
- end
95
-
96
- def source_restore_callouts(code, callouts)
97
- text = to_xml(code)
98
- text.split(/[\n\r]/).each_with_index do |c, i|
99
- while !callouts.empty? && callouts[0][:line] == i
100
- c.sub!(/\s+$/, " #{callouts[0][:xml]} ")
101
- callouts.shift
102
- end
103
- end.join("\n")
104
- end
105
-
106
- def sourcecode_table_to_elem(elem, tokens)
107
- r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
108
- pre = r.at(".//td[@class = 'rouge-code']/pre")
109
- %w(style).each { |n| elem[n] and pre[n] = elem[n] }
110
- pre.name = "sourcecode"
111
- [r, pre]
112
- end
113
-
114
- def source_lex(elem)
115
- l = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
116
- Rouge::Lexer.find("plaintext"))
117
- l.lex(@c.decode(elem.children.to_xml))
118
- end
119
-
120
- def source_label(elem)
121
- labelled_ancestor(elem) and return
122
- lbl = @xrefs.anchor(elem["id"], :label, false) or return
123
- prefix_name(elem, block_delim,
124
- l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
125
- end
126
-
127
30
  def formula(docxml)
128
31
  docxml.xpath(ns("//formula")).each { |f| formula1(f) }
129
32
  end