polytexnic 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.pull_requests/1371777257 +0 -0
- data/.pull_requests/1371927975 +0 -0
- data/.pull_requests/1372804345 +0 -0
- data/.pull_requests/1374784075 +0 -0
- data/.pull_requests/1375304853 +0 -0
- data/.pull_requests/1375408308 +0 -0
- data/.pull_requests/1375409462 +0 -0
- data/.pull_requests/1375410668 +0 -0
- data/.pull_requests/1375472132 +0 -0
- data/.pull_requests/1375485496 +0 -0
- data/.pull_requests/1375487548 +0 -0
- data/.pull_requests/1375492835 +0 -0
- data/.pull_requests/1375497765 +0 -0
- data/.pull_requests/1375559547 +0 -0
- data/.pull_requests/1375589063 +0 -0
- data/.pull_requests/1375841786 +0 -0
- data/.pull_requests/1376352634 +0 -0
- data/.pull_requests/1376353299 +0 -0
- data/.pull_requests/1376449284 +0 -0
- data/.pull_requests/1376452696 +0 -0
- data/.pull_requests/1376454166 +0 -0
- data/.pull_requests/1376532291 +0 -0
- data/.pull_requests/1376625487 +0 -0
- data/.pull_requests/1376690108 +0 -0
- data/.pull_requests/1376699046 +0 -0
- data/.pull_requests/1376707642 +0 -0
- data/.pull_requests/1377230284 +0 -0
- data/.pull_requests/1379118478 +0 -0
- data/.pull_requests/1379123150 +0 -0
- data/.pull_requests/1380221847 +0 -0
- data/.pull_requests/1380589654 +0 -0
- data/.pull_requests/1380673142 +0 -0
- data/.pull_requests/1380850800 +0 -0
- data/.pull_requests/1381001264 +0 -0
- data/.pull_requests/1381005204 +0 -0
- data/.pull_requests/1381103022 +0 -0
- data/.pull_requests/1381252832 +0 -0
- data/.pull_requests/1381276624 +0 -0
- data/.pull_requests/1381344234 +0 -0
- data/.pull_requests/1381385297 +0 -0
- data/.pull_requests/1381427498 +0 -0
- data/.pull_requests/1381429761 +0 -0
- data/.pull_requests/1381873684 +0 -0
- data/.pull_requests/1382045490 +0 -0
- data/.pull_requests/1382056384 +0 -0
- data/.pull_requests/1382405223 +0 -0
- data/.pull_requests/1382478400 +0 -0
- data/.pull_requests/1382479780 +0 -0
- data/.pull_requests/1382485483 +0 -0
- data/.pull_requests/1382569911 +0 -0
- data/.pull_requests/1382646199 +0 -0
- data/.pull_requests/1382649778 +0 -0
- data/.pull_requests/1382660987 +0 -0
- data/.pull_requests/1382743927 +0 -0
- data/.pull_requests/1382840347 +0 -0
- data/.pull_requests/1383077676 +0 -0
- data/.pull_requests/1383086948 +0 -0
- data/.pull_requests/1383161978 +0 -0
- data/.pull_requests/1383263695 +0 -0
- data/.pull_requests/1383274008 +0 -0
- data/.pull_requests/1383327328 +0 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +15 -0
- data/Guardfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +2 -0
- data/lib/polytexnic/literal.rb +299 -0
- data/lib/polytexnic/postprocessor.rb +28 -0
- data/lib/polytexnic/postprocessors/html.rb +1139 -0
- data/lib/polytexnic/postprocessors/latex.rb +18 -0
- data/lib/polytexnic/postprocessors/polytex.rb +44 -0
- data/lib/polytexnic/preprocessor.rb +23 -0
- data/lib/polytexnic/preprocessors/html.rb +349 -0
- data/lib/polytexnic/preprocessors/latex.rb +43 -0
- data/lib/polytexnic/preprocessors/polytex.rb +127 -0
- data/lib/polytexnic/utils.rb +176 -0
- data/lib/polytexnic/version.rb +3 -0
- data/lib/polytexnic.rb +92 -0
- data/notes/pandoc.md +41 -0
- data/polytexnic.gemspec +28 -0
- data/polytexnic_commands.sty +5 -0
- data/precompiled_binaries/tralics +0 -0
- data/spec/fixtures/code_listing.tex +14 -0
- data/spec/fixtures/figures.tex +8 -0
- data/spec/fixtures/inline_math.html +4 -0
- data/spec/fixtures/inline_math.tex +3 -0
- data/spec/fixtures/math_environments.html +50 -0
- data/spec/fixtures/math_environments.tex +56 -0
- data/spec/fixtures/section_xrefs.tex +9 -0
- data/spec/fixtures/sidebar.tex +10 -0
- data/spec/fixtures/tables.tex +8 -0
- data/spec/fixtures/verbatim_environments.html +11 -0
- data/spec/fixtures/verbatim_environments.tex +13 -0
- data/spec/integration_spec.rb +34 -0
- data/spec/markdown_to_polytex_spec.rb +192 -0
- data/spec/resemble_matcher_spec.rb +69 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/resemble_matcher.rb +100 -0
- data/spec/to_html/asides_spec.rb +42 -0
- data/spec/to_html/chapters_and_sections_spec.rb +268 -0
- data/spec/to_html/characters_and_punctuation_spec.rb +138 -0
- data/spec/to_html/codelistings_spec.rb +70 -0
- data/spec/to_html/core_spec.rb +227 -0
- data/spec/to_html/eqref_spec.rb +32 -0
- data/spec/to_html/footnote_spec.rb +164 -0
- data/spec/to_html/graphics_and_figures_spec.rb +358 -0
- data/spec/to_html/lists_spec.rb +103 -0
- data/spec/to_html/literal_environments/code_spec.rb +141 -0
- data/spec/to_html/literal_environments/math_spec.rb +255 -0
- data/spec/to_html/literal_environments/unicode_spec.rb +12 -0
- data/spec/to_html/literal_environments/verbatim_spec.rb +168 -0
- data/spec/to_html/quotations_and_verse_spec.rb +86 -0
- data/spec/to_html/table_of_contents_spec.rb +93 -0
- data/spec/to_html/table_spec.rb +269 -0
- data/spec/to_html/text_formatting_spec.rb +50 -0
- data/spec/to_latex_spec.rb +197 -0
- data/tasks/bin/ruby_tests +41 -0
- data/tasks/run_tests_with_both_rubies.rake +5 -0
- data/tmp/.gitkeep +0 -0
- metadata +286 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Polytexnic::Pipeline do
|
5
|
+
before(:all) do
|
6
|
+
FileUtils.rm('.highlight_cache') if File.exist?('.highlight_cache')
|
7
|
+
end
|
8
|
+
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
|
9
|
+
|
10
|
+
describe "code blocks" do
|
11
|
+
|
12
|
+
context "without syntax highlighting" do
|
13
|
+
let(:polytex) do <<-'EOS'
|
14
|
+
\begin{code}
|
15
|
+
def foo
|
16
|
+
"bar"
|
17
|
+
end
|
18
|
+
\end{code}
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
|
22
|
+
it { should resemble 'def foo' }
|
23
|
+
it { should resemble '<div class="code">' }
|
24
|
+
it { should_not resemble '\begin{code}' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with syntax highlighting" do
|
28
|
+
let(:polytex) do <<-'EOS'
|
29
|
+
%= lang:ruby
|
30
|
+
\begin{code}
|
31
|
+
def foo
|
32
|
+
"bar"
|
33
|
+
end
|
34
|
+
\end{code}
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
|
38
|
+
it do
|
39
|
+
should resemble <<-'EOS'
|
40
|
+
<div class="code">
|
41
|
+
<div class="highlight">
|
42
|
+
<pre>
|
43
|
+
<span class="k">def</span> <span class="nf">foo</span>
|
44
|
+
<span class="s2">"bar"</span>
|
45
|
+
<span class="k">end</span>
|
46
|
+
</pre>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
EOS
|
50
|
+
end
|
51
|
+
|
52
|
+
it { should resemble '<div class="code">' }
|
53
|
+
it "should not have repeated code divs" do
|
54
|
+
expect(processed_text.scan(/<div class="code">/).length).to eq 1
|
55
|
+
end
|
56
|
+
it { should resemble '<div class="highlight">' }
|
57
|
+
it { should resemble '<pre>' }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with a space after 'lang'" do
|
62
|
+
let(:polytex) do <<-'EOS'
|
63
|
+
%= lang: ruby
|
64
|
+
\begin{code}
|
65
|
+
def foo
|
66
|
+
"bar"
|
67
|
+
end
|
68
|
+
\end{code}
|
69
|
+
EOS
|
70
|
+
end
|
71
|
+
|
72
|
+
it do
|
73
|
+
should resemble <<-'EOS'
|
74
|
+
<div class="code">
|
75
|
+
<div class="highlight">
|
76
|
+
<pre>
|
77
|
+
<span class="k">def</span> <span class="nf">foo</span>
|
78
|
+
<span class="s2">"bar"</span>
|
79
|
+
<span class="k">end</span>
|
80
|
+
</pre>
|
81
|
+
</div>
|
82
|
+
</div>
|
83
|
+
EOS
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "code inclusion" do
|
88
|
+
context "for an existing file" do
|
89
|
+
|
90
|
+
context "with no extension" do
|
91
|
+
let(:polytex) do <<-'EOS'
|
92
|
+
%= <<(Rakefile)
|
93
|
+
EOS
|
94
|
+
end
|
95
|
+
let(:output) do <<-'EOS'
|
96
|
+
<span class="n">require</span>
|
97
|
+
EOS
|
98
|
+
end
|
99
|
+
it { should resemble output }
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with an extension" do
|
103
|
+
let(:polytex) do <<-'EOS'
|
104
|
+
%= <<(spec/to_html/literal_environments/code_spec.rb)
|
105
|
+
EOS
|
106
|
+
end
|
107
|
+
let(:output) do <<-'EOS'
|
108
|
+
<div class="code">
|
109
|
+
<div class="highlight">
|
110
|
+
<pre><span class="c1"># encoding=utf-8</span>
|
111
|
+
EOS
|
112
|
+
end
|
113
|
+
it { should resemble output }
|
114
|
+
it { should_not include '<p></p>' }
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with a custom language override" do
|
118
|
+
let(:polytex) do <<-'EOS'
|
119
|
+
%= << (polytexnic_commands.sty, lang: tex)
|
120
|
+
EOS
|
121
|
+
end
|
122
|
+
let(:output) do <<-'EOS'
|
123
|
+
<span class="c">% Add some custom commands needed by PolyTeXnic.</span>
|
124
|
+
EOS
|
125
|
+
end
|
126
|
+
it { should resemble output }
|
127
|
+
it { should_not include '<p></p>' }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
context "for a nonexistent file" do
|
134
|
+
let(:polytex) do <<-'EOS'
|
135
|
+
%= <<(foobar.rb)
|
136
|
+
EOS
|
137
|
+
end
|
138
|
+
it { should include "ERROR: File 'foobar.rb' does not exist" }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,255 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Polytexnic::Pipeline do
|
5
|
+
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
|
6
|
+
|
7
|
+
describe "display and inline math" do
|
8
|
+
let(:math) do <<-'EOS'
|
9
|
+
\begin{bmatrix}
|
10
|
+
1 & \cdots & 0 \\
|
11
|
+
\vdots & \ddots & \vdots \\
|
12
|
+
2 & \cdots & 0
|
13
|
+
\end{bmatrix}
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:result) do <<-'EOS'
|
18
|
+
\begin{bmatrix}
|
19
|
+
1 & \cdots & 0 \\
|
20
|
+
\vdots & \ddots & \vdots \\
|
21
|
+
2 & \cdots & 0
|
22
|
+
\end{bmatrix}
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
context "TeX displaystyle" do
|
27
|
+
let(:equation) { "$$ #{math} $$"}
|
28
|
+
let(:polytex) { equation }
|
29
|
+
let(:contents) { "\\[ #{result} \\]"}
|
30
|
+
|
31
|
+
it { should resemble contents }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "LaTeX displaystyle" do
|
35
|
+
let(:equation) { "\\[ #{math} \\]"}
|
36
|
+
let(:polytex) { equation }
|
37
|
+
let(:contents) { "\\[ #{result} \\]"}
|
38
|
+
|
39
|
+
it { should resemble contents }
|
40
|
+
|
41
|
+
context "with surrounding text" do
|
42
|
+
let(:polytex) { "lorem\n\\[ #{math} \\]\nipsum" }
|
43
|
+
it { should resemble '<p class="noindent">' }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "TeX inline" do
|
48
|
+
let(:equation) { "$#{math}$"}
|
49
|
+
let(:polytex) { equation }
|
50
|
+
let(:contents) { "\\( #{result} \\)"}
|
51
|
+
|
52
|
+
it { should resemble contents }
|
53
|
+
end
|
54
|
+
|
55
|
+
context "TeX inline with a dollar sign" do
|
56
|
+
let(:equation) { "$#{math} \\mbox{\\$2 bill}$"}
|
57
|
+
let(:polytex) { equation }
|
58
|
+
let(:contents) { "\\( #{result} \\mbox{\\$2 bill} \\)"}
|
59
|
+
|
60
|
+
it { should resemble contents }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "LaTeX inline" do
|
64
|
+
let(:equation) { "\\( #{math} \\)"}
|
65
|
+
let(:polytex) { equation }
|
66
|
+
let(:contents) { "\\( #{result} \\)"}
|
67
|
+
|
68
|
+
it { should resemble contents }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with a space before a dollar sign" do
|
72
|
+
let(:polytex) { "foo $x$ bar" }
|
73
|
+
let(:contents) { "<p>foo <span class=\"inline_math\">\\( x \\)</span> bar" }
|
74
|
+
it { should include contents }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "multiple occurrences of inline math on one line" do
|
79
|
+
let(:polytex) { '$\Omega > 0$ and \( x^2 - 2 \equiv 0 \) should work.' }
|
80
|
+
|
81
|
+
it { should resemble '\Omega' }
|
82
|
+
it { should resemble '\equiv' }
|
83
|
+
it { should resemble '<span class="inline_math">' }
|
84
|
+
it { should resemble '\(' }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "equation environments" do
|
88
|
+
|
89
|
+
shared_examples "an equation environment" do
|
90
|
+
it { should resemble contents }
|
91
|
+
it { should resemble '<div' }
|
92
|
+
it { should resemble 'class="equation"' }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "alone" do
|
96
|
+
let(:equation) do <<-'EOS'
|
97
|
+
\begin{equation}
|
98
|
+
\int_\Omega d\omega = \int_{\partial\Omega} \omega
|
99
|
+
\end{equation}
|
100
|
+
EOS
|
101
|
+
end
|
102
|
+
let(:polytex) { equation }
|
103
|
+
let(:contents) { equation }
|
104
|
+
|
105
|
+
it_behaves_like "an equation environment"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with a label and cross-reference" do
|
109
|
+
let(:equation) do <<-'EOS'
|
110
|
+
\chapter{Foo}
|
111
|
+
\begin{equation}
|
112
|
+
\label{stokes_theorem}
|
113
|
+
\int_\Omega d\omega = \int_{\partial\Omega} \omega
|
114
|
+
\end{equation}
|
115
|
+
|
116
|
+
Eq.~\eqref{stokes_theorem} or \eqref{stokes_theorem}
|
117
|
+
EOS
|
118
|
+
end
|
119
|
+
let(:polytex) { equation }
|
120
|
+
let(:contents) do <<-'EOS'
|
121
|
+
<div id="cid1" data-tralics-id="cid1" class="chapter" data-number="1"><h1><a href="#cid1" class="heading"><span class="number">Chapter 1 </span>Foo</a></h1>
|
122
|
+
<div id="stokes_theorem" data-tralics-id="uid1" data-number="1.1" class="equation">
|
123
|
+
\begin{equation}
|
124
|
+
\label{stokes_theorem}
|
125
|
+
\int_\Omega d\omega = \int_{\partial\Omega} \omega
|
126
|
+
\end{equation}
|
127
|
+
</div>
|
128
|
+
<p class="noindent"><a href="#stokes_theorem" class="hyperref">Eq. (<span class="ref">1.1</span>)</a>
|
129
|
+
or
|
130
|
+
<a href="#stokes_theorem" class="hyperref">(<span class="ref">1.1</span>)</a>
|
131
|
+
</p>
|
132
|
+
EOS
|
133
|
+
end
|
134
|
+
|
135
|
+
it_behaves_like "an equation environment"
|
136
|
+
end
|
137
|
+
|
138
|
+
context "surrounded by text" do
|
139
|
+
let(:equation) do <<-'EOS'
|
140
|
+
\begin{equation}
|
141
|
+
\int_\Omega d\omega = \int_{\partial\Omega} \omega
|
142
|
+
\end{equation}
|
143
|
+
EOS
|
144
|
+
end
|
145
|
+
let(:polytex) { "lorem\n" + equation + "\nipsum" }
|
146
|
+
let(:contents) { equation }
|
147
|
+
|
148
|
+
it_behaves_like "an equation environment"
|
149
|
+
it { should resemble '<p>lorem' }
|
150
|
+
it { should resemble '<p class="noindent">ipsum' }
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "align" do
|
154
|
+
let(:equation) do <<-'EOS'
|
155
|
+
\begin{align}
|
156
|
+
x^2 + y^2 & = 1 \\
|
157
|
+
y & = \sqrt{1 - x^2}.
|
158
|
+
\end{align}
|
159
|
+
EOS
|
160
|
+
end
|
161
|
+
let(:polytex) { equation }
|
162
|
+
let(:contents) do <<-'EOS'
|
163
|
+
\begin{align}
|
164
|
+
x^2 + y^2 & = 1 \\
|
165
|
+
y & = \sqrt{1 - x^2}.
|
166
|
+
\end{align}
|
167
|
+
EOS
|
168
|
+
end
|
169
|
+
|
170
|
+
it_behaves_like "an equation environment"
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "align*" do
|
174
|
+
let(:equation) do <<-'EOS'
|
175
|
+
\begin{align*}
|
176
|
+
x^2 + y^2 & = 1 \\
|
177
|
+
y & = \sqrt{1 - x^2}.
|
178
|
+
\end{align*}
|
179
|
+
EOS
|
180
|
+
end
|
181
|
+
let(:polytex) { equation }
|
182
|
+
let(:contents) do <<-'EOS'
|
183
|
+
\begin{align*}
|
184
|
+
x^2 + y^2 & = 1 \\
|
185
|
+
y & = \sqrt{1 - x^2}.
|
186
|
+
\end{align*}
|
187
|
+
EOS
|
188
|
+
end
|
189
|
+
|
190
|
+
it_behaves_like "an equation environment"
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "aligned" do
|
194
|
+
let(:equation) do <<-'EOS'
|
195
|
+
\begin{equation}
|
196
|
+
\begin{aligned}
|
197
|
+
\nabla \times \vec{\mathbf{B}} -\, \frac1c\,
|
198
|
+
\frac{\partial\vec{\mathbf{E}}}{\partial t} & =
|
199
|
+
\frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & =
|
200
|
+
4 \pi \rho \\
|
201
|
+
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\,
|
202
|
+
\frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
|
203
|
+
\nabla \cdot \vec{\mathbf{B}} & = 0
|
204
|
+
\end{aligned}
|
205
|
+
\end{equation}
|
206
|
+
EOS
|
207
|
+
end
|
208
|
+
let(:polytex) { equation }
|
209
|
+
let(:contents) do <<-'EOS'
|
210
|
+
\begin{equation}
|
211
|
+
\begin{aligned}
|
212
|
+
\nabla \times \vec{\mathbf{B}} -\, \frac1c\,
|
213
|
+
\frac{\partial\vec{\mathbf{E}}}{\partial t} & =
|
214
|
+
\frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} &
|
215
|
+
= 4 \pi \rho \\
|
216
|
+
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\,
|
217
|
+
\frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
|
218
|
+
\nabla \cdot \vec{\mathbf{B}} & = 0
|
219
|
+
\end{aligned}
|
220
|
+
\end{equation}
|
221
|
+
EOS
|
222
|
+
end
|
223
|
+
|
224
|
+
it_behaves_like "an equation environment"
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "equation*" do
|
228
|
+
let(:equation) do <<-'EOS'
|
229
|
+
\begin{equation*}
|
230
|
+
\left.\begin{aligned}
|
231
|
+
dE &= \rho \\
|
232
|
+
d*B &= J + \dot{E}
|
233
|
+
\end{aligned}
|
234
|
+
\right\}
|
235
|
+
\qquad \text{Maxwell}
|
236
|
+
\end{equation*}
|
237
|
+
EOS
|
238
|
+
end
|
239
|
+
let(:polytex) { equation }
|
240
|
+
let(:contents) do <<-'EOS'
|
241
|
+
\begin{equation*}
|
242
|
+
\left.\begin{aligned}
|
243
|
+
dE &= \rho \\
|
244
|
+
d*B &= J + \dot{E}
|
245
|
+
\end{aligned}
|
246
|
+
\right\}
|
247
|
+
\qquad \text{Maxwell}
|
248
|
+
\end{equation*}
|
249
|
+
EOS
|
250
|
+
end
|
251
|
+
|
252
|
+
it_behaves_like "an equation environment"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Polytexnic::Pipeline do
|
5
|
+
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
|
6
|
+
|
7
|
+
describe "non-ASCII Unicode" do
|
8
|
+
let(:polytex) { 'Алексей Разуваев' }
|
9
|
+
it { should include %(<span class="unicode">Алексей</span>) }
|
10
|
+
it { should include %(<span class="unicode">Разуваев</span>) }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Polytexnic::Pipeline do
|
5
|
+
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
|
6
|
+
|
7
|
+
describe "\\verb environments" do
|
8
|
+
let(:polytex) { '\verb+\begin{center}+ \verb-$foo-' }
|
9
|
+
let(:output) do
|
10
|
+
'<span class="inline_verbatim">\begin{center}</span>' +
|
11
|
+
'<span class="inline_verbatim">$foo</span>'
|
12
|
+
end
|
13
|
+
it { should resemble output }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "verbatim environments" do
|
17
|
+
|
18
|
+
context "alone" do
|
19
|
+
let(:polytex) do <<-'EOS'
|
20
|
+
\begin{verbatim}
|
21
|
+
\label{foo:bar}
|
22
|
+
\emph{foo bar} & \\
|
23
|
+
\end{verbatim}
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:output) { '\emph{foo bar} & \\\\' }
|
28
|
+
|
29
|
+
it { should resemble output }
|
30
|
+
it { should resemble '<pre class="verbatim">' }
|
31
|
+
it { should_not resemble '\begin{verbatim}' }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with nesting" do
|
35
|
+
let(:polytex) do <<-'EOS'
|
36
|
+
\begin{verbatim}
|
37
|
+
\begin{verbatim}
|
38
|
+
\emph{foo bar}
|
39
|
+
\end{verbatim}
|
40
|
+
\end{verbatim}
|
41
|
+
lorem ipsum
|
42
|
+
EOS
|
43
|
+
end
|
44
|
+
|
45
|
+
let(:output) do <<-'EOS'
|
46
|
+
\begin{verbatim}
|
47
|
+
\emph{foo bar}
|
48
|
+
\end{verbatim}
|
49
|
+
EOS
|
50
|
+
end
|
51
|
+
|
52
|
+
it { should resemble output }
|
53
|
+
it "should break out of the loop if verbatim count is zero" do
|
54
|
+
expect(processed_text).to resemble 'lorem ipsum'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with missing \end{verbatim}' do
|
59
|
+
let(:polytex) do <<-'EOS'
|
60
|
+
\begin{verbatim}
|
61
|
+
\emph{foo bar}
|
62
|
+
EOS
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise an error" do
|
66
|
+
expect { processed_text }.to raise_error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "containing a code environment" do
|
71
|
+
let(:polytex) do <<-'EOS'
|
72
|
+
\begin{verbatim}
|
73
|
+
\begin{code}
|
74
|
+
\emph{foo bar}
|
75
|
+
\end{code}
|
76
|
+
\end{verbatim}
|
77
|
+
lorem ipsum
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:output) do <<-'EOS'
|
82
|
+
\begin{code}
|
83
|
+
\emph{foo bar}
|
84
|
+
\end{code}
|
85
|
+
EOS
|
86
|
+
end
|
87
|
+
|
88
|
+
it { should resemble output }
|
89
|
+
end
|
90
|
+
|
91
|
+
context "containing a highlighted code environment" do
|
92
|
+
let(:polytex) do <<-'EOS'
|
93
|
+
\begin{verbatim}
|
94
|
+
%= lang:ruby
|
95
|
+
\begin{code}
|
96
|
+
foo ||= bar
|
97
|
+
\end{code}
|
98
|
+
\end{verbatim}
|
99
|
+
lorem ipsum
|
100
|
+
EOS
|
101
|
+
end
|
102
|
+
|
103
|
+
let(:output) do <<-'EOS'
|
104
|
+
%= lang:ruby
|
105
|
+
\begin{code}
|
106
|
+
foo ||= bar
|
107
|
+
\end{code}
|
108
|
+
EOS
|
109
|
+
end
|
110
|
+
|
111
|
+
it { should resemble output }
|
112
|
+
end
|
113
|
+
|
114
|
+
context "containing a code inclusion" do
|
115
|
+
let(:polytex) do <<-'EOS'
|
116
|
+
\begin{verbatim}
|
117
|
+
%= <</path/to/file.rb
|
118
|
+
\end{verbatim}
|
119
|
+
EOS
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:output) do <<-'EOS'
|
123
|
+
%= <</path/to/file.rb
|
124
|
+
EOS
|
125
|
+
end
|
126
|
+
|
127
|
+
it { should resemble output }
|
128
|
+
end
|
129
|
+
|
130
|
+
context "preceded by a highlighted code environment" do
|
131
|
+
let(:polytex) do <<-'EOS'
|
132
|
+
|
133
|
+
%= lang:scheme
|
134
|
+
\begin{code}
|
135
|
+
(define tau 6.283185)
|
136
|
+
\end{code}
|
137
|
+
|
138
|
+
\begin{verbatim}
|
139
|
+
<start-quote/>
|
140
|
+
\end{verbatim}
|
141
|
+
EOS
|
142
|
+
end
|
143
|
+
|
144
|
+
let(:output) do <<-'EOS'
|
145
|
+
<start-quote/>
|
146
|
+
EOS
|
147
|
+
end
|
148
|
+
|
149
|
+
it { should resemble output }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "Verbatim environments" do
|
154
|
+
let(:polytex) do <<-'EOS'
|
155
|
+
\begin{Verbatim}
|
156
|
+
\emph{foo bar}
|
157
|
+
\end{Verbatim}
|
158
|
+
EOS
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:output) { '\emph{foo bar}' }
|
162
|
+
|
163
|
+
it { should resemble output }
|
164
|
+
it { should_not resemble '\begin{Verbatim}' }
|
165
|
+
it { should_not resemble 'rend="tt"' }
|
166
|
+
it { should resemble '<pre class="verbatim">' }
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Polytexnic::Pipeline#to_html' do
|
5
|
+
|
6
|
+
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
|
7
|
+
|
8
|
+
describe "quotations and verse" do
|
9
|
+
describe '\begin{quote}...\end{quote}' do
|
10
|
+
let(:polytex) { '\quote{foo}' }
|
11
|
+
it { should resemble "<blockquote class=\"quote\">foo\n</blockquote>" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "quote environment" do
|
15
|
+
|
16
|
+
context "alone" do
|
17
|
+
let(:polytex) do <<-'EOS'
|
18
|
+
\begin{quote}
|
19
|
+
lorem ipsum
|
20
|
+
|
21
|
+
dolor sit amet
|
22
|
+
\end{quote}
|
23
|
+
EOS
|
24
|
+
end
|
25
|
+
|
26
|
+
it do
|
27
|
+
should resemble <<-'EOS'
|
28
|
+
<blockquote class="quotation">
|
29
|
+
<p>lorem ipsum</p>
|
30
|
+
<p>dolor sit amet</p>
|
31
|
+
</blockquote>
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "nested" do
|
37
|
+
let(:polytex) do <<-'EOS'
|
38
|
+
\begin{quote}
|
39
|
+
lorem ipsum
|
40
|
+
|
41
|
+
\begin{quote}
|
42
|
+
foo bar
|
43
|
+
\end{quote}
|
44
|
+
|
45
|
+
dolor sit amet
|
46
|
+
\end{quote}
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
it do
|
50
|
+
should resemble <<-'EOS'
|
51
|
+
<blockquote class="quotation">
|
52
|
+
<p>lorem ipsum</p>
|
53
|
+
<blockquote class="quotation">
|
54
|
+
<p>foo bar</p>
|
55
|
+
</blockquote>
|
56
|
+
<p>dolor sit amet</p>
|
57
|
+
</blockquote>
|
58
|
+
EOS
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '\verse' do
|
64
|
+
let(:polytex) { '\verse{foo}' }
|
65
|
+
it { should resemble "<blockquote class=\"verse\">foo\n</blockquote>" }
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "verse environment" do
|
69
|
+
let(:polytex) do <<-'EOS'
|
70
|
+
\begin{verse}
|
71
|
+
lorem ipsum\\
|
72
|
+
dolor sit amet
|
73
|
+
\end{verse}
|
74
|
+
EOS
|
75
|
+
end
|
76
|
+
it do
|
77
|
+
should resemble <<-'EOS'
|
78
|
+
<blockquote class="verse">
|
79
|
+
<p>lorem ipsum<span class="break"></span>
|
80
|
+
dolor sit amet</p>
|
81
|
+
</blockquote>
|
82
|
+
EOS
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|