polytexnic 1.1.14 → 1.2.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.
- checksums.yaml +4 -4
- data/lib/polytexnic/postprocessors/html.rb +20 -6
- data/lib/polytexnic/preprocessors/html.rb +4 -2
- data/lib/polytexnic/utils.rb +1 -1
- data/lib/polytexnic/version.rb +1 -1
- data/lib/polytexnic.rb +2 -1
- data/spec/to_html/core_spec.rb +10 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 889d526bb149a5216215bcc4aec2ed9454214c56
|
4
|
+
data.tar.gz: b78febaefb8e5c65b5e353d96e79791088970a94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1830eef955e1288ca5d02cb3fc5e92894309f97094ee3882286fabcfb5b471f4f4e852a56b44a580601dc60b2f0f45e4e71688768eff75ee9cf1236c365682b
|
7
|
+
data.tar.gz: fc21b6e1e2daf2edf6e586433de3b0fd91b8840ccad145702576f473ff7f43ad0684495df566c2fe89ae15c69f4b3b45cda27bf1ec1baf59c2e430e5e18aa348
|
@@ -1238,18 +1238,31 @@ module Polytexnic
|
|
1238
1238
|
# Trims empty paragraphs.
|
1239
1239
|
# Sometimes a <p></p> creeps in due to idiosyncrasies of the
|
1240
1240
|
# Tralics conversion.
|
1241
|
-
def trim_empty_paragraphs(string)
|
1242
|
-
string.gsub!(/<p>\s*<\/p
|
1241
|
+
def trim_empty_paragraphs!(string)
|
1242
|
+
string.gsub!(/<p>\s*<\/p>/m, '')
|
1243
1243
|
end
|
1244
1244
|
|
1245
|
-
#
|
1245
|
+
# Restores quotes or verse inside figure.
|
1246
1246
|
# This is a terrible hack.
|
1247
|
-
def restore_figure_quotes(string)
|
1247
|
+
def restore_figure_quotes!(string)
|
1248
1248
|
figure_quote_cache.each do |key, html|
|
1249
1249
|
string.gsub!(/<p>\s*#{key}\s*<\/p>/m, html)
|
1250
1250
|
end
|
1251
1251
|
end
|
1252
1252
|
|
1253
|
+
# Retores literal HTML included via %=.
|
1254
|
+
# E.g., writing
|
1255
|
+
# %= </span>
|
1256
|
+
# inserts a literal closing span tag into the HTML output.
|
1257
|
+
def restore_literal_html!(string)
|
1258
|
+
literal_html_cache.each do |key, html|
|
1259
|
+
string.gsub!(/<p>\s*<literalhtml>#{key}<\/literalhtml>\s*<\/p>/m,
|
1260
|
+
html)
|
1261
|
+
string.gsub!(/<literalhtml>#{key}<\/literalhtml>/, html)
|
1262
|
+
end
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
|
1253
1266
|
# Converts a document to HTML.
|
1254
1267
|
# Because there's no way to know which elements are block-level
|
1255
1268
|
# (and hence can't be nested inside a paragraph tag), we first extract
|
@@ -1266,8 +1279,9 @@ module Polytexnic
|
|
1266
1279
|
end
|
1267
1280
|
body = doc.at_css('document').children.to_xhtml
|
1268
1281
|
Nokogiri::HTML.fragment(body).to_xhtml.tap do |html|
|
1269
|
-
trim_empty_paragraphs(html)
|
1270
|
-
restore_figure_quotes(html)
|
1282
|
+
trim_empty_paragraphs!(html)
|
1283
|
+
restore_figure_quotes!(html)
|
1284
|
+
restore_literal_html!(html)
|
1271
1285
|
end
|
1272
1286
|
end
|
1273
1287
|
|
@@ -120,11 +120,13 @@ module Polytexnic
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# Removes commented-out lines.
|
123
|
-
# Contents of the special sequence `%=` are converted to HTML
|
123
|
+
# Contents of the special sequence `%=` are converted to literal HTML.
|
124
124
|
def remove_comments(output)
|
125
125
|
output.gsub!(/[^\\]%[^=].*$/, '')
|
126
126
|
output.gsub!(/[^\\]%=(.*)$/) do
|
127
|
-
|
127
|
+
key = digest($1)
|
128
|
+
literal_html_cache[key] = $1
|
129
|
+
xmlelement('literalhtml') { key }
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
data/lib/polytexnic/utils.rb
CHANGED
@@ -241,7 +241,7 @@ module Polytexnic
|
|
241
241
|
# because in Ruby '\\foo' is the same as '\\\\foo', '\}' is '}', etc.
|
242
242
|
# I thought I escaped (heh) this problem with the `escape_backslashes`
|
243
243
|
# method, but here the problem is extremely specific. In particular,
|
244
|
-
# \\\{\} is really \\ and \{ and \}, but Ruby
|
244
|
+
# \\\{\} is really \\ and \{ and \}, but Ruby doesn't know WTF to do
|
245
245
|
# with it, and thinks that it's "\\{}", which is the same as '\{}'.
|
246
246
|
# The solution is to replace '\\\\' with some number of backslashes.
|
247
247
|
# How many? I literally had to just keep adding backslashes until
|
data/lib/polytexnic/version.rb
CHANGED
data/lib/polytexnic.rb
CHANGED
@@ -39,13 +39,14 @@ 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, :figure_quote_cache
|
42
|
+
:article, :figure_quote_cache, :literal_html_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
48
|
@figure_quote_cache = {}
|
49
|
+
@literal_html_cache = {}
|
49
50
|
@maketitle_elements = {}
|
50
51
|
@article = options[:article]
|
51
52
|
@language_labels = if (labels = options[:language_labels]).nil?
|
data/spec/to_html/core_spec.rb
CHANGED
@@ -70,8 +70,16 @@ describe 'Polytexnic::Pipeline#to_html' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
context "with a percent-equals" do
|
73
|
-
|
74
|
-
|
73
|
+
|
74
|
+
context "with an opening tag" do
|
75
|
+
let(:polytex) { '%= <span id="foo" class="bar">' }
|
76
|
+
it { should eq '<span id="foo" class="bar">' }
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with a closing tag" do
|
80
|
+
let(:polytex) { '%= </span>' }
|
81
|
+
it { should eq '</span>' }
|
82
|
+
end
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
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.2.0
|
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: 2016-
|
12
|
+
date: 2016-02-17 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.4.5
|
295
|
+
rubygems_version: 2.4.5.1
|
296
296
|
signing_key:
|
297
297
|
specification_version: 4
|
298
298
|
summary: Convert from PolyTeX & Markdown to HTML & LaTeX
|