polytexnic 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.pull_requests/1371777257 +0 -0
  4. data/.pull_requests/1371927975 +0 -0
  5. data/.pull_requests/1372804345 +0 -0
  6. data/.pull_requests/1374784075 +0 -0
  7. data/.pull_requests/1375304853 +0 -0
  8. data/.pull_requests/1375408308 +0 -0
  9. data/.pull_requests/1375409462 +0 -0
  10. data/.pull_requests/1375410668 +0 -0
  11. data/.pull_requests/1375472132 +0 -0
  12. data/.pull_requests/1375485496 +0 -0
  13. data/.pull_requests/1375487548 +0 -0
  14. data/.pull_requests/1375492835 +0 -0
  15. data/.pull_requests/1375497765 +0 -0
  16. data/.pull_requests/1375559547 +0 -0
  17. data/.pull_requests/1375589063 +0 -0
  18. data/.pull_requests/1375841786 +0 -0
  19. data/.pull_requests/1376352634 +0 -0
  20. data/.pull_requests/1376353299 +0 -0
  21. data/.pull_requests/1376449284 +0 -0
  22. data/.pull_requests/1376452696 +0 -0
  23. data/.pull_requests/1376454166 +0 -0
  24. data/.pull_requests/1376532291 +0 -0
  25. data/.pull_requests/1376625487 +0 -0
  26. data/.pull_requests/1376690108 +0 -0
  27. data/.pull_requests/1376699046 +0 -0
  28. data/.pull_requests/1376707642 +0 -0
  29. data/.pull_requests/1377230284 +0 -0
  30. data/.pull_requests/1379118478 +0 -0
  31. data/.pull_requests/1379123150 +0 -0
  32. data/.pull_requests/1380221847 +0 -0
  33. data/.pull_requests/1380589654 +0 -0
  34. data/.pull_requests/1380673142 +0 -0
  35. data/.pull_requests/1380850800 +0 -0
  36. data/.pull_requests/1381001264 +0 -0
  37. data/.pull_requests/1381005204 +0 -0
  38. data/.pull_requests/1381103022 +0 -0
  39. data/.pull_requests/1381252832 +0 -0
  40. data/.pull_requests/1381276624 +0 -0
  41. data/.pull_requests/1381344234 +0 -0
  42. data/.pull_requests/1381385297 +0 -0
  43. data/.pull_requests/1381427498 +0 -0
  44. data/.pull_requests/1381429761 +0 -0
  45. data/.pull_requests/1381873684 +0 -0
  46. data/.pull_requests/1382045490 +0 -0
  47. data/.pull_requests/1382056384 +0 -0
  48. data/.pull_requests/1382405223 +0 -0
  49. data/.pull_requests/1382478400 +0 -0
  50. data/.pull_requests/1382479780 +0 -0
  51. data/.pull_requests/1382485483 +0 -0
  52. data/.pull_requests/1382569911 +0 -0
  53. data/.pull_requests/1382646199 +0 -0
  54. data/.pull_requests/1382649778 +0 -0
  55. data/.pull_requests/1382660987 +0 -0
  56. data/.pull_requests/1382743927 +0 -0
  57. data/.pull_requests/1382840347 +0 -0
  58. data/.pull_requests/1383077676 +0 -0
  59. data/.pull_requests/1383086948 +0 -0
  60. data/.pull_requests/1383161978 +0 -0
  61. data/.pull_requests/1383263695 +0 -0
  62. data/.pull_requests/1383274008 +0 -0
  63. data/.pull_requests/1383327328 +0 -0
  64. data/.rspec +2 -0
  65. data/.ruby-gemset +1 -0
  66. data/.ruby-version +1 -0
  67. data/Gemfile +15 -0
  68. data/Guardfile +15 -0
  69. data/LICENSE.txt +22 -0
  70. data/README.md +21 -0
  71. data/Rakefile +2 -0
  72. data/lib/polytexnic/literal.rb +299 -0
  73. data/lib/polytexnic/postprocessor.rb +28 -0
  74. data/lib/polytexnic/postprocessors/html.rb +1139 -0
  75. data/lib/polytexnic/postprocessors/latex.rb +18 -0
  76. data/lib/polytexnic/postprocessors/polytex.rb +44 -0
  77. data/lib/polytexnic/preprocessor.rb +23 -0
  78. data/lib/polytexnic/preprocessors/html.rb +349 -0
  79. data/lib/polytexnic/preprocessors/latex.rb +43 -0
  80. data/lib/polytexnic/preprocessors/polytex.rb +127 -0
  81. data/lib/polytexnic/utils.rb +176 -0
  82. data/lib/polytexnic/version.rb +3 -0
  83. data/lib/polytexnic.rb +92 -0
  84. data/notes/pandoc.md +41 -0
  85. data/polytexnic.gemspec +28 -0
  86. data/polytexnic_commands.sty +5 -0
  87. data/precompiled_binaries/tralics +0 -0
  88. data/spec/fixtures/code_listing.tex +14 -0
  89. data/spec/fixtures/figures.tex +8 -0
  90. data/spec/fixtures/inline_math.html +4 -0
  91. data/spec/fixtures/inline_math.tex +3 -0
  92. data/spec/fixtures/math_environments.html +50 -0
  93. data/spec/fixtures/math_environments.tex +56 -0
  94. data/spec/fixtures/section_xrefs.tex +9 -0
  95. data/spec/fixtures/sidebar.tex +10 -0
  96. data/spec/fixtures/tables.tex +8 -0
  97. data/spec/fixtures/verbatim_environments.html +11 -0
  98. data/spec/fixtures/verbatim_environments.tex +13 -0
  99. data/spec/integration_spec.rb +34 -0
  100. data/spec/markdown_to_polytex_spec.rb +192 -0
  101. data/spec/resemble_matcher_spec.rb +69 -0
  102. data/spec/spec_helper.rb +38 -0
  103. data/spec/support/resemble_matcher.rb +100 -0
  104. data/spec/to_html/asides_spec.rb +42 -0
  105. data/spec/to_html/chapters_and_sections_spec.rb +268 -0
  106. data/spec/to_html/characters_and_punctuation_spec.rb +138 -0
  107. data/spec/to_html/codelistings_spec.rb +70 -0
  108. data/spec/to_html/core_spec.rb +227 -0
  109. data/spec/to_html/eqref_spec.rb +32 -0
  110. data/spec/to_html/footnote_spec.rb +164 -0
  111. data/spec/to_html/graphics_and_figures_spec.rb +358 -0
  112. data/spec/to_html/lists_spec.rb +103 -0
  113. data/spec/to_html/literal_environments/code_spec.rb +141 -0
  114. data/spec/to_html/literal_environments/math_spec.rb +255 -0
  115. data/spec/to_html/literal_environments/unicode_spec.rb +12 -0
  116. data/spec/to_html/literal_environments/verbatim_spec.rb +168 -0
  117. data/spec/to_html/quotations_and_verse_spec.rb +86 -0
  118. data/spec/to_html/table_of_contents_spec.rb +93 -0
  119. data/spec/to_html/table_spec.rb +269 -0
  120. data/spec/to_html/text_formatting_spec.rb +50 -0
  121. data/spec/to_latex_spec.rb +197 -0
  122. data/tasks/bin/ruby_tests +41 -0
  123. data/tasks/run_tests_with_both_rubies.rake +5 -0
  124. data/tmp/.gitkeep +0 -0
  125. metadata +286 -0
