polytexnic 0.6.11 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57bbac0600d61db44cc14762bacc2a24594ab2c9
4
- data.tar.gz: fa73a4ee9071da8a1cd15c8bdc8224fd40368cee
3
+ metadata.gz: 6fefdba29706e24a266960f6a454f31341a88d94
4
+ data.tar.gz: 88c02fe48f01aa19d3ec84d18e3b4096a409fcc3
5
5
  SHA512:
6
- metadata.gz: 1e8b902671181b3e01162ee6aa1a6f8882e1b72d02364c33854b97922803771d1e23d0e9137adc3f5a743fa8c9694601afa916ba20a5d673d0c7b3a839ba8960
7
- data.tar.gz: 1e7f38cb586cce81529f9d3b29a5c732ad3176afa4bda9a56b834a0abcafc463e966173c0391de26cd31a69f70d87d9bc490357bab03d47091784e34de3ef69f
6
+ metadata.gz: d2f68541b94dda5f0a717bf6adeeb1df7d3ac2ff8a8908c1a0096eb126f5743e2e6e0f67b3654cbb685a3731089017e76f5221c4ccee15025b9354b904b073af
7
+ data.tar.gz: 10d075f42e1f407d3f7dda9843d16db013b267bad1e892c89831ce0d81ee554f5680124fc722466cbae783d21e2bd768ed0464e903065a6a6f3c14c84bf80afa
data/.gitignore CHANGED
@@ -35,3 +35,4 @@ log
35
35
  .DS_Store
36
36
  .api_token
37
37
  .project_id
38
+ .ruby-*
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -9,7 +9,7 @@ module Polytexnic
9
9
  # Matches the line for code inclusion.
10
10
  # %= <</path/to/code.ext
11
11
  CODE_INCLUSION_REGEX = /^\s*%=\s+<<\s*\( # opening
12
- \s*([\w\/-]+\.?(\w*)) # path
12
+ \s*([^\s]+) # path to file
13
13
  (?:,\s*lang:\s*(\w+))? # optional lang
14
14
  (,\s*options:\s*.*)? # optional options
15
15
  \s*\) # closing paren
@@ -83,13 +83,14 @@ module Polytexnic
83
83
  # <content of file.rb>
84
84
  # \end{code}
85
85
  # and then prepend the code to the current `lines` array.
86
- filename = $1
86
+ filename, custom_language, highlight_options = $1, $2, $3
87
+ extension_array = File.extname(filename).scan(/\.(.*)/).first
88
+ lang_from_extension = extension_array.nil? ? nil : extension_array[0]
87
89
  if File.exist?(filename)
88
- language = $3 || $2 || 'text'
89
- highlight_options = $4
90
+ language = custom_language || lang_from_extension || 'text'
90
91
  code = ["%= lang:#{language}#{highlight_options}"]
91
92
  code << '\begin{code}'
92
- code.concat(File.read($1).split("\n"))
93
+ code.concat(File.read(filename).split("\n"))
93
94
  code << '\end{code}'
94
95
  lines.unshift(*code)
95
96
  else
@@ -425,10 +425,12 @@ module Polytexnic
425
425
 
426
426
  # Returns the node for a list item (li).
427
427
  def item(doc)
428
+ doc.xpath('//item/p[@noindent="true"]').each do |node|
429
+ node.replace(node.inner_html)
430
+ end
428
431
  doc.xpath('//item').each do |node|
429
432
  clean_node node, %w{id-text id label}
430
433
  node.name = 'li'
431
- node.inner_html = node.at_css('p').inner_html
432
434
  end
433
435
  end
434
436
 
@@ -842,7 +844,7 @@ module Polytexnic
842
844
  def hrefs(doc)
843
845
  doc.xpath('//xref').each do |node|
844
846
  node.name = 'a'
845
- node['href'] = literal_cache[node['url']]
847
+ node['href'] = unescape_underscores(literal_cache[node['url']])
846
848
  # Put a class on hrefs containing TeX to allow a style override.
847
849
  node.traverse do |descendant|
