polytexnic 0.7.6 → 0.7.7
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.
- checksums.yaml +4 -4
- data/.pull_requests/1387418273 +0 -0
- data/lib/polytexnic/postprocessors/html.rb +15 -3
- data/lib/polytexnic/preprocessors/html.rb +12 -6
- data/lib/polytexnic/preprocessors/polytex.rb +6 -4
- data/lib/polytexnic/version.rb +1 -1
- data/lib/polytexnic.rb +1 -1
- data/spec/markdown_to_polytex_spec.rb +12 -1
- data/spec/to_html/chapters_and_sections_spec.rb +21 -1
- data/spec/to_html/core_spec.rb +25 -1
- data/spec/to_html/table_spec.rb +29 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a292613f26b5df5bb474ef756294b4ff1a9b6069
|
4
|
+
data.tar.gz: f3925c8503988094dbc563cad18bc476a660b75e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3659cd17693bbd70c6a93b2aad80a27db49d3b580ca06dd98601b3f5878484bc800909ebee5e2f016e0d3ffb5a7880eedc139760bcf370027db5ef01e981c04
|
7
|
+
data.tar.gz: 6e8c25794bff35cb1874eedf6982bc25646d77a02d1519d07de05e4e1646d724de0bb3de59b497575313a6ca28229d7a6724934bbefa57d5574279d75086e91d
|
File without changes
|
@@ -681,8 +681,10 @@ module Polytexnic
|
|
681
681
|
if title_element
|
682
682
|
type = %w{title subtitle}.include?(field) ? 'h1' : 'h2'
|
683
683
|
el = Nokogiri::XML::Node.new(type, doc)
|
684
|
-
|
685
|
-
|
684
|
+
pipe = Polytexnic::Pipeline.new(title_element,
|
685
|
+
literal_cache: literal_cache)
|
686
|
+
raw_html = pipe.to_html
|
687
|
+
content = Nokogiri::HTML.fragment(raw_html).at_css('p')
|
686
688
|
unless (content.nil? && field == 'date')
|
687
689
|
el.inner_html = content.inner_html.strip
|
688
690
|
el['class'] = field
|
@@ -753,7 +755,8 @@ module Polytexnic
|
|
753
755
|
if (head = node.css('h1 a, h2 a, h3 a').first)
|
754
756
|
el = doc.create_element 'span'
|
755
757
|
number = node['data-number']
|
756
|
-
|
758
|
+
is_section = number.match(/\./)
|
759
|
+
prefix = (@cha.nil? || is_section) ? '' : "#{chaptername} "
|
757
760
|
el.content = prefix + node['data-number'] + ' '
|
758
761
|
el['class'] = 'number'
|
759
762
|
chapter_name = head.children.first
|
@@ -791,6 +794,15 @@ module Polytexnic
|
|
791
794
|
end
|
792
795
|
end
|
793
796
|
|
797
|
+
# Returns the name to use for chapters.
|
798
|
+
# The default is 'Chapter', of course, but this can be overriden
|
799
|
+
# using '\renewcommand', especially in books other than Engilsh.
|
800
|
+
def chaptername
|
801
|
+
name_regex = /\\renewcommand\{\\chaptername\}\{(.*?)\}/
|
802
|
+
name = custom_commands.scan(name_regex).flatten.last
|
803
|
+
name || 'Chapter'
|
804
|
+
end
|
805
|
+
|
794
806
|
# Returns the formatted number appropriate for the node.
|
795
807
|
# E.g., "2.1" for a section.
|
796
808
|
# Note: sets @cha as a side-effect. Yes, this is gross.
|
@@ -122,10 +122,10 @@ module Polytexnic
|
|
122
122
|
lines = []
|
123
123
|
in_table = false
|
124
124
|
string.split("\n").each do |line|
|
125
|
-
in_table ||= (line =~ /^\s*\\begin{(?:
|
125
|
+
in_table ||= (line =~ /^\s*\\begin{(?:tabularx?|longtable)}/)
|
126
126
|
line.gsub!('\\\\', xmlelement('backslashbreak')) unless in_table
|
127
127
|
lines << line
|
128
|
-
in_table = (in_table && line !~ /^\s*\\end{
|
128
|
+
in_table = (in_table && line !~ /^\s*\\end{tabularx?}/)
|
129
129
|
end
|
130
130
|
lines.join("\n")
|
131
131
|
end
|
@@ -216,13 +216,19 @@ module Polytexnic
|
|
216
216
|
output.replace(centered)
|
217
217
|
end
|
218
218
|
|
219
|
-
# Converts the
|
220
|
-
# This is
|
219
|
+
# Converts the alt table environments to simple tabular.
|
220
|
+
# This is was originaly because kramdown outputs longtables by default,
|
221
221
|
# but as a side-effect you can also use longtables in PolyTeX
|
222
|
-
# input documents.
|
222
|
+
# input documents. The latest update includes support for the tabularx
|
223
|
+
# environment
|
223
224
|
def convert_longtable(output)
|
224
225
|
output.gsub!('\begin{longtable}', '\begin{tabular}')
|
225
226
|
output.gsub!('\end{longtable}', '\end{tabular}')
|
227
|
+
output.gsub!(/\\begin\{tabularx\}\{.*?\}\{(.*)\}/) do
|
228
|
+
alignment = $1.gsub('X', 'l') # X becomes left-justified in HTML
|
229
|
+
"\\begin{tabular}{#{alignment}}"
|
230
|
+
end
|
231
|
+
output.gsub!('\end{tabularx}', '\end{tabular}')
|
226
232
|
end
|
227
233
|
|
228
234
|
# Marks environments with their types.
|
@@ -287,7 +293,7 @@ module Polytexnic
|
|
287
293
|
# I've tried in vain to figure out WTF is going on in the Tralics
|
288
294
|
# source, but it's easy enough in Ruby so I'm throwing it in here.
|
289
295
|
def make_tabular_alignment_cache(output)
|
290
|
-
alignment_regex = /^\s*\\begin{tabular}{((?:\|*[lcr]+\|*)+)}/
|
296
|
+
alignment_regex = /^\s*\\begin{tabular}{\s*((?:\|*[lcr]+\|*)+)\s*}/
|
291
297
|
@tabular_alignment_cache = output.scan(alignment_regex).flatten
|
292
298
|
end
|
293
299
|
|
@@ -26,7 +26,7 @@ module Polytexnic
|
|
26
26
|
require 'kramdown'
|
27
27
|
cache = {}
|
28
28
|
math_cache = {}
|
29
|
-
cleaned_markdown = cache_code_environments
|
29
|
+
cleaned_markdown = cache_code_environments(@source)
|
30
30
|
puts cleaned_markdown if debug?
|
31
31
|
cleaned_markdown.tap do |markdown|
|
32
32
|
convert_code_inclusion(markdown, cache)
|
@@ -63,7 +63,9 @@ module Polytexnic
|
|
63
63
|
|
64
64
|
# Caches literal LaTeX environments.
|
65
65
|
def cache_latex_literal(markdown, cache)
|
66
|
-
|
66
|
+
# Add tabular and tabularx support.
|
67
|
+
literal_types = Polytexnic::Literal.literal_types + %w[tabular tabularx]
|
68
|
+
literal_types.each do |literal|
|
67
69
|
regex = /(\\begin\{#{Regexp.escape(literal)}\}
|
68
70
|
.*?
|
69
71
|
\\end\{#{Regexp.escape(literal)}\})
|
@@ -135,9 +137,9 @@ module Polytexnic
|
|
135
137
|
# Caches Markdown code environments.
|
136
138
|
# Included are indented environments, Leanpub-style indented environments,
|
137
139
|
# and GitHub-style code fencing.
|
138
|
-
def cache_code_environments
|
140
|
+
def cache_code_environments(source)
|
139
141
|
output = []
|
140
|
-
lines =
|
142
|
+
lines = source.split("\n")
|
141
143
|
indentation = ' ' * 4
|
142
144
|
while (line = lines.shift)
|
143
145
|
if line =~ /\{lang="(.*?)"\}/
|
data/lib/polytexnic/version.rb
CHANGED
data/lib/polytexnic.rb
CHANGED
@@ -40,7 +40,7 @@ Lorem ipsum
|
|
40
40
|
it { should_not include '\hypertarget' }
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
context "hyphenation" do
|
44
44
|
let(:source) { 'profes\-sional' }
|
45
45
|
it { should include source }
|
46
46
|
end
|
@@ -302,6 +302,17 @@ def foo; "bar"; end
|
|
302
302
|
end
|
303
303
|
it { should resemble '\chapter{Foo}' }
|
304
304
|
end
|
305
|
+
|
306
|
+
context "a tabular LaTeX environment" do
|
307
|
+
let(:source) do <<-'EOS'
|
308
|
+
\begin{tabularx}
|
309
|
+
a & b \\
|
310
|
+
c & d
|
311
|
+
\end{tabularx}
|
312
|
+
EOS
|
313
|
+
end
|
314
|
+
it { should resemble source }
|
315
|
+
end
|
305
316
|
end
|
306
317
|
|
307
318
|
describe "source code" do
|
@@ -3,7 +3,8 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe 'Polytexnic::Pipeline#to_html' do
|
5
5
|
|
6
|
-
|
6
|
+
let(:pipeline) { Polytexnic::Pipeline.new(polytex) }
|
7
|
+
subject(:processed_text) { pipeline.to_html }
|
7
8
|
|
8
9
|
describe '\chapter' do
|
9
10
|
context "with a name" do
|
@@ -36,6 +37,25 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
36
37
|
it { should resemble output }
|
37
38
|
end
|
38
39
|
|
40
|
+
context "with an alternate to 'Chapter'" do
|
41
|
+
before do
|
42
|
+
pipeline.stub(:custom_commands).
|
43
|
+
and_return('\renewcommand{\chaptername}{Chapitre}')
|
44
|
+
end
|
45
|
+
let(:polytex) do <<-'EOS'
|
46
|
+
\chapter{Foo \emph{bar}}
|
47
|
+
\label{cha:foo}
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
let(:output) do <<-'EOS'
|
51
|
+
<div id="cha-foo" data-tralics-id="cid1" class="chapter" data-number="1">
|
52
|
+
<h1><a href="#cha-foo" class="heading"><span class="number">Chapitre 1 </span>Foo <em>bar</em></a></h1>
|
53
|
+
</div>
|
54
|
+
EOS
|
55
|
+
end
|
56
|
+
it { should resemble output }
|
57
|
+
end
|
58
|
+
|
39
59
|
end
|
40
60
|
|
41
61
|
describe '\section' do
|
data/spec/to_html/core_spec.rb
CHANGED
@@ -96,7 +96,7 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
96
96
|
|
97
97
|
describe '\maketitle' do
|
98
98
|
|
99
|
-
context "with all
|
99
|
+
context "with all elements filled out explicitly" do
|
100
100
|
let(:polytex) do <<-'EOS'
|
101
101
|
\title{Foo \\ \emph{Bar}}
|
102
102
|
\subtitle{Baz}
|
@@ -124,6 +124,30 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
context "with Unicode" do
|
128
|
+
let(:polytex) do <<-'EOS'
|
129
|
+
\title{A könyv címe}
|
130
|
+
\subtitle{Alcím - itt lesz az alcím}
|
131
|
+
\author{Árvíztűrő fúrógép}
|
132
|
+
\date{January 1, 2013}
|
133
|
+
\begin{document}
|
134
|
+
\maketitle
|
135
|
+
\end{document}
|
136
|
+
EOS
|
137
|
+
end
|
138
|
+
|
139
|
+
it do
|
140
|
+
should resemble <<-'EOS'
|
141
|
+
<div id="title_page">
|
142
|
+
<h1 class="title">A k<span class="unicode">ö</span>nyv c<span class="unicode">í</span>me</h1>
|
143
|
+
<h1 class="subtitle">Alc<span class="unicode">í</span>m - itt lesz az alc<span class="unicode">í</span>m</h1>
|
144
|
+
<h2 class="author"><span class="unicode">Á</span>rv<span class="unicode">í</span>zt<span class="unicode">ű</span>r<span class="unicode">ő</span> f<span class="unicode">ú</span>r<span class="unicode">ó</span>g<span class="unicode">é</span>p</h2>
|
145
|
+
<h2 class="date">January 1, 2013</h2>
|
146
|
+
</div>
|
147
|
+
EOS
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
127
151
|
context "when date is blank" do
|
128
152
|
let(:polytex) do <<-'EOS'
|
129
153
|
\title{Foo \\ \emph{Bar}}
|
data/spec/to_html/table_spec.rb
CHANGED
@@ -51,6 +51,35 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
context "tabularx environments" do
|
55
|
+
let(:polytex) do <<-'EOS'
|
56
|
+
\begin{tabularx}{\textwidth}{ |l|l|l|l| }
|
57
|
+
\hline
|
58
|
+
label 1 & label 2 & label 3 & label 4 \\
|
59
|
+
\hline
|
60
|
+
item 1 & item 2 & item 3 & item 4 \\
|
61
|
+
\hline
|
62
|
+
\end{tabularx}
|
63
|
+
EOS
|
64
|
+
end
|
65
|
+
let(:output) do <<-'EOS'
|
66
|
+
<table class="tabular">
|
67
|
+
<tr class="top_border bottom_border"><td class="left_border align_left right_border">label 1</td>
|
68
|
+
<td class="align_left right_border">label 2</td>
|
69
|
+
<td class="align_left right_border">label 3</td>
|
70
|
+
<td class="align_left right_border">label 4</td>
|
71
|
+
</tr>
|
72
|
+
<tr class="bottom_border"><td class="left_border align_left right_border">item 1</td>
|
73
|
+
<td class="align_left right_border">item 2</td>
|
74
|
+
<td class="align_left right_border">item 3</td>
|
75
|
+
<td class="align_left right_border">item 4</td>
|
76
|
+
</tr>
|
77
|
+
</table>
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
it { should resemble output }
|
81
|
+
end
|
82
|
+
|
54
83
|
context "more complicated left-aligned cells with lines" do
|
55
84
|
let(:polytex) do <<-'EOS'
|
56
85
|
\begin{tabular}{|l|lll|}
|
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: 0.7.
|
4
|
+
version: 0.7.7
|
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: 2013-12-
|
12
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- .pull_requests/1386936855
|
195
195
|
- .pull_requests/1387316123
|
196
196
|
- .pull_requests/1387337421
|
197
|
+
- .pull_requests/1387418273
|
197
198
|
- .rspec
|
198
199
|
- Gemfile
|
199
200
|
- Guardfile
|