polytexnic 1.0.4 → 1.1.beta1
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/lib/polytexnic/postprocessors/html.rb +20 -5
- data/lib/polytexnic/version.rb +1 -1
- data/lib/polytexnic.rb +3 -1
- data/spec/articles_spec.rb +90 -0
- data/spec/to_html/chapters_and_sections_spec.rb +3 -1
- data/spec/to_html/characters_and_punctuation_spec.rb +4 -4
- data/spec/to_html/graphics_and_figures_spec.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de97a8848a323aaaa3558b8cac21a2273404b1f8
|
4
|
+
data.tar.gz: 3064c4792f08d5812d9ad45e699861e03377994e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b617bb00aef112924e92c74e297d11a2375472b95b676f59792da1f973c1707ec2d6613872972e8f6353b2db0d2bbd2e9fc139bde84040c5dfdbdb2dcb1638d
|
7
|
+
data.tar.gz: c92ea88a740e56f74300246670e37777220a0e7e797ad84b0a98aa6832537b3ed06ef0388019bc8c845db7b4615ff33dceb03b1634f2a5bc62e8dc7e587f139b
|
@@ -390,6 +390,7 @@ module Polytexnic
|
|
390
390
|
# so recursively search the parents to find it.
|
391
391
|
# Then return the first number in the value, e.g., "1" in "1.2".
|
392
392
|
def chapter_number(node)
|
393
|
+
return 0 if article?
|
393
394
|
number = node['data-number']
|
394
395
|
if number && !number.empty?
|
395
396
|
number.split('.').first.to_i
|
@@ -410,12 +411,12 @@ module Polytexnic
|
|
410
411
|
|
411
412
|
# Returns HTML for a nicely styled TeX logo.
|
412
413
|
def tex
|
413
|
-
%(<span class="texhtml">T<span
|
414
|
+
%(<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>)
|
414
415
|
end
|
415
416
|
|
416
417
|
# Returns HTML for a nicely styled LaTeX logo.
|
417
418
|
def latex
|
418
|
-
%(<span class="texhtml">L<span
|
419
|
+
%(<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>)
|
419
420
|
end
|
420
421
|
|
421
422
|
# Handles \begin{quote} ... \end{quote}.
|
@@ -494,11 +495,12 @@ module Polytexnic
|
|
494
495
|
label = node.at_css('data-label')
|
495
496
|
node['id'] = pipeline_label(label)
|
496
497
|
unexpected.remove
|
498
|
+
clean_node node, %w{data-label}
|
497
499
|
elsif label = node.at_css('data-label')
|
498
500
|
node['id'] = pipeline_label(label)
|
499
501
|
label.remove
|
502
|
+
clean_node node, %w{data-label}
|
500
503
|
end
|
501
|
-
clean_node node, %w{data-label place}
|
502
504
|
end
|
503
505
|
doc.xpath('//table').each do |node|
|
504
506
|
if unexpected = node.at_css('unexpected')
|
@@ -666,6 +668,7 @@ module Polytexnic
|
|
666
668
|
heading['class'] = 'heading'
|
667
669
|
|
668
670
|
number = heading.at_css('strong')
|
671
|
+
number.content = number.content.sub!('0.', '') if article?
|
669
672
|
number.name = 'span'
|
670
673
|
number['class'] = 'number'
|
671
674
|
if css_class == 'codelisting'
|
@@ -896,7 +899,7 @@ module Polytexnic
|
|
896
899
|
@equation = 0
|
897
900
|
@figure = 0
|
898
901
|
@table = 0
|
899
|
-
@cha = node['id-text']
|
902
|
+
@cha = article? ? nil : node['id-text']
|
900
903
|
elsif node['class'] == 'section'
|
901
904
|
@sec = node['id-text']
|
902
905
|
label_number(@cha, @sec)
|
@@ -914,7 +917,8 @@ module Polytexnic
|
|
914
917
|
end
|
915
918
|
label_number(@cha, @equation)
|
916
919
|
elsif node['class'] == 'codelisting'
|
917
|
-
node['id-text']
|
920
|
+
@listing = number_from_id(node['id-text'])
|
921
|
+
label_number(@cha, @listing)
|
918
922
|
elsif node['class'] == 'aside'
|
919
923
|
node['id-text']
|
920
924
|
elsif node.name == 'table' && node['id-text']
|
@@ -934,6 +938,17 @@ module Polytexnic
|
|
934
938
|
end
|
935
939
|
end
|
936
940
|
|
941
|
+
# Extract the sequential number from the node id.
|
942
|
+
# I.e., number_from_id('2.3') -> '3'
|
943
|
+
def number_from_id(id)
|
944
|
+
id.split('.')[1]
|
945
|
+
end
|
946
|
+
|
947
|
+
# Returns true if pipeline was called on an article document.
|
948
|
+
def article?
|
949
|
+
!!article
|
950
|
+
end
|
951
|
+
|
937
952
|
# Returns a label number for use in headings.
|
938
953
|
# For example, label_number("1", "2") returns "1.2".
|
939
954
|
def label_number(*args)
|
data/lib/polytexnic/version.rb
CHANGED
data/lib/polytexnic.rb
CHANGED
@@ -38,13 +38,15 @@ module Polytexnic
|
|
38
38
|
|
39
39
|
attr_accessor :literal_cache, :code_cache, :polytex, :xml, :html,
|
40
40
|
:math_label_cache, :highlight_cache, :maketitle_elements,
|
41
|
-
:custom_commands, :language_labels, :unicode_cache
|
41
|
+
:custom_commands, :language_labels, :unicode_cache,
|
42
|
+
:article
|
42
43
|
|
43
44
|
def initialize(source, options = {})
|
44
45
|
@literal_cache = options[:literal_cache] || {}
|
45
46
|
@unicode_cache = {}
|
46
47
|
@code_cache = {}
|
47
48
|
@maketitle_elements = {}
|
49
|
+
@article = options[:article]
|
48
50
|
@language_labels = if (labels = options[:language_labels]).nil?
|
49
51
|
default_language_labels
|
50
52
|
else
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding=utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "articles" do
|
5
|
+
let(:pipeline) { Polytexnic::Pipeline.new(polytex, article: true) }
|
6
|
+
subject(:processed_text) { pipeline.to_html }
|
7
|
+
|
8
|
+
let(:polytex) do <<-'EOS'
|
9
|
+
Lorem ipsum
|
10
|
+
\section{Foo}
|
11
|
+
\label{sec:foo}
|
12
|
+
|
13
|
+
\begin{figure}
|
14
|
+
lorem
|
15
|
+
\label{fig:foo}
|
16
|
+
\end{figure}
|
17
|
+
|
18
|
+
\begin{table}
|
19
|
+
\begin{tabular}{cc}
|
20
|
+
HTTP request & URL \\
|
21
|
+
GET & /users \\
|
22
|
+
GET & /users/1
|
23
|
+
\end{tabular}
|
24
|
+
\label{table:foo}
|
25
|
+
\end{table}
|
26
|
+
|
27
|
+
\begin{codelisting}
|
28
|
+
\codecaption{Creating a \texttt{gem} configuration file. \\ \filepath{path/to/file}}
|
29
|
+
\label{code:create_gemrc}
|
30
|
+
%= lang:console
|
31
|
+
\begin{code}
|
32
|
+
$ subl .gemrc
|
33
|
+
\end{code}
|
34
|
+
\end{codelisting}
|
35
|
+
|
36
|
+
Listing~\ref{code:create_gemrc}\footnote{asdfasdf}
|
37
|
+
|
38
|
+
Section~\ref{sec:foo}
|
39
|
+
|
40
|
+
Figure~\ref{fig:foo}
|
41
|
+
EOS
|
42
|
+
end
|
43
|
+
let(:section) { '<a href="#sec-foo" class="heading"><span class="number">1 </span>' }
|
44
|
+
let(:figure) { '<span class="header">Figure 1</span>' }
|
45
|
+
let(:table) { '<span class="header">Table 1</span>' }
|
46
|
+
let(:listing) { '<span class="number">Listing 1:</span>' }
|
47
|
+
let(:footnote) { '<sup id="cha-0_footnote-ref-1" class="footnote"><a href="#cha-0_footnote-1">1</a></sup>' }
|
48
|
+
|
49
|
+
let(:sref) { 'Section <span class="ref">1</span>' }
|
50
|
+
let(:fref) { 'Figure <span class="ref">1</span>' }
|
51
|
+
let(:lref) { 'Listing <span class="ref">1</span>' }
|
52
|
+
let(:fntext) { 'asdfasdf' }
|
53
|
+
|
54
|
+
describe "section" do
|
55
|
+
describe "numbering" do
|
56
|
+
it { should include section }
|
57
|
+
end
|
58
|
+
describe "xref" do
|
59
|
+
it { should resemble sref }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "figure" do
|
64
|
+
describe "numbering" do
|
65
|
+
it { should include figure }
|
66
|
+
end
|
67
|
+
describe "xref" do
|
68
|
+
it { should resemble fref }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "listing" do
|
73
|
+
describe "numbering" do
|
74
|
+
it { should include listing }
|
75
|
+
end
|
76
|
+
describe "xref" do
|
77
|
+
it { should resemble lref }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "footnote" do
|
82
|
+
it { should include '<ol class="footnotes">' }
|
83
|
+
describe "numbering" do
|
84
|
+
it { should include footnote }
|
85
|
+
end
|
86
|
+
describe "footnote text" do
|
87
|
+
it { should include fntext }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -108,11 +108,13 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
108
108
|
|
109
109
|
describe '\section' do
|
110
110
|
let(:polytex) do <<-'EOS'
|
111
|
+
Lorem ipsum
|
111
112
|
\section{Foo}
|
112
113
|
\label{sec:foo}
|
113
114
|
EOS
|
114
115
|
end
|
115
116
|
let(:output) do <<-'EOS'
|
117
|
+
<p>Lorem ipsum</p>
|
116
118
|
<div id="sec-foo" data-tralics-id="cid1" class="section" data-number="1">
|
117
119
|
<h2><a href="#sec-foo" class="heading"><span class="number">1 </span>Foo</a></h2>
|
118
120
|
</div>
|
@@ -333,4 +335,4 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
333
335
|
EOS
|
334
336
|
end
|
335
337
|
end
|
336
|
-
end
|
338
|
+
end
|
@@ -116,7 +116,7 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
116
116
|
describe "TeX logo" do
|
117
117
|
let(:polytex) { '\TeX' }
|
118
118
|
let(:output) do
|
119
|
-
%(<span class="texhtml">T<span
|
119
|
+
%(<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>)
|
120
120
|
end
|
121
121
|
it { should include(output) }
|
122
122
|
end
|
@@ -124,7 +124,7 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
124
124
|
describe "LaTeX logo" do
|
125
125
|
let(:polytex) { '\LaTeX' }
|
126
126
|
let(:output) do
|
127
|
-
%(<span class="texhtml">L<span
|
127
|
+
%(<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>)
|
128
128
|
end
|
129
129
|
it { should include(output) }
|
130
130
|
end
|
@@ -132,7 +132,7 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
132
132
|
describe "PolyTeX logo" do
|
133
133
|
let(:polytex) { '\PolyTeX' }
|
134
134
|
let(:output) do
|
135
|
-
%(Poly<span class="texhtml">T<span
|
135
|
+
%(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>)
|
136
136
|
end
|
137
137
|
it { should include(output) }
|
138
138
|
end
|
@@ -140,7 +140,7 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
140
140
|
describe "PolyTeXnic logo" do
|
141
141
|
let(:polytex) { '\PolyTeXnic' }
|
142
142
|
let(:output) do
|
143
|
-
%(Poly<span class="texhtml">T<span
|
143
|
+
%(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)
|
144
144
|
end
|
145
145
|
it { should include(output) }
|
146
146
|
end
|
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.
|
4
|
+
version: 1.1.beta1
|
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-03-
|
12
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- precompiled_binaries/tralics-os-x-newer
|
233
233
|
- precompiled_binaries/tralics-os-x-older
|
234
234
|
- precompiled_binaries/tralics-x86_64-linux
|
235
|
+
- spec/articles_spec.rb
|
235
236
|
- spec/fixtures/code_listing.tex
|
236
237
|
- spec/fixtures/figures.tex
|
237
238
|
- spec/fixtures/inline_math.html
|
@@ -286,9 +287,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
287
|
version: '0'
|
287
288
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
289
|
requirements:
|
289
|
-
- - "
|
290
|
+
- - ">"
|
290
291
|
- !ruby/object:Gem::Version
|
291
|
-
version:
|
292
|
+
version: 1.3.1
|
292
293
|
requirements: []
|
293
294
|
rubyforge_project:
|
294
295
|
rubygems_version: 2.2.2
|
@@ -296,6 +297,7 @@ signing_key:
|
|
296
297
|
specification_version: 4
|
297
298
|
summary: Convert from PolyTeX & Markdown to HTML & LaTeX
|
298
299
|
test_files:
|
300
|
+
- spec/articles_spec.rb
|
299
301
|
- spec/fixtures/code_listing.tex
|
300
302
|
- spec/fixtures/figures.tex
|
301
303
|
- spec/fixtures/inline_math.html
|