848
850
  if descendant['class'] == 'texhtml'
@@ -854,6 +856,11 @@ module Polytexnic
854
856
  end
855
857
  end
856
858
 
859
+ # Unescapes underscores, which are escaped by kramdown.
860
+ def unescape_underscores(url)
861
+ url.gsub(/\\_/, '_')
862
+ end
863
+
857
864
  # Handles both \includegraphics and figure environments.
858
865
  # The unified treatment comes from Tralics using the <figure> tag
859
866
  # in both cases.
@@ -32,6 +32,7 @@ module Polytexnic
32
32
  convert_code_inclusion(markdown, cache)
33
33
  cache_latex_literal(markdown, cache)
34
34
  cache_raw_latex(markdown, cache)
35
+ cache_image_locations(markdown, cache)
35
36
  puts markdown if debug?
36
37
  cache_math(markdown, math_cache)
37
38
  end
@@ -39,6 +40,9 @@ module Polytexnic
39
40
  # Override the header ordering, which starts with 'section' by default.
40
41
  lh = 'chapter,section,subsection,subsubsection,paragraph,subparagraph'
41
42
  kramdown = Kramdown::Document.new(cleaned_markdown, latex_headers: lh)
43
+ puts kramdown.inspect if debug?
44
+ puts kramdown.to_html if debug?
45
+ puts kramdown.to_latex if debug?
42
46
  @source = kramdown.to_latex.tap do |polytex|
43
47
  remove_comments(polytex)
44
48
  convert_includegraphics(polytex)
@@ -75,7 +79,7 @@ module Polytexnic
75
79
  # Caches raw LaTeX commands to be passed through the pipeline.
76
80
  def cache_raw_latex(markdown, cache)
77
81
  command_regex = /(
78
- ^\s*\\\w+.*\}[ \t]*$ # Command on line with arg
82
+ ^[ \t]*\\\w+.*\}[ \t]*$ # Command on line with arg
79
83
  |
80
84
  ~\\ref\{.*?\} # reference with a tie
81
85
  |
@@ -90,6 +94,7 @@ module Polytexnic
90
94
  /x
91
95
  markdown.gsub!(command_regex) do
92
96
  content = $1
97
+ puts content.inspect if debug?
93
98
  key = digest(content)
94
99
  cache[key] = content
95
100
 
@@ -102,6 +107,18 @@ module Polytexnic
102
107
  end
103
108
  end
104
109
 
110
+ # Caches the locations of images to be passed through the pipeline.
111
+ # This works around a Kramdown bug, which fails to convert images
112
+ # properly when their location includes a URL.
113
+ def cache_image_locations(text, cache)
114
+ # Matches '![Image caption](/path/to/image)'
115
+ text.gsub!(/^\s*(!\[.*?\])\((.*?)\)/) do
116
+ key = digest($2)
117
+ cache[key] = $2
118
+ "\n#{$1}(#{key})"
119
+ end
120
+ end
121
+
105
122
  # Restores raw code from the cache
106
123
  def restore_hashed_content(text, cache)
107
124
  cache.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module Polytexnic
2
- VERSION = "0.6.11"
2
+ VERSION = "0.7.0"
3
3
  end
data/polytexnic.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency 'nokogiri', '~> 1.5.0'
21
+ gem.add_dependency 'nokogiri', '~> 1.6.0'
22
22
  gem.add_dependency 'pygments.rb', '~> 0.4.2'
23
23
  gem.add_dependency 'msgpack', '~> 0.4.2'
24
24
  gem.add_dependency 'kramdown'
@@ -35,12 +35,9 @@ Lorem ipsum
35
35
  end
36
36
 
37
37
  describe "with math" do
38
- subject do
39
- Polytexnic::Pipeline.new(markdown, source: :markdown).polytex
40
- end
41
38
 
42
39
  context "inline math" do
43
- let(:markdown) do <<-'EOS'
40
+ let(:source) do <<-'EOS'
44
41
  This is inline math: {$$} x^2 {/$$}.
45
42
  EOS
46
43
  end
