polytexnic 1.1.8 → 1.1.9
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac7a3fa330f197e8af6715e2626d7e9be2261f3d
|
4
|
+
data.tar.gz: 8b4e4f88a82246ed1aa6932913340ff77cd45425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db08f8612eb672b9393e2c8d7fc54509a85d21a93d144b330d9614d7de8edd5752651287777617710dc48ed87cc6a242f71b33e6ec9d783fdbfb8ce481f8b57
|
7
|
+
data.tar.gz: 8b40839422d8fb170b0e89de00bd62e23ff5b68ff801db330646b087dcb71c0b92787fb41ec96a9e9032bdb504dc31fbda874924c08178aec45f7974aa76a101
|
@@ -1242,6 +1242,14 @@ module Polytexnic
|
|
1242
1242
|
string.gsub!(/<p>\s*<\/p>/, '')
|
1243
1243
|
end
|
1244
1244
|
|
1245
|
+
# Retores quotes or verse inside figure.
|
1246
|
+
# This is a terrible hack.
|
1247
|
+
def restore_figure_quotes(string)
|
1248
|
+
figure_quote_cache.each do |key, html|
|
1249
|
+
string.gsub!(/<p>\s*#{key}\s*<\/p>/m, html)
|
1250
|
+
end
|
1251
|
+
end
|
1252
|
+
|
1245
1253
|
# Converts a document to HTML.
|
1246
1254
|
# Because there's no way to know which elements are block-level
|
1247
1255
|
# (and hence can't be nested inside a paragraph tag), we first extract
|
@@ -1259,6 +1267,7 @@ module Polytexnic
|
|
1259
1267
|
body = doc.at_css('document').children.to_xhtml
|
1260
1268
|
Nokogiri::HTML.fragment(body).to_xhtml.tap do |html|
|
1261
1269
|
trim_empty_paragraphs(html)
|
1270
|
+
restore_figure_quotes(html)
|
1262
1271
|
end
|
1263
1272
|
end
|
1264
1273
|
|
@@ -209,29 +209,48 @@ module Polytexnic
|
|
209
209
|
# is to use \centering anyway, so this kludge is actually better LaTeX.
|
210
210
|
def convert_float_centering(output)
|
211
211
|
@in_float = false
|
212
|
-
centered =
|
212
|
+
centered = []
|
213
|
+
quote_or_verse = []
|
214
|
+
output.split("\n").each do |line|
|
213
215
|
if line =~ /^\s*\\begin\{(figure|table)\}/
|
214
216
|
@in_float = true
|
215
217
|
@float_type = $1
|
216
|
-
line
|
218
|
+
centered << line
|
217
219
|
elsif @in_float && line =~ /^\s*\\begin\{center\}/
|
218
|
-
'\centering'
|
220
|
+
centered << '\centering'
|
219
221
|
elsif @in_float && line =~ /^\s*\\end\{center\}/
|
220
|
-
''
|
222
|
+
centered << ''
|
221
223
|
elsif @in_float && line =~/^\s*\\footnotesize/
|
222
224
|
# Removes \footnotesize in floats.
|
223
225
|
# This sizing is useful for tables
|
224
226
|
# in some LaTeX PDF contexts, but not in HTML,
|
225
227
|
# and it messes up the conversion.
|
226
|
-
''
|
228
|
+
centered << ''
|
227
229
|
elsif @in_float && line =~ /^\s*\\end\{#{@float_type}\}/
|
228
230
|
@in_float = false
|
229
|
-
line
|
231
|
+
centered << line
|
232
|
+
elsif @in_float && line =~ /^\s*\\begin\{(?:verse|quote)\}/
|
233
|
+
quote_or_verse << line
|
234
|
+
@in_quote = true
|
235
|
+
centered << ''
|
236
|
+
elsif @in_float && line =~ /^\s*\\end\{(?:verse|quote)\}/
|
237
|
+
quote_or_verse << line
|
238
|
+
quote = quote_or_verse.join("\n")
|
239
|
+
key = digest(latex)
|
240
|
+
html = Polytexnic::Pipeline.new(quote,
|
241
|
+
literal_cache: literal_cache).to_html
|
242
|
+
figure_quote_cache[key] = html
|
243
|
+
@in_quote = false
|
244
|
+
quote_or_verse = []
|
245
|
+
centered << key
|
246
|
+
elsif @in_quote
|
247
|
+
quote_or_verse << line
|
248
|
+
centered << ''
|
230
249
|
else
|
231
|
-
line
|
250
|
+
centered << line
|
232
251
|
end
|
233
|
-
end
|
234
|
-
output.replace(centered)
|
252
|
+
end
|
253
|
+
output.replace(centered.join("\n"))
|
235
254
|
end
|
236
255
|
|
237
256
|
# Converts the alt table environments to simple tabular.
|
data/lib/polytexnic/version.rb
CHANGED
data/lib/polytexnic.rb
CHANGED
@@ -39,12 +39,13 @@ module Polytexnic
|
|
39
39
|
attr_accessor :literal_cache, :code_cache, :polytex, :xml, :html,
|
40
40
|
:math_label_cache, :highlight_cache, :maketitle_elements,
|
41
41
|
:custom_commands, :language_labels, :unicode_cache,
|
42
|
-
:article
|
42
|
+
:article, :figure_quote_cache
|
43
43
|
|
44
44
|
def initialize(source, options = {})
|
45
45
|
@literal_cache = options[:literal_cache] || {}
|
46
46
|
@unicode_cache = {}
|
47
47
|
@code_cache = {}
|
48
|
+
@figure_quote_cache = {}
|
48
49
|
@maketitle_elements = {}
|
49
50
|
@article = options[:article]
|
50
51
|
@language_labels = if (labels = options[:language_labels]).nil?
|
@@ -82,10 +82,12 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
context "with a label and a cross-reference" do
|
85
|
+
context "with a label and a cross-reference and a quote" do
|
86
86
|
let(:polytex) do <<-'EOS'
|
87
|
-
\begin{figure}
|
87
|
+
\begin{figure}
|
88
|
+
\begin{quote}
|
88
89
|
lorem
|
90
|
+
\end{quote}
|
89
91
|
\label{fig:foo}
|
90
92
|
\end{figure}
|
91
93
|
|
@@ -96,7 +98,9 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
96
98
|
it do
|
97
99
|
should resemble <<-'EOS'
|
98
100
|
<div id="fig-foo" data-tralics-id="uid1" data-number="1" class="figure">
|
99
|
-
<
|
101
|
+
<blockquote class="quotation">
|
102
|
+
<p class="quote">lorem</p>
|
103
|
+
</blockquote>
|
100
104
|
<div class="caption">
|
101
105
|
<span class="header">Figure 1</span>
|
102
106
|
</div>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polytexnic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
292
|
version: '0'
|
293
293
|
requirements: []
|
294
294
|
rubyforge_project:
|
295
|
-
rubygems_version: 2.
|
295
|
+
rubygems_version: 2.4.5
|
296
296
|
signing_key:
|
297
297
|
specification_version: 4
|
298
298
|
summary: Convert from PolyTeX & Markdown to HTML & LaTeX
|