polytexnic 1.1.0 → 1.1.1
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 +19 -5
- data/lib/polytexnic/preprocessors/html.rb +5 -1
- data/lib/polytexnic/version.rb +1 -1
- data/spec/to_html/core_spec.rb +11 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de8929b21f46055c1eccdbbc6ead05b0d5aa3480
|
4
|
+
data.tar.gz: f62ab6bd126d89ce3091240bfb2756447d30f19c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc6ab63fc1aaa5eb4ac4c6832af09891b5d20912344f3534e7cc26f4e0a0abc5440d4a77e23cebac50fd5f73616ac54af5cce165ca6a6e0797e01c46bd144d4
|
7
|
+
data.tar.gz: 8e93034c107c9be60ec2cf18051b659c626160f1238f84b5cb609aa330cd6285a6e2a877dd1cb253e44f3026bb0349362c200c401a4818b3000a395c443ff189
|
@@ -5,7 +5,9 @@ module Polytexnic
|
|
5
5
|
|
6
6
|
# Converts Tralics XML output to HTML.
|
7
7
|
def xml_to_html(xml)
|
8
|
+
restore_underscores(xml)
|
8
9
|
doc = Nokogiri::XML(xml)
|
10
|
+
comments(doc)
|
9
11
|
emphasis(doc)
|
10
12
|
boldface(doc)
|
11
13
|
small_caps(doc)
|
@@ -56,6 +58,21 @@ module Polytexnic
|
|
56
58
|
|
57
59
|
private
|
58
60
|
|
61
|
+
# Restores underscores.
|
62
|
+
# Tralics does weird stuff with underscores, in some contexts,
|
63
|
+
# so they are subbed out and passed through the pipeline intact.
|
64
|
+
# This is where we restore them.
|
65
|
+
def restore_underscores(xml)
|
66
|
+
xml.gsub!(underscore_digest, '_')
|
67
|
+
end
|
68
|
+
|
69
|
+
# Replaces comment content with proper HTML comments.
|
70
|
+
def comments(doc)
|
71
|
+
doc.xpath('//comment').each do |node|
|
72
|
+
node.replace("<!-- #{node.inner_html} -->")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
59
76
|
# Handles output of \emph{} and \textit{}.
|
60
77
|
def emphasis(doc)
|
61
78
|
doc.xpath('//hi[@rend="it"]').each do |node|
|
@@ -538,12 +555,9 @@ module Polytexnic
|
|
538
555
|
end
|
539
556
|
end
|
540
557
|
|
541
|
-
#
|
542
|
-
# Tralics does weird stuff with underscores, so they are subbed out
|
543
|
-
# so that they can be passed through the pipeline intact. This is where
|
544
|
-
# we restore them.
|
558
|
+
# Pulls the label out of the node.
|
545
559
|
def pipeline_label(node)
|
546
|
-
node.inner_html
|
560
|
+
node.inner_html
|
547
561
|
end
|
548
562
|
|
549
563
|
# Processes the <head> tag given a section node.
|
@@ -120,8 +120,12 @@ module Polytexnic
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# Removes commented-out lines.
|
123
|
+
# Contents of the special sequence `%=` are converted to HTML comments.
|
123
124
|
def remove_comments(output)
|
124
|
-
output.gsub!(/[^\\]
|
125
|
+
output.gsub!(/[^\\]%[^=].*$/, '')
|
126
|
+
output.gsub!(/[^\\]%=(.*)$/) do
|
127
|
+
xmlelement('comment') { $1.gsub('_', underscore_digest) }
|
128
|
+
end
|
125
129
|
end
|
126
130
|
|
127
131
|
# Converts LaTeX double backslashes to HTML breaks.
|
data/lib/polytexnic/version.rb
CHANGED
data/spec/to_html/core_spec.rb
CHANGED
@@ -18,11 +18,6 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
18
18
|
it { should eq '' }
|
19
19
|
end
|
20
20
|
|
21
|
-
context "with a manual break" do
|
22
|
-
let(:polytex) { 'foo \\\\ bar' }
|
23
|
-
it { should include '<span class="break">' }
|
24
|
-
end
|
25
|
-
|
26
21
|
context "with a code listing" do
|
27
22
|
let(:polytex) do <<-'EOS'
|
28
23
|
% \begin{codelisting}
|
@@ -73,6 +68,11 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
73
68
|
end
|
74
69
|
it { should eq '' }
|
75
70
|
end
|
71
|
+
|
72
|
+
context "with a percent-equals" do
|
73
|
+
let(:polytex) { '%= literal_text' }
|
74
|
+
it { should include '<!-- literal_text -->' }
|
75
|
+
end
|
76
76
|
end
|
77
77
|
|
78
78
|
describe "a complete document" do
|
@@ -88,6 +88,12 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
88
88
|
it { should resemble "<p>lorem ipsum</p>" }
|
89
89
|
end
|
90
90
|
|
91
|
+
describe "a manual break" do
|
92
|
+
let(:polytex) { 'foo \\\\ bar' }
|
93
|
+
it { should include '<span class="break">' }
|
94
|
+
end
|
95
|
+
|
96
|
+
|
91
97
|
describe "paragraphs" do
|
92
98
|
let(:polytex) { 'lorem ipsum' }
|
93
99
|
it { should resemble "<p>lorem ipsum</p>" }
|
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.1
|
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-05-
|
12
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|