@@ -49,7 +46,7 @@ This is inline math: {$$} x^2 {/$$}.
49
46
  end
50
47
 
51
48
  context "block math" do
52
- let(:markdown) do <<-'EOS'
49
+ let(:source) do <<-'EOS'
53
50
  This is block math:
54
51
  {$$}
55
52
  x^2
@@ -59,9 +56,27 @@ x^2
59
56
 
60
57
  it { should resemble '\[ x^2 \]' }
61
58
  end
59
+ end
62
60
 
63
- describe "tables" do
64
- let(:markdown) do <<-'EOS'
61
+ context "asides with internal lists" do
62
+ let(:source) do <<-'EOS'
63
+ \begin{aside}
64
+ \label{aside:softcover_uses}
65
+ \heading{How to use Softcover}
66
+
67
+ * Producing ebooks with `softcover` and giving them away
68
+ * Producing ebooks with `softcover` and selling them from your own website
69
+
70
+ \end{aside}
71
+
72
+ EOS
73
+ end
74
+ it { should include '\begin{aside}' }
75
+ it { should_not include "\\end{aside}\n\\end{itemize}" }
76
+ end
77
+
78
+ describe "tables" do
79
+ let(:source) do <<-'EOS'
65
80
  \begin{table}
66
81
 
67
82
  |**option**|**size**|**actual size**|
@@ -83,12 +98,11 @@ x^2
83
98
  \caption{A caption.}
84
99
  \end{table}
85
100
 
86
- EOS
87
- end
88
- it { should include '\begin{table}' }
89
- it { should include '\begin{longtable}' }
90
- it { should_not include '\textbar' }
101
+ EOS
91
102
  end
103
+ it { should include '\begin{table}' }
104
+ it { should include '\begin{longtable}' }
105
+ it { should_not include '\textbar' }
92
106
  end
93
107
 
94
108
  describe "footnotes" do
@@ -122,7 +136,7 @@ That is it. You can keep writing your text after the footnote content.
122
136
  Polytexnic::Pipeline.new(markdown, source: :markdown).polytex
123
137
  end
124
138
 
125
- context "inclusion with a caption and a label" do
139
+ context "with a caption and a label" do
126
140
  let(:markdown) do <<-'EOS'
127
141
  ![Running the Softcover server in a separate tab.\label{fig:softcover_server}](images/figures/softcover_server.png)
128
142
  EOS
@@ -133,6 +147,22 @@ That is it. You can keep writing your text after the footnote content.
133
147
  it { should_not include '\includegraphics' }
134
148
  end
135
149
 