@@ -0,0 +1,32 @@
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 'equation \ref' do
8
+
9
+ let(:equation) do <<-'EOS'
10
+ \chapter{Equation test}
11
+
12
+ \[ x^2 \]
13
+
14
+ \begin{equation}
15
+ \label{eq:foobar}
16
+ x
17
+ \end{equation}
18
+
19
+ EOS
20
+ end
21
+
22
+ context 'with \ref{eq:foobar}' do
23
+ let(:polytex) { equation + '\ref{eq:foobar}' }
24
+ it { should include '1.1' }
25
+ end
26
+
27
+ context 'with \eqref{eq:foobar}' do
28
+ let(:polytex) { equation + '\eqref{eq:foobar}' }
29
+ it { should include '(<span class="ref">1.1</span>)' }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,164 @@
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 "first chapter with footnotes" do
9
+ let(:polytex) do <<-'EOS'
10
+ \chapter{Foo \emph{bar}}
11
+ \label{cha:foo}
12
+
13
+ \section{Foobar}
14
+ \label{sec:foobar}
15
+
16
+ Lorem ipsum.\footnote{Cicero}
17
+
18
+ \chapter{Bar}
19
+ \label{cha:bar}
20
+
21
+ Dolor sit amet.
22
+ EOS
23
+ end
24
+
25
+ let(:output) do <<-'EOS'
26
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
27
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span>Foo <em>bar</em></a></h1>
28
+ </div>
29
+ <div id="sec-foobar" data-tralics-id="cid2" class="section" data-number="1.1">
30
+ <h2><a href="#sec-foobar" class="heading"><span class="number">1.1 </span>Foobar</a></h2>
31
+ <p>Lorem ipsum.<sup id="cha-1_footnote-ref-1" class="footnote"><a href="#cha-1_footnote-1">1</a></sup></p>
32
+ </div>
33
+ <div id="cha-1_footnotes">
34
+ <ol class="footnotes">
35
+ <li id="cha-1_footnote-1">
36
+ Cicero <a class="arrow" href="#cha-1_footnote-ref-1">↑</a>
37
+ </li>
38
+ </ol>
39
+ </div>
40
+ <div id="cha-bar" data-tralics-id="cid3" class="chapter" data-number="2">
41
+ <h1><a href="#cha-bar" class="heading"><span class="number">Chapter 2 </span>Bar</a></h1>
42
+ <p>Dolor sit amet.</p>
43
+ </div>
44
+ EOS
45
+ end
46
+ it { should resemble output }
47
+ it "should display the footnotes only once" do
48
+ expect(processed_text.scan(/id="cha-1_footnotes"/).length).to eq 1
49
+ end
50
+ end
51
+
52
+ describe "multiple chapters with footnotes" do
53
+ let(:polytex) do <<-'EOS'
54
+ \chapter{Foo \emph{bar}}
55
+ \label{cha:foo}
56
+
57
+ \section{Foobar}
58
+ \label{sec:foobar}
59
+
60
+ Lorem ipsum.\footnote{Cicero}
61
+
62
+ \chapter{Bar}
63
+ \label{cha:bar}
64
+
65
+ Dolor sit amet.\footnote{\emph{Still} Cicero}
66
+
67
+ Hey Jude.\footnote{Lennon/McCartney}
68
+ EOS
69
+ end
70
+
71
+ let(:output) do <<-'EOS'
72
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
73
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span>Foo <em>bar</em></a></h1>
74
+ </div>
75
+ <div id="sec-foobar" data-tralics-id="cid2" class="section" data-number="1.1">
76
+ <h2><a href="#sec-foobar" class="heading"><span class="number">1.1 </span>Foobar</a></h2>
77
+ <p>Lorem ipsum.<sup id="cha-1_footnote-ref-1" class="footnote"><a href="#cha-1_footnote-1">1</a></sup></p>
78
+ </div>
79
+ <div id="cha-1_footnotes">
80
+ <ol class="footnotes">
81
+ <li id="cha-1_footnote-1">
82
+ Cicero <a class="arrow" href="#cha-1_footnote-ref-1">↑</a>
83
+ </li>
84
+ </ol>
85
+ </div>
86
+ <div id="cha-bar" data-tralics-id="cid3" class="chapter" data-number="2">
87
+ <h1><a href="#cha-bar" class="heading"><span class="number">Chapter 2 </span>Bar</a></h1>
88
+ <p>Dolor sit amet.<sup id="cha-2_footnote-ref-1" class="footnote"><a href="#cha-2_footnote-1">1</a></sup></p>
89
+ <p>Hey Jude.<sup id="cha-2_footnote-ref-2" class="footnote"><a href="#cha-2_footnote-2">2</a></sup></p>
90
+ </div>
91
+ <div id="cha-2_footnotes">
92
+ <ol class="footnotes">
93
+ <li id="cha-2_footnote-1">
94
+ <em>Still</em> Cicero <a class="arrow" href="#cha-2_footnote-ref-1">↑</a>
95
+ </li>
96
+ <li id="cha-2_footnote-2">
97
+ Lennon/McCartney <a class="arrow" href="#cha-2_footnote-ref-2">↑</a>
98
+ </li>
99
+ </ol>
100
+ </div>
101
+ EOS
102
+ end
103
+ it { should resemble output }
104
+ end
105
+
106
+ describe "symbols in place of numbers" do
107
+ let(:polytex) do <<-'EOS'
108
+ \documentclass{book}
109
+ \renewcommand{\thefootnote}{\fnsymbol{footnote}}
110
+ \begin{document}
111
+ \chapter{Foo \emph{bar}}
112
+ \label{cha:foo}
113
+
114
+ \section{Foobar}
115
+ \label{sec:foobar}
116
+
117
+ Lorem ipsum.\footnote{Cicero}
118
+
119
+ \chapter{Bar}
120
+ \label{cha:bar}
121
+
122
+ Dolor sit amet.\footnote{\emph{Still} Cicero}
123
+
124
+ Hey Jude!\footnote{Lennon/McCartney} Be afraid.
125
+ \end{document}
126
+ EOS
127
+ end
128
+
129
+ let(:output) do <<-'EOS'
130
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
131
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span>Foo <em>bar</em></a></h1>
132
+ </div>
133
+ <div id="sec-foobar" data-tralics-id="cid2" class="section" data-number="1.1">
134
+ <h2><a href="#sec-foobar" class="heading"><span class="number">1.1 </span>Foobar</a></h2>
135
+ <p>Lorem ipsum.<sup id="cha-1_footnote-ref-1" class="footnote"><a href="#cha-1_footnote-1">*</a></sup></p>
136
+ </div>
137
+ <div id="cha-1_footnotes">
138
+ <ul class="footnotes nonumbers">
139
+ <li id="cha-1_footnote-1">
140
+ <sup>*</sup> Cicero <a class="arrow" href="#cha-1_footnote-ref-1">↑</a>
141
+ </li>
142
+ </ul>
143
+ </div>
144
+ <div id="cha-bar" data-tralics-id="cid3" class="chapter" data-number="2">
145
+ <h1><a href="#cha-bar" class="heading"><span class="number">Chapter 2 </span>Bar</a></h1>
146
+ <p>Dolor sit amet.<sup id="cha-2_footnote-ref-1" class="footnote"><a href="#cha-2_footnote-1">*</a></sup></p>
147
+ <p>Hey Jude!<sup id="cha-2_footnote-ref-2" class="footnote intersentence"><a href="#cha-2_footnote-2">†</a></sup><span class="intersentencespace"></span>
148
+ Be afraid.<span class="intersentencespace"></span></p>
149
+ </div>
150
+ <div id="cha-2_footnotes">
151
+ <ul class="footnotes nonumbers">
152
+ <li id="cha-2_footnote-1">
153
+ <sup>*</sup> <em>Still</em> Cicero <a class="arrow" href="#cha-2_footnote-ref-1">↑</a>
154
+ </li>
155
+ <li id="cha-2_footnote-2">
156
+ <sup>†</sup> Lennon/McCartney <a class="arrow" href="#cha-2_footnote-ref-2">↑</a>
157
+ </li>
158
+ </ul>
159
+ </div>
160
+ EOS
161
+ end
162
+ it { should resemble output }
163
+ end
164
+ end
@@ -0,0 +1,358 @@
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 "graphics" do
9
+ let(:polytex) do <<-'EOS'
10
+ \includegraphics{foo.png}
11
+ EOS
12
+ end
13
+
14
+ it do
15
+ should resemble <<-'EOS'
16
+ <div class="graphics">
17
+ <img src="foo.png" alt="foo" />
18
+ </div>
19
+ EOS
20
+ end
21
+ it { should_not resemble 'class="figure"' }
22
+ it { should_not resemble 'Figure' }
23
+
24
+ context "with a PDF image" do
25
+ let(:polytex) do <<-'EOS'
26
+ \includegraphics{foo.pdf}
27
+ EOS
28
+ end
29
+
30
+ it do
31
+ should resemble <<-'EOS'
32
+ <div class="graphics">
33
+ <img src="foo.png" alt="foo" />
34
+ </div>
35
+ EOS
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "figures" do
41
+ let(:polytex) do <<-'EOS'
42
+ \begin{figure}
43
+ lorem
44
+ \end{figure}
45
+ EOS
46
+ end
47
+
48
+ it do
49
+ should resemble <<-'EOS'
50
+ <div id="uid1" data-tralics-id="uid1" data-number="1" class="figure">
51
+ <p>lorem</p>
52
+ <div class="caption">
53
+ <span class="header">Figure 1</span>
54
+ </div>
55
+ </div>
56
+ EOS
57
+ end
58
+
59
+ context "with an explicit center environment" do
60
+ let(:polytex) do <<-'EOS'
61
+ \begin{figure}
62
+ \begin{center}
63
+ lorem
64
+ \end{center}
65
+ \end{figure}
66
+ EOS
67
+ end
68
+ it do
69
+ should resemble <<-'EOS'
70
+ <div class="center figure" id="uid1" data-tralics-id="uid1" data-number="1">
71
+ <p>lorem</p>
72
+ <div class="caption">
73
+ <span class="header">Figure 1</span>
74
+ </div>
75
+ </div>
76
+ EOS
77
+ end
78
+ end
79
+
80
+ context "with a label and a cross-reference" do
81
+ let(:polytex) do <<-'EOS'
82
+ \begin{figure}
83
+ lorem
84
+ \label{fig:foo}
85
+ \end{figure}
86
+
87
+ Figure~\ref{fig:foo} or Fig.~\ref{fig:foo}
88
+ EOS
89
+ end
90
+
91
+ it do
92
+ should resemble <<-'EOS'
93
+ <div id="fig-foo" data-tralics-id="uid1" data-number="1" class="figure">
94
+ <p>lorem</p>
95
+ <div class="caption">
96
+ <span class="header">Figure 1</span>
97
+ </div>
98
+ </div>
99
+ <p><a href="#fig-foo" class="hyperref">Figure <span class="ref">1</span></a>
100
+ or
101
+ <a href="#fig-foo" class="hyperref">Fig. <span class="ref">1</span></a>
102
+ </p>
103
+ EOS
104
+ end
105
+ end
106
+
107
+ context "with included graphics" do
108
+ let(:polytex) do <<-'EOS'
109
+ \begin{figure}
110
+ \includegraphics{images/foo.png}
111
+ \label{fig:foo}
112
+ \end{figure}
113
+ EOS
114
+ end
115
+
116
+ it do
117
+ should resemble <<-'EOS'
118
+ <div id="fig-foo" data-tralics-id="uid1" data-number="1" class="figure">
119
+ <div class="graphics">
120
+ <img src="images/foo.png" alt="foo" />
121
+ </div>
122
+ <div class="caption">
123
+ <span class="header">Figure 1</span>
124
+ </div>
125
+ </div>
126
+ EOS
127
+ end
128
+ end
129
+
130
+ context "with a caption" do
131
+ let(:polytex) do <<-'EOS'
132
+ \chapter{The chapter}
133
+
134
+ \begin{figure}
135
+ \includegraphics{foo.png}
136
+ \caption{This is a \emph{caption} with $x$.}
137
+ \end{figure}
138
+
139
+ \begin{figure}
140
+ \includegraphics{bar.png}
141
+ \caption{This is another caption.}
142
+ \end{figure}
143
+ EOS
144
+ end
145
+
146
+ it do
147
+ should resemble <<-'EOS'
148
+ <div id="cid1" data-tralics-id="cid1" class="chapter" data-number="1">
149
+ <h1>
150
+ <a href="#cid1" class="heading">
151
+ <span class="number">Chapter 1 </span>The chapter</a>
152
+ </h1>
153
+ <div id="uid1" data-tralics-id="uid1" data-number="1.1" class="figure">
154
+ <div class="graphics">
155
+ <img src="foo.png" alt="foo" />
156
+ </div>
157
+ <div class="caption">
158
+ <span class="header">Figure 1.1: </span>
159
+ <span class="description">This is a <em>caption</em> with <span class="inline_math">\( x \)</span>.</span>
160
+ </div>
161
+ </div>
162
+ <div id="uid2" data-tralics-id="uid2" data-number="1.2" class="figure">
163
+ <div class="graphics">
164
+ <img src="bar.png" alt="bar" />
165
+ </div>
166
+ <div class="caption">
167
+ <span class="header">Figure 1.2: </span>
168
+ <span class="description">This is another caption.</span>
169
+ </div>
170
+ </div>
171
+ </div>
172
+ EOS
173
+ end
174
+ end
175
+
176
+ context "with labels and cross-reference" do
177
+ let(:polytex) do <<-'EOS'
178
+ \chapter{The chapter}
179
+ \label{cha:lorem_ipsum}
180
+
181
+ \begin{figure}
182
+ \includegraphics{foo.png}
183
+ \caption{This is a caption.\label{fig:foo}}
184
+ \end{figure}
185
+
186
+ \begin{figure}
187
+ \includegraphics{bar.png}
188
+ \caption{This is another caption.\label{fig:bar}}
189
+ \end{figure}
190
+
191
+ Figure~\ref{fig:baz}
192
+
193
+ \chapter{A second chapter}
194
+ \label{cha:two}
195
+
196
+ \begin{figure}
197
+ \includegraphics{baz.png}
198
+ \caption{Yet another.\label{fig:baz}}
199
+ \end{figure}
200
+
201
+ Figure~\ref{fig:foo} and Figure~\ref{fig:bar}
202
+ EOS
203
+ end
204
+
205
+ it do
206
+ should resemble <<-'EOS'
207
+ <div id="cha-lorem_ipsum" data-tralics-id="cid1" class="chapter" data-number="1">
208
+ <h1>
209
+ <a href="#cha-lorem_ipsum" class="heading">
210
+ <span class="number">Chapter 1 </span>The chapter</a>
211
+ </h1>
212
+ <div id="fig-foo" data-tralics-id="uid1" data-number="1.1" class="figure">
213
+ <div class="graphics">
214
+ <img src="foo.png" alt="foo" />
215
+ </div>
216
+ <div class="caption">
217
+ <span class="header">Figure 1.1: </span>
218
+ <span class="description">This is a caption.</span>
219
+ </div>
220
+ </div>
221
+ <div id="fig-bar" data-tralics-id="uid2" data-number="1.2" class="figure">
222
+ <div class="graphics">
223
+ <img src="bar.png" alt="bar" />
224
+ </div>
225
+ <div class="caption">
226
+ <span class="header">Figure 1.2: </span>
227
+ <span class="description">This is another caption.</span>
228
+ </div>
229
+ </div>
230
+ <p>
231
+ <a href="#fig-baz" class="hyperref">Figure <span class="ref">2.1</span></a>
232
+ </p>
233
+ </div>
234
+ <div id="cha-two" data-tralics-id="cid2" class="chapter" data-number="2">
235
+ <h1>
236
+ <a href="#cha-two" class="heading">
237
+ <span class="number">Chapter 2 </span>A second chapter</a>
238
+ </h1>
239
+ <div id="fig-baz" data-tralics-id="uid3" data-number="2.1" class="figure">
240
+ <div class="graphics">
241
+ <img src="baz.png" alt="baz" />
242
+ </div>
243
+ <div class="caption">
244
+ <span class="header">Figure 2.1: </span>
245
+ <span class="description">Yet another.</span>
246
+ </div>
247
+ </div>
248
+ <p>
249
+ <a href="#fig-foo" class="hyperref">Figure <span class="ref">1.1</span></a>
250
+ and
251
+ <a href="#fig-bar" class="hyperref">Figure <span class="ref">1.2</span></a>
252
+ </p>
253
+ </div>
254
+ EOS
255
+ end
256
+
257
+ context "with a centered image" do
258
+ let(:polytex) do <<-'EOS'
259
+ \chapter{The chapter}
260
+ \label{cha:lorem_ipsum}
261
+
262
+ \begin{figure}
263
+ \centering
264
+ \includegraphics{foo.png}
265
+ \caption{This is a caption.\label{fig:foo}}
266
+ \end{figure}
267
+ EOS
268
+ end
269
+
270
+ it do
271
+ should resemble <<-'EOS'
272
+ <div id="cha-lorem_ipsum" data-tralics-id="cid1" class="chapter" data-number="1">
273
+ <h1>
274
+ <a href="#cha-lorem_ipsum" class="heading">
275
+ <span class="number">Chapter 1 </span>The chapter</a>
276
+ </h1>
277
+ <div class="center figure" id="fig-foo" data-tralics-id="uid1" data-number="1.1">
278
+ <div class="graphics">
279
+ <img src="foo.png" alt="foo" />
280
+ </div>
281
+ <div class="caption">
282
+ <span class="header">Figure 1.1: </span>
283
+ <span class="description">This is a caption.</span>
284
+ </div>
285
+ </div>
286
+ </div>
287
+ EOS
288
+ end
289
+
290
+ context "using the \\image command" do
291
+ let(:polytex) do <<-'EOS'
292
+ \chapter{The chapter}
293
+ \label{cha:lorem_ipsum}
294
+
295
+ \begin{figure}
296
+ \image{foo_bar.png}
297
+ \caption{This is a caption.\label{fig:foo}}
298
+ \end{figure}
299
+ EOS
300
+ end
301
+
302
+ it do
303
+ should resemble <<-'EOS'
304
+ <div id="cha-lorem_ipsum" data-tralics-id="cid1" class="chapter" data-number="1">
305
+ <h1>
306
+ <a href="#cha-lorem_ipsum" class="heading">
307
+ <span class="number">Chapter 1 </span>The chapter</a>
308
+ </h1>
309
+ <div id="fig-foo" data-tralics-id="uid1" data-number="1.1" class="figure">
310
+ <div class="graphics image">
311
+ <img src="foo_bar.png" alt="foo_bar" />
312
+ </div>
313
+ <div class="caption">
314
+ <span class="header">Figure 1.1: </span>
315
+ <span class="description">This is a caption.</span>
316
+ </div>
317
+ </div>
318
+ </div>
319
+ EOS
320
+ end
321
+ end
322
+
323
+ context "using the \\imagebox command" do
324
+ let(:polytex) do <<-'EOS'
325
+ \chapter{The chapter}
326
+ \label{cha:lorem_ipsum}
327
+
328
+ \begin{figure}
329
+ \imagebox{foo_bar.png}
330
+ \caption{This is a caption.\label{fig:foo}}
331
+ \end{figure}
332
+ EOS
333
+ end
334
+
335
+ it do
336
+ should resemble <<-'EOS'
337
+ <div id="cha-lorem_ipsum" data-tralics-id="cid1" class="chapter" data-number="1">
338
+ <h1>
339
+ <a href="#cha-lorem_ipsum" class="heading">
340
+ <span class="number">Chapter 1 </span>The chapter</a>
341
+ </h1>
342
+ <div id="fig-foo" data-tralics-id="uid1" data-number="1.1" class="figure">
343
+ <div class="graphics image box">
344
+ <img src="foo_bar.png" alt="foo_bar" />
345
+ </div>
346
+ <div class="caption">
347
+ <span class="header">Figure 1.1: </span>
348
+ <span class="description">This is a caption.</span>
349
+ </div>
350
+ </div>
351
+ </div>
352
+ EOS
353
+ end
354
+ end
355
+ end
356
+ end
357
+ end
358
+ end
@@ -0,0 +1,103 @@
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 "itemize" do
9
+ let(:polytex) { '\itemize' }
10
+ it { should resemble '<ul></ul>'}
11
+ end
12
+
13
+ describe "enumerate" do
14
+ let(:polytex) { '\enumerate' }
15
+ it { should resemble '<ol></ol>'}
16
+ end
17
+
18
+ describe "item" do
19
+ let(:polytex) { '\item foo' }
20
+ it { should resemble "<li>foo\n</li>"}
21
+ end
22
+
23
+ describe "itemized list" do
24
+
25
+ context "alone" do
26
+ let(:polytex) do <<-'EOS'
27
+ \begin{itemize}
28
+ \item Foo
29
+ \item Bar
30
+ \end{itemize}
31
+ EOS
32
+ end
33
+ it do
34
+ should resemble <<-'EOS'
35
+ <ul>
36
+ <li>Foo</li>
37
+ <li>Bar</li>
38
+ </ul>
39
+ EOS
40
+ end
41
+ end
42
+
43
+ context "preceded by text" do
44
+ let(:polytex) do <<-'EOS'
45
+ lorem ipsum
46
+
47
+ \begin{itemize}
48
+ \item Foo
49
+ \item Bar
50
+ \end{itemize}
51
+ EOS
52
+ end
53
+ it do
54
+ should resemble <<-'EOS'
55
+ <p>lorem ipsum</p>
56
+ <ul>
57
+ <li>Foo</li>
58
+ <li>Bar</li>
59
+ </ul>
60
+ EOS
61
+ end
62
+ end
63
+
64
+ context "afollowed by text" do
65
+ let(:polytex) do <<-'EOS'
66
+ \begin{itemize}
67
+ \item Foo
68
+ \item Bar
69
+ \end{itemize}
70
+
71
+ lorem ipsum
72
+ EOS
73
+ end
74
+ it do
75
+ should resemble <<-'EOS'
76
+ <ul>
77
+ <li>Foo</li>
78
+ <li>Bar</li>
79
+ </ul><p>lorem ipsum
80
+ </p>
81
+ EOS
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "enumerated list" do
87
+ let(:polytex) do <<-'EOS'
88
+ \begin{enumerate}
89
+ \item Foo
90
+ \item Bar
91
+ \end{enumerate}
92
+ EOS
93
+ end
94
+ it do
95
+ should resemble <<-'EOS'
96
+ <ol>
97
+ <li>Foo</li>
98
+ <li>Bar</li>
99
+ </ol>
100
+ EOS
101
+ end
102
+ end
103
+ end