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,268 @@
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 '\chapter' do
9
+ context "with a name" do
10
+ let(:polytex) do <<-'EOS'
11
+ \chapter{Foo \emph{bar}}
12
+ \label{cha:foo}
13
+ EOS
14
+ end
15
+ let(:output) do <<-'EOS'
16
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
17
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span>Foo <em>bar</em></a></h1>
18
+ </div>
19
+ EOS
20
+ end
21
+ it { should resemble output }
22
+ end
23
+
24
+ context "with no name" do
25
+ let(:polytex) do <<-'EOS'
26
+ \chapter{}
27
+ \label{cha:foo}
28
+ EOS
29
+ end
30
+ let(:output) do <<-'EOS'
31
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
32
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span></a></h1>
33
+ </div>
34
+ EOS
35
+ end
36
+ it { should resemble output }
37
+ end
38
+
39
+ end
40
+
41
+ describe '\section' do
42
+ let(:polytex) do <<-'EOS'
43
+ \section{Foo}
44
+ \label{sec:foo}
45
+ EOS
46
+ end
47
+ let(:output) do <<-'EOS'
48
+ <div id="sec-foo" data-tralics-id="cid1" class="section" data-number="1">
49
+ <h2><a href="#sec-foo" class="heading"><span class="number">1 </span>Foo</a></h2>
50
+ </div>
51
+ EOS
52
+ end
53
+ it { should resemble output }
54
+ end
55
+
56
+ describe '\subsection' do
57
+ let(:polytex) do <<-'EOS'
58
+ \section{Foo}
59
+ \label{sec:foo}
60
+
61
+ \subsection{Bar}
62
+ \label{sec:bar}
63
+ EOS
64
+ end
65
+
66
+ let(:output) do <<-'EOS'
67
+ <div id="sec-foo" data-tralics-id="cid1" class="section" data-number="1">
68
+ <h2><a href="#sec-foo" class="heading"><span class="number">1 </span>Foo</a></h2>
69
+ <div id="sec-bar" data-tralics-id="uid1" class="subsection" data-number="1.1">
70
+ <h3><a href="#sec-bar" class="heading"><span class="number">1.1 </span>Bar</a></h3>
71
+ </div>
72
+ </div>
73
+ EOS
74
+ end
75
+ it { should resemble output }
76
+ end
77
+
78
+ describe '\subsubsection' do
79
+ let(:polytex) do <<-'EOS'
80
+ \chapter{The Chapter}
81
+ \label{cha:the_chapter}
82
+
83
+ \section{Foo}
84
+ \label{sec:foo}
85
+
86
+ \subsection{Bar}
87
+ \label{sec:bar}
88
+
89
+ \subsubsection{Baz}
90
+ \label{sec:baz}
91
+ EOS
92
+ end
93
+
94
+ let(:output) do <<-'EOS'
95
+ <div id="cha-the_chapter" data-tralics-id="cid1" class="chapter" data-number="1"><h1><a href="#cha-the_chapter" class="heading"><span class="number">Chapter 1 </span>The Chapter</a></h1>
96
+ </div>
97
+ <div id="sec-foo" data-tralics-id="cid2" class="section" data-number="1.1"><h2><a href="#sec-foo" class="heading"><span class="number">1.1 </span>Foo</a></h2>
98
+
99
+ <div id="sec-bar" data-tralics-id="uid1" class="subsection" data-number="1.1.1"><h3><a href="#sec-bar" class="heading"><span class="number">1.1.1 </span>Bar</a></h3>
100
+
101
+ <div id="sec-baz" data-tralics-id="uid2" class="subsubsection" data-number="1.1.1.1"><h4><a href="#sec-baz" class="heading">Baz</a></h4>
102
+ </div>
103
+ </div>
104
+ </div>
105
+ EOS
106
+ end
107
+ it { should resemble output }
108
+ end
109
+
110
+ describe '\chapter*' do
111
+ let(:polytex) do <<-'EOS'
112
+ \chapter*{Preface}
113
+ Lorem ipsum
114
+ EOS
115
+ end
116
+ it { should resemble '<div class="chapter-star">' }
117
+ end
118
+
119
+ describe '\section*, etc.' do
120
+ let(:polytex) do <<-'EOS'
121
+ \section*{Foo}
122
+
123
+ \subsection*{Bar}
124
+
125
+ Lorem ipsum
126
+
127
+ \section{Baz}
128
+ EOS
129
+ end
130
+ let(:output) do <<-'EOS'
131
+ <div class="section-star">
132
+ <h2><a class="heading">Foo</a></h2>
133
+ <div class="subsection-star">
134
+ <h3><a class="heading">Bar</a></h3>
135
+ <p>Lorem ipsum</p>
136
+ </div>
137
+ </div>
138
+ <div id="cid1" data-tralics-id="cid1" class="section" data-number="1">
139
+ <h2><a href="#cid1" class="heading"><span class="number">1 </span>Baz</a></h2>
140
+ </div>
141
+ EOS
142
+ end
143
+ it { should resemble output }
144
+ end
145
+
146
+ describe 'chapter cross-references' do
147
+ let(:polytex) do <<-'EOS'
148
+ \chapter{Foo}
149
+ \label{cha:foo_bar}
150
+
151
+ Chapter~\ref{cha:foo_bar} and
152
+ Chapter \ref{cha:foo_baz}
153
+
154
+ \chapter{Baz}
155
+ \label{cha:foo_baz}
156
+
157
+ Chapter~\ref{cha:foo_baz} and
158
+ Chapter \ref{cha:foo_bar}
159
+ EOS
160
+ end
161
+
162
+ it do
163
+ should resemble <<-'EOS'
164
+ <div id="cha-foo_bar" data-tralics-id="cid1" class="chapter" data-number="1">
165
+ <h1><a href="#cha-foo_bar" class="heading"><span class="number">Chapter 1 </span>Foo</a></h1>
166
+ <p><a href="#cha-foo_bar" class="hyperref">Chapter <span class="ref">1</span></a>
167
+ and
168
+ <a href="#cha-foo_baz" class="hyperref">Chapter <span class="ref">2</span></a>
169
+ </p>
170
+ </div>
171
+
172
+ <div id="cha-foo_baz" data-tralics-id="cid2" class="chapter" data-number="2">
173
+ <h1><a href="#cha-foo_baz" class="heading"><span class="number">Chapter 2 </span>Baz</a></h1>
174
+ <p><a href="#cha-foo_baz" class="hyperref">Chapter <span class="ref">2</span></a>
175
+ and
176
+ <a href="#cha-foo_bar" class="hyperref">Chapter <span class="ref">1</span></a>
177
+ </p>
178
+ </div>
179
+ EOS
180
+ end
181
+ end
182
+
183
+ describe "section cross-references" do
184
+ let(:polytex) do <<-'EOS'
185
+ \section{Foo}
186
+ \label{sec:foo}
187
+
188
+ Section~\ref{sec:bar} and Section~\ref{sec:baz}
189
+
190
+ \subsection{Bar}
191
+ \label{sec:bar}
192
+
193
+ Section~\ref{sec:foo}
194
+
195
+ \subsubsection{Baz}
196
+ \label{sec:baz}
197
+ EOS
198
+ end
199
+
200
+ it do
201
+ should resemble <<-'EOS'
202
+ <div id="sec-foo" data-tralics-id="cid1" class="section" data-number="1"><h2><a href="#sec-foo" class="heading"><span class="number">1 </span>Foo</a></h2>
203
+ <p>
204
+ <a href="#sec-bar" class="hyperref">Section <span class="ref">1.1</span></a>
205
+ and
206
+ <a href="#sec-baz" class="hyperref">Section <span class="ref">1.1.1</span></a>
207
+ </p>
208
+ <div id="sec-bar" data-tralics-id="uid1" class="subsection" data-number="1.1"><h3><a href="#sec-bar" class="heading"><span class="number">1.1 </span>Bar</a></h3>
209
+ <p><a href="#sec-foo" class="hyperref">Section <span class="ref">1</span></a>
210
+ </p>
211
+ <div id="sec-baz" data-tralics-id="uid2" class="subsubsection" data-number="1.1.1">
212
+ <h4><a href="#sec-baz" class="heading">Baz</a></h4>
213
+ </div></div></div>
214
+ EOS
215
+ end
216
+ end
217
+
218
+ describe 'missing cross-references' do
219
+ let(:polytex) do <<-'EOS'
220
+ \chapter{Foo}
221
+ \label{cha:foo}
222
+
223
+ Chapter~\ref{cha:bar}
224
+ EOS
225
+ end
226
+
227
+ it do
228
+ should resemble <<-'EOS'
229
+ <div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
230
+ <h1><a href="#cha-foo" class="heading"><span class="number">Chapter 1 </span>Foo</a></h1>
231
+ <p><a href="#cha-bar" class="hyperref">Chapter <span class="undefined_ref">cha:bar</span></a>
232
+ </p>
233
+ </div>
234
+ EOS
235
+ end
236
+ end
237
+
238
+ describe "frontmatter and mainmatter" do
239
+ let(:polytex) do <<-'EOS'
240
+ \frontmatter
241
+ \chapter{Foo}
242
+
243
+ Lorem ipsum.\footnote{Foo bar.}
244
+
245
+ \mainmatter
246
+ \chapter{Bar}
247
+ \label{cha:bar}
248
+
249
+ Chapter~\ref{cha:bar}
250
+ EOS
251
+ end
252
+
253
+ it do
254
+ should resemble <<-'EOS'
255
+ <div id="frontmatter" data-number="0">
256
+ <div class="chapter-star"><h1><a class="heading">Foo</a></h1>
257
+ <p>Lorem ipsum.<sup id="cha-0_footnote-ref-1" class="footnote"><a href="#cha-0_footnote-1">1</a></sup></p>
258
+ </div></div>
259
+ <div id="cha-0_footnotes">
260
+ <ol class="footnotes"><li id="cha-0_footnote-1">Foo bar. <a class="arrow" href="#cha-0_footnote-ref-1">↑</a></li>
261
+ </ol></div>
262
+ <div id="cha-bar" data-tralics-id="cid1" class="chapter" data-number="1"><h1><a href="#cha-bar" class="heading"><span class="number">Chapter 1 </span>Bar</a></h1>
263
+ <p><a href="#cha-bar" class="hyperref">Chapter <span class="ref">1</span></a>
264
+ </p></div>
265
+ EOS
266
+ end
267
+ end
268
+ end
@@ -0,0 +1,138 @@
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 "quoted strings" do
9
+ context "with single quotes" do
10
+ let(:polytex) { "``foo bar''" }
11
+ it { should resemble '“foo bar”' }
12
+ end
13
+
14
+ context "with single quotes" do
15
+ let(:polytex) { "`foo bar'" }
16
+ it { should resemble '‘foo bar’' }
17
+ end
18
+
19
+ context "with an apostrophe" do
20
+ let(:polytex) { "don't stop believin'" }
21
+ it { should resemble 'don’t stop believin’' }
22
+ end
23
+ end
24
+
25
+ describe "dashes" do
26
+
27
+ context "em" do
28
+ let(:polytex) { '---' }
29
+ it { should resemble '—' }
30
+ end
31
+
32
+ context "en" do
33
+ let(:polytex) { '--' }
34
+ it { should resemble '–' }
35
+ end
36
+ end
37
+
38
+ describe '\ldots' do
39
+ let(:polytex) { '\ldots' }
40
+ it { should resemble '…' }
41
+ end
42
+
43
+ describe 'end-of-sentence punctuation' do
44
+
45
+
46
+ describe "spaces" do
47
+
48
+ context "thin" do
49
+ let(:polytex) { 'a\,b' }
50
+ it { should resemble 'a<span class="thinspace">&thinsp;</span>b' }
51
+ end
52
+
53
+ context "normal" do
54
+ let(:polytex) { 'Dr.\ No' }
55
+ it { should resemble 'Dr. No' }
56
+ end
57
+
58
+ context "intersentence" do
59
+ let(:intsp) { '<span class="intersentencespace"></span>' }
60
+
61
+ context "separated by a space" do
62
+ let(:polytex) { 'I am. You are.' }
63
+ it { should resemble "I am.#{intsp} You are." }
64
+ end
65
+
66
+ context "separated by n spaces" do
67
+ let(:polytex) { 'I am! You are.' }
68
+ it { should resemble "I am!#{intsp} You are." }
69
+ end
70
+
71
+ context "separated by a newline" do
72
+ let(:polytex) { "I am?\nYou are." }
73
+ it { should resemble "I am?#{intsp} You are." }
74
+ end
75
+
76
+ context "separated by two newlines" do
77
+ let(:polytex) { "I am.\n\nYou are." }
78
+ it { should resemble 'I am.</p><p>You are.' }
79
+ end
80
+
81
+ context "with a sentence ending in a closing parenthesis" do
82
+ let(:polytex) { "(Or otherwise.) A new sentence." }
83
+ it { should resemble "(Or otherwise.)#{intsp} A new sentence." }
84
+ end
85
+
86
+ context "with a sentence ending in a closing quote" do
87
+ let(:polytex) { "``Yes, indeed!'' A new sentence." }
88
+ it { should resemble "“Yes, indeed!”#{intsp} A new sentence." }
89
+ end
90
+
91
+ context "forced inter-sentence override" do
92
+ let(:polytex) { 'Superman II\@. Lorem ipsum.' }
93
+ it { should resemble "Superman II.#{intsp} Lorem ipsum." }
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'unbreakable interword space' do
100
+ let(:polytex) { 'foo~bar' }
101
+ it { should resemble 'foo bar' }
102
+ end
103
+
104
+ describe "(La)TeX logos" do
105
+
106
+ describe "TeX logo" do
107
+ let(:polytex) { '\TeX' }
108
+ let(:output) do
109
+ %(<span class="texhtml" style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Times New Roman', 'Nimbus Roman No9 L', Times, serif;">T<span style="text-transform: uppercase; vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em;">E</span>X</span>)
110
+ end
111
+ it { should include(output) }
112
+ end
113
+
114
+ describe "LaTeX logo" do
115
+ let(:polytex) { '\LaTeX' }
116
+ let(:output) do
117
+ %(<span class="texhtml" style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Times New Roman', 'Nimbus Roman No9 L', Times, serif;">L<span style="text-transform: uppercase; font-size: 70%; margin-left: -0.36em; vertical-align: 0.3em; line-height: 0; margin-right: -0.15em;">A</span>T<span style="text-transform: uppercase; margin-left: -0.1667em; vertical-align: -0.5ex; line-height: 0; margin-right: -0.125em;">E</span>X</span>)
118
+ end
119
+ it { should include(output) }
120
+ end
121
+
122
+ describe "PolyTeX logo" do
123
+ let(:polytex) { '\PolyTeX' }
124
+ let(:output) do
125
+ %(Poly<span class="texhtml" style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Times New Roman', 'Nimbus Roman No9 L', Times, serif;">T<span style="text-transform: uppercase; vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em;">E</span>X</span>)
126
+ end
127
+ it { should include(output) }
128
+ end
129
+
130
+ describe "PolyTeXnic logo" do
131
+ let(:polytex) { '\PolyTeXnic' }
132
+ let(:output) do
133
+ %(Poly<span class="texhtml" style="font-family: 'CMU Serif', cmr10, LMRoman10-Regular, 'Times New Roman', 'Nimbus Roman No9 L', Times, serif;">T<span style="text-transform: uppercase; vertical-align: -0.5ex; margin-left: -0.1667em; margin-right: -0.125em;">E</span>X</span>nic)
134
+ end
135
+ it { should include(output) }
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,70 @@
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 "code listings" do
9
+ let(:polytex) do <<-'EOS'
10
+ \chapter{Foo bar}
11
+
12
+ \begin{codelisting}
13
+ \codecaption{Creating a \texttt{gem} configuration file. \\ \filepath{path/to/file}}
14
+ \label{code:create_gemrc}
15
+ %= lang:console
16
+ \begin{code}
17
+ $ subl .gemrc
18
+ \end{code}
19
+ \end{codelisting}
20
+
21
+ Listing~\ref{code:create_gemrc}
22
+ EOS
23
+ end
24
+
25
+ it do
26
+ should resemble <<-'EOS'
27
+ <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 bar</a></h1>
28
+ <div class="codelisting" id="code-create_gemrc" data-tralics-id="uid1" data-number="1.1">
29
+ <div class="heading">
30
+ <span class="number">Listing 1.1:</span>
31
+ <span class="description">Creating a <span class="tt">gem</span> configuration file.<span class="intersentencespace"></span>
32
+ <span class="break"></span>
33
+ <span class="filepath">path/to/file</span>
34
+ </span>
35
+ </div>
36
+ <div class="code">
37
+ <div class="highlight">
38
+ <pre><span class="gp">$</span> subl .gemrc</pre>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ <p><a href="#code-create_gemrc" class="hyperref">Listing <span class="ref">1.1</span></a></p>
43
+ </div>
44
+ EOS
45
+ end
46
+ end
47
+
48
+ describe "metacode listings" do
49
+ let(:polytex) do <<-'EOS'
50
+ \begin{codelisting}
51
+ \label{code:listing}
52
+ \codecaption{The heading.}
53
+ %= lang:latex
54
+ \begin{metacode}
55
+ %= lang:ruby
56
+ \begin{code}
57
+ def foo
58
+ "bar"
59
+ end
60
+ \end{code}
61
+ \end{metacode}
62
+ \end{codelisting}
63
+ EOS
64
+ end
65
+
66
+ it "should not raise an error" do
67
+ expect { processed_text }.not_to raise_error
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,227 @@
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 "comments" do
9
+ let(:polytex) { "% A LaTeX comment" }
10
+ it { should eq '' }
11
+
12
+ context "with a section and label" do
13
+ let(:polytex) do <<-'EOS'
14
+ % \section{Foo}
15
+ % \label{sec:foo}
16
+ EOS
17
+ end
18
+ it { should eq '' }
19
+ end
20
+
21
+ context "with a code listing" do
22
+ let(:polytex) do <<-'EOS'
23
+ % \begin{codelisting}
24
+ % \heading{A hello program in Ruby.}
25
+ % \label{code:hello}
26
+ % %= lang:ruby
27
+ % \begin{code}
28
+ % def hello
29
+ % "hello, world!"
30
+ % end
31
+ % \end{code}
32
+ % \end{codelisting}
33
+ EOS
34
+ end
35
+ it { should eq '' }
36
+ end
37
+
38
+ context "with a code inclusion" do
39
+ let(:polytex) { '% %= << spec/spec_helper.rb' }
40
+ it { should eq '' }
41
+ end
42
+
43
+ context "with a literal percent" do
44
+ let(:polytex) { '87.3\% of statistics are made up' }
45
+ it { should resemble '87.3% of statistics are made up' }
46
+ end
47
+
48
+ context "with characters before the percent" do
49
+ let(:polytex) { 'foo % bar' }
50
+ it { should resemble 'foo' }
51
+ end
52
+
53
+ context "with two percent signs" do
54
+ let(:polytex) { 'foo % bar % baz' }
55
+ it { should resemble 'foo' }
56
+ end
57
+
58
+ context "with display math" do
59
+ let(:polytex) do <<-'EOS'
60
+ % \[
61
+ % \begin{bmatrix}
62
+ % 1 & \cdots & 0 \\
63
+ % \vdots & \ddots & \vdots \\
64
+ % 2 & \cdots & 0
65
+ % \end{bmatrix}
66
+ % \]
67
+ EOS
68
+ end
69
+ it { should eq '' }
70
+ end
71
+ end
72
+
73
+ describe "a complete document" do
74
+ let(:polytex) do <<-'EOS'
75
+ \documentclass{book}
76
+
77
+ \begin{document}
78
+ lorem ipsum
79
+ \end{document}
80
+ EOS
81
+ end
82
+
83
+ it { should resemble "<p>lorem ipsum</p>" }
84
+ end
85
+
86
+ describe "paragraphs" do
87
+ let(:polytex) { 'lorem ipsum' }
88
+ it { should resemble "<p>lorem ipsum</p>" }
89
+ it { should_not resemble '<unknown>' }
90
+ end
91
+
92
+ describe '\maketitle' do
93
+
94
+ context "with all element filled out explicitly" do
95
+ let(:polytex) do <<-'EOS'
96
+ \title{Foo \\ \emph{Bar}}
97
+ \subtitle{Baz}
98
+ \author{Michael Hartl}
99
+ \date{January 1, 2013}
100
+ \begin{document}
101
+ \maketitle
102
+ \end{document}
103
+ EOS
104
+ end
105
+
106
+ it do
107
+ should resemble <<-'EOS'
108
+ <div id="title_page">
109
+ <h1 class="title">Foo <span class="break"></span> <em>Bar</em></h1>
110
+ <h1 class="subtitle">Baz</h1>
111
+ <h2 class="author">Michael Hartl</h2>
112
+ <h2 class="date">January 1, 2013</h2>
113
+ </div>
114
+ EOS
115
+ end
116
+
117
+ it "should not have repeated title elements" do
118
+ expect(processed_text.scan(/Michael Hartl/).length).to eq 1
119
+ end
120
+ end
121
+
122
+ context "when date is blank" do
123
+ let(:polytex) do <<-'EOS'
124
+ \title{Foo \\ \emph{Bar}}
125
+ \subtitle{Baz}
126
+ \author{Michael Hartl}
127
+ \date{}
128
+ \begin{document}
129
+ \maketitle
130
+ \end{document}
131
+ EOS
132
+ end
133
+
134
+ it do
135
+ should resemble <<-'EOS'
136
+ <div id="title_page">
137
+ <h1 class="title">Foo <span class="break"></span> <em>Bar</em></h1>
138
+ <h1 class="subtitle">Baz</h1>
139
+ <h2 class="author">Michael Hartl</h2>
140
+ </div>
141
+ EOS
142
+ end
143
+ end
144
+
145
+ context "when date is missing" do
146
+ let(:polytex) do <<-'EOS'
147
+ \title{Foo \\ \emph{Bar}}
148
+ \subtitle{Baz}
149
+ \author{Michael Hartl}
150
+ \begin{document}
151
+ \maketitle
152
+ \end{document}
153
+ EOS
154
+ end
155
+
156
+ it { should resemble '<h2 class="date">' }
157
+ it "should include today's date" do
158
+ expect(processed_text).to resemble Date.today.strftime("%A, %b %e")
159
+ end
160
+ end
161
+ end
162
+
163
+ describe "double backslashes" do
164
+ let(:polytex) { 'foo \\\\ bar' }
165
+ let(:output) { 'foo <span class="break"></span> bar' }
166
+ it { should resemble output }
167
+ end
168
+
169
+ describe "unknown command" do
170
+ let(:polytex) { '\foobar' }
171
+ let(:output) { '' }
172
+ it { should resemble output }
173
+ end
174
+
175
+ describe "href" do
176
+
177
+ context "standard URL" do
178
+ let(:polytex) { '\href{http://example.com/}{Example Site}' }
179
+ let(:output) { '<a href="http://example.com/">Example Site</a>' }
180
+ it { should resemble output }
181
+ end
182
+
183
+ context "URL containing TeX" do
184
+ let(:polytex) { '\href{http://example.com/}{\emph{\TeX}}' }
185
+ let(:output) { '<a href="http://example.com/" class="tex">' }
186
+ it { should resemble output }
187
+ end
188
+ end
189
+
190
+ describe "centering" do
191
+ let(:polytex) do <<-'EOS'
192
+ \begin{center}
193
+ Lorem ipsum
194
+
195
+ dolor sit amet
196
+ \end{center}
197
+ EOS
198
+ end
199
+ let(:output) do <<-'EOS'
200
+ <div class="center">
201
+ <p>Lorem ipsum</p>
202
+
203
+ <p>dolor sit amet</p>
204
+ </div>
205
+ EOS
206
+ end
207
+ it { should resemble output }
208
+ end
209
+
210
+ describe "skips" do
211
+
212
+ context "bigskip" do
213
+ let(:polytex) { '\bigskip' }
214
+ it { should resemble '<p style="margin-top: 12.0pt"' }
215
+ end
216
+
217
+ context "medskip" do
218
+ let(:polytex) { '\medskip' }
219
+ it { should resemble '<p style="margin-top: 6.0pt"' }
220
+ end
221
+
222
+ context "smallskip" do
223
+ let(:polytex) { '\smallskip' }
224
+ it { should resemble '<p style="margin-top: 3.0pt"' }
225
+ end
226
+ end
227
+ end