150
+ context "using an example that failed" do
151
+ let(:markdown) do <<-'EOS'
152
+ a screenshot from [Lowdown](http://lowdownapp.com/), a web
153
+ application that developers use for organizing user stories.
154
+
155
+ ![Lowdown for user stories](https://tutorials.railsapps.org/assets/learn-rails-lowdown-partial.png)
156
+
157
+ Just like Rails provides a structure for building a web application,
158
+ user stories provide a structure for organizing your product plan.
159
+ EOS
160
+ end
161
+
162
+ it { should include '\caption{Lowdown for user stories}' }
163
+ it { should include '\image{https://tutorials.railsapps.org' }
164
+ end
165
+
136
166
  end
137
167
 
138
168
  context "with LaTeX containing" do
@@ -64,18 +64,19 @@ $ subl .gemrc
64
64
  it { should_not include 'Listing 1.1:' }
65
65
  end
66
66
 
67
- context "containing code inclusion with a hyphen" do
67
+ context "containing code inclusion with a hyphen and a leading dot" do
68
+ let(:filename) { '.name-with-hyphens.txt' }
68
69
  before do
69
- File.write(File.join('spec', 'fixtures', 'name-with-hyphens.txt'), '')
70
+ File.write(File.join('spec', 'fixtures', filename), '')
70
71
  end
71
72
  after do
72
- FileUtils.rm(File.join('spec', 'fixtures', 'name-with-hyphens.txt'))
73
+ FileUtils.rm(File.join('spec', 'fixtures', filename))
73
74
  end
74
75
  let(:polytex) do <<-'EOS'
75
76
  \begin{codelisting}
76
77
  \codecaption{Foo}
77
78
  \label{code:foo}
78
- %= <<(spec/fixtures/name-with-hyphens.txt, lang: text)
79
+ %= <<(spec/fixtures/.name-with-hyphens.txt, lang: text)
79
80
  \end{codelisting}
80
81
  EOS
81
82
  end
@@ -185,6 +185,11 @@ describe 'Polytexnic::Pipeline#to_html' do
185
185
  let(:output) { '<a href="http://example.com/" class="tex">' }
186
186
  it { should resemble output }
187
187
  end
188
+
189
+ context "URL containing escaped text" do
190
+ let(:polytex) { '\href{http://example.com/escaped\_text}{Example Site}' }
191
+ it { should include '<a href="http://example.com/escaped_text">Example Site</a>' }
192
+ end
188
193
  end
189
194
 
190
195
  describe "centering" do
@@ -61,7 +61,7 @@ describe 'Polytexnic::Pipeline#to_html' do
61
61
  end
62
62
  end
63
63
 
64
- context "afollowed by text" do
64
+ context "followed by text" do
65
65
  let(:polytex) do <<-'EOS'
66
66
  \begin{itemize}
67
67
  \item Foo
@@ -81,6 +81,44 @@ describe 'Polytexnic::Pipeline#to_html' do
81
81
  EOS
82
82
  end
83
83
  end
84
+
85
+ context "nested" do
86
+ let(:polytex) do <<-'EOS'
87
+ \begin{itemize}
88
+ \item foo
89
+
90
+
91
+ \begin{itemize}
92
+ \item bar
93
+ \item baz
94
+ \end{itemize}
95
+ \item quux
96
+
97
+
98
+ \begin{itemize}
99
+ \item dude
100
+ \end{itemize}
101
+ \end{itemize}
102
+ EOS
103
+ end
104
+ it do
105
+ should resemble <<-'EOS'
106
+ <ul>
107
+ <li>foo
108
+ <ul>
109
+ <li>bar</li>
110
+ <li>baz</li>
111
+ </ul>
112
+ </li>
113
+ <li>quux
114
+ <ul>
115
+ <li>dude</li>
116
+ </ul>
117
+ </li>
118
+ </ul>
119
+ EOS
120
+ end
121
+ end
84
122
  end
85
123
 
86
124
  describe "enumerated list" do
@@ -126,11 +126,7 @@ describe Polytexnic::Pipeline do
126
126
  %= <<(Rakefile)
127
127
  EOS
128
128
  end
129
- let(:output) do <<-'EOS'
130
- <span class="n">require</span>
131
- EOS
132
- end
133
- it { should resemble output }
129
+ it { should include '<pre>require' }
134
130
  end
135
131
 
136
132
  context "with an extension" 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.6.11
4
+ version: 0.7.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: 2013-11-30 00:00:00.000000000 Z
12
+ date: 2013-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 1.5.0
20
+ version: 1.6.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 1.5.0
27
+ version: 1.6.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: pygments.rb
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -185,9 +185,12 @@ files:
185
185
  - .pull_requests/1385598040
186
186
  - .pull_requests/1385601533
187
187
  - .pull_requests/1385778060
188
+ - .pull_requests/1385928695
189
+ - .pull_requests/1386022309
190
+ - .pull_requests/1386036048
191
+ - .pull_requests/1386105869
192
+ - .pull_requests/1386184858
188
193
  - .rspec
189
- - .ruby-gemset
190
- - .ruby-version
191
194
  - Gemfile
192
195
  - Guardfile
193
196
  - LICENSE.txt
@@ -266,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
269
  version: '0'
267
270
  requirements: []
268
271
  rubyforge_project:
269
- rubygems_version: 2.0.6
272
+ rubygems_version: 2.0.14
270
273
  signing_key:
271
274
  specification_version: 4
272
275
  summary: Convert from PolyTeX & Markdown to HTML & LaTeX
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- polytexnic
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0-p247