polytexnic 0.7.3 → 0.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50ed75b9b53138ba115a7af87b3dc690e4dbcf70
4
- data.tar.gz: d9a7c85d261e77667c483163c299434e7099a9b7
3
+ metadata.gz: 79efdbbf104728740b5f914246576bed48de4e7f
4
+ data.tar.gz: db68bb996ee36dae5a50d11d148a99a4fb27185c
5
5
  SHA512:
6
- metadata.gz: 124b21054c5e3f1cad103613afeeb1b6c139ff52a5d588e5374b4cf195e73d9752884e6da60480431f3cf6802479be3f5bd8aea3d2f877605e588e17d91ed81c
7
- data.tar.gz: 5604d325b1edabdef96de6a27cfdd26cd8b7fda8f5af91448c7c3606a68207866d1137551565b661cbbff8ad3fe95eb65b2cca5eb12332f628cf3d5a7cbbc0e1
6
+ metadata.gz: e2d1c109775edd3a36dedd8419e1a35c9897b64c413058e23ca5cb106619e2167a475e771bc94a4ccc59bc066a5c466888a8924826347c68b7efbeeeb9dad49a
7
+ data.tar.gz: 1048adc5309ab22bab8ba836cb31017451c33ea51a70dd46e5fa15ac3cdacccfb49dd156cf876dba0ae0eba585f07fbd1e55a69e17671ab093d34530432811c9
File without changes
@@ -111,7 +111,6 @@ module Polytexnic
111
111
  text = []
112
112
  text << line if line.math_environment? || (latex && !language)
113
113
  while (line = lines.shift)
114
- puts line.inspect if debug?
115
114
  if line.begin_literal?(literal_type)
116
115
  count += 1
117
116
  elsif line.end_literal?(literal_type)
@@ -127,7 +126,6 @@ module Polytexnic
127
126
  end
128
127
  raise "Missing \\end{#{line.literal_type}}" if count != 0
129
128
  content = text.join("\n")
130
- puts content.inspect if debug?
131
129
  if math
132
130
  key = digest(content)
133
131
  literal_cache[key] = content
@@ -35,11 +35,20 @@ module Polytexnic
35
35
  # which reduces syntax highlighting to a previously solved problem.
36
36
  def write_polytex_code
37
37
  code_cache.each do |key, (code, lang, in_codelisting, options)|
38
+ # puts '*********'
39
+ # puts @source.inspect
40
+ # raise code.inspect
38
41
  latex = "%= lang:#{lang}#{options}\n" +
39
- "\\begin{code}\n#{code}\n\\end{code}"
42
+ "\\begin{code}\n" + escape_hack(code) + "\n\\end{code}"
40
43
  @source.gsub!(key, latex)
41
44
  end
42
45
  end
46
+
47
+ # Hacks some backslash escapes.
48
+ # Seriously, WTF is up with backslashes?
49
+ def escape_hack(string)
50
+ string.gsub('\\', '\\\\\\')
51
+ end
43
52
  end
44
53
  end
45
54
  end
@@ -1,3 +1,4 @@
1
+ # encoding=utf-8
1
2
  require 'securerandom'
2
3
  require 'json'
3
4
 
@@ -7,15 +8,25 @@ module Polytexnic
7
8
 
8
9
  # Returns the executable for the Tralics LaTeX-to-XML converter.
9
10
  def tralics
10
- filename = if RUBY_PLATFORM.match(/darwin/)
11
+ filename = if os_x?
11
12
  'tralics-os-x'
12
- elsif RUBY_PLATFORM.match(/linux/)
13
+ elsif linux?
13
14
  'tralics-linux'
14
15
  else
15
16
  raise "Platform #{RUBY_PLATFORM} not supported"
16
17
  end
17
- File.join(File.dirname(__FILE__), '..', '..',
18
- 'precompiled_binaries', filename)
18
+ project_root = File.join(File.dirname(__FILE__), '..', '..')
19
+ File.join(project_root, 'precompiled_binaries', filename)
20
+ end
21
+
22
+ # Returns true if platform is OS X.
23
+ def os_x?
24
+ RUBY_PLATFORM.match(/darwin/)
25
+ end
26
+
27
+ # Returns true if platform is Linux.
28
+ def linux?
29
+ RUBY_PLATFORM.match(/linux/)
19
30
  end
20
31
 
21
32
  # Returns a salted hash digest of the string.
@@ -177,7 +188,7 @@ module Polytexnic
177
188
  # with it, and thinks that it's "\\{}", which is the same as '\{}'.
178
189
  # The solution is to replace '\\\\' with some number of backslashes.
179
190
  # How many? I literally had to just keep adding backslashes until
180
- # the output was correct when running `poly build:pdf`.
191
+ # the output was correct when running `softcover build:pdf`.
181
192
  def horrible_backslash_kludge(string)
182
193
  string.gsub!(/commandchars=\\\\/, 'commandchars=\\\\\\\\')
183
194
  end
@@ -1,3 +1,3 @@
1
1
  module Polytexnic
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
data/lib/polytexnic.rb CHANGED
@@ -39,6 +39,7 @@ module Polytexnic
39
39
  @highlight_cache_filename = '.highlight_cache'
40
40
  if File.exist?(@highlight_cache_filename)
41
41
  content = File.read(@highlight_cache_filename)
42
+ .force_encoding('ASCII-8BIT')
42
43
  @highlight_cache = MessagePack.unpack(content) unless content.empty?
43
44
  end
44
45
  @highlight_cache ||= {}
@@ -403,6 +403,21 @@ lorem
403
403
  end
404
404
  it { should resemble output }
405
405
  end
406
+
407
+
408
+
409
+ context "with a code listing from Urbit that broke" do
410
+ let(:source) do <<-'EOS'
411
+ ```text
412
+ 'Foo \'bar'
413
+ 0x27
414
+ ```
415
+
416
+ foo
417
+ EOS
418
+ end
419
+ it { should_not include "\\begin{code}\n'Foo \n"}
420
+ end
406
421
  end
407
422
  end
408
423
  end
@@ -56,6 +56,29 @@ describe Polytexnic::Pipeline do
56
56
  it { should resemble '<div class="highlight">' }
57
57
  it { should resemble '<pre>' }
58
58
  end
59
+
60
+ context "with Unicode in the highlighting cache" do
61
+ let(:polytex) do <<-'EOS'
62
+ %= lang:console
63
+ \begin{code}
64
+ 'foo★bar'
65
+ \end{code}
66
+
67
+ %= lang:console
68
+ \begin{code}
69
+ foo
70
+ \end{code}
71
+ EOS
72
+ end
73
+ before do
74
+ # Create the broken highlight cache.
75
+ Polytexnic::Pipeline.new(polytex).to_html
76
+ end
77
+ it "should not crash" do
78
+ expect(File.exist?('.highlight_cache')).to be_true
79
+ expect { Polytexnic::Pipeline.new(polytex).to_html }.not_to raise_error
80
+ end
81
+ end
59
82
  end
60
83
 
61
84
  context "with a space after 'lang'" do
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.3
4
+ version: 0.7.4
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-11 00:00:00.000000000 Z
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -191,6 +191,7 @@ files:
191
191
  - .pull_requests/1386105869
192
192
  - .pull_requests/1386184858
193
193
  - .pull_requests/1386718874
194
+ - .pull_requests/1386936855
194
195
  - .rspec
195
196
  - Gemfile
196
197
  - Guardfile