polytexnic 1.6.1 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1f2eb8f0ea1afe5f4f09645beb2d38100c9bdafc097fcd5943ac222d41fc592
4
- data.tar.gz: c0ea88d4a8fbdb470be081cd446b5f3d007d37e5a1df7eec8a3197a07ecc146a
3
+ metadata.gz: aa4a264539262673bc0a0436583a9ce31c3fc9ecbc2ef5cc138016873676ea58
4
+ data.tar.gz: 53fb1e2697742893dc61a1161296c26ae6f9b0bdde33b525528f3c5385e250cf
5
5
  SHA512:
6
- metadata.gz: f6bb4ddcd578b51b1683f00fcfd78325964ccc0461a46c4ac98826fc73b22912448d9ec9fc12bda4877869b755a77dcf5cc0faf828f6ebd94ea5c15e1aa04389
7
- data.tar.gz: e37c38285cab036bbabe23a8444587547ea63084f0f73171887d0ad8b512983be1704d2d4efe709796b37464c9155abf1167996913c6d97d0e24bbd624c2273e
6
+ metadata.gz: a90cd3b66b2ead91ced4337458ec2be79fb35d7991aa66b763f5ed5db7b49145cfe7e2ecfc28050731ebf689473264374ada7b5d7f4f99690fe73cd1782add30
7
+ data.tar.gz: b0b90e6906c207ffb355e591e07385fb57e5b5ee7d7acae42417fe331c4046e4f3f68e12a4cd793609b5677fe050980b872686dccc682283d245ce079167e961
data/Gemfile CHANGED
@@ -22,6 +22,6 @@ group :test do
22
22
  end
23
23
 
24
24
  group :development do
25
- gem 'guard-rspec'
25
+ gem 'guard-rspec', require: false
26
26
  gem 'rake'
27
27
  end
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polytexnic (1.6.1)
4
+ polytexnic (1.6.5)
5
5
  json (~> 2.3.0)
6
- kramdown (>= 1.17, < 3.0)
6
+ kramdown (>= 2.0, < 3.0)
7
7
  msgpack (~> 1.2.0)
8
- nokogiri (~> 1.10.8)
9
- pygments.rb (~> 1.2.1)
8
+ nokogiri (>= 1.6.0, < 2.0)
9
+ pygments.rb (~> 2.1)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
@@ -25,16 +25,16 @@ GEM
25
25
  debugger-linecache (~> 1.2.0)
26
26
  diff-lcs (1.4.4)
27
27
  docile (1.1.5)
28
- ffi (1.13.1)
29
- formatador (0.2.5)
28
+ ffi (1.15.3)
29
+ formatador (0.3.0)
30
30
  growl (1.0.3)
31
- guard (2.16.2)
31
+ guard (2.18.0)
32
32
  formatador (>= 0.2.4)
33
33
  listen (>= 2.7, < 4.0)
34
34
  lumberjack (>= 1.0.12, < 2.0)
35
35
  nenv (~> 0.1)
36
36
  notiffany (~> 0.0)
37
- pry (>= 0.9.12)
37
+ pry (>= 0.13.0)
38
38
  shellany (~> 0.0)
39
39
  thor (>= 0.18.1)
40
40
  guard-compat (1.2.1)
@@ -43,37 +43,40 @@ GEM
43
43
  guard-compat (~> 1.1)
44
44
  rspec (>= 2.99.0, < 4.0)
45
45
  json (2.3.1)
46
- kramdown (2.3.0)
46
+ kramdown (2.3.1)
47
47
  rexml
48
- listen (3.2.1)
48
+ listen (3.7.0)
49
49
  rb-fsevent (~> 0.10, >= 0.10.3)
50
50
  rb-inotify (~> 0.9, >= 0.9.10)
51
- lumberjack (1.2.7)
51
+ lumberjack (1.2.8)
52
52
  method_source (1.0.0)
53
53
  mime-types (3.3.1)
54
54
  mime-types-data (~> 3.2015)
55
- mime-types-data (3.2020.0512)
56
- mini_portile2 (2.4.0)
55
+ mime-types-data (3.2021.0704)
56
+ mini_portile2 (2.6.1)
57
57
  msgpack (1.2.10)
58
58
  multi_json (1.15.0)
59
59
  nenv (0.3.0)
60
- nokogiri (1.10.10)
61
- mini_portile2 (~> 2.4.0)
60
+ nokogiri (1.12.3)
61
+ mini_portile2 (~> 2.6.1)
62
+ racc (~> 1.4)
63
+ nokogiri (1.12.3-x86_64-darwin)
64
+ racc (~> 1.4)
62
65
  notiffany (0.1.3)
63
66
  nenv (~> 0.1)
64
67
  shellany (~> 0.0)
65
- pry (0.13.1)
68
+ pry (0.14.1)
66
69
  coderay (~> 1.1)
67
70
  method_source (~> 1.0)
68
- pygments.rb (1.2.1)
69
- multi_json (>= 1.0.0)
70
- rake (13.0.1)
71
- rb-fsevent (0.10.4)
71
+ pygments.rb (2.2.0)
72
+ racc (1.5.2)
73
+ rake (13.0.6)
74
+ rb-fsevent (0.11.0)
72
75
  rb-inotify (0.10.1)
73
76
  ffi (~> 1.0)
74
77
  rest-client (1.6.7)
75
78
  mime-types (>= 1.16)
76
- rexml (3.2.4)
79
+ rexml (3.2.5)
77
80
  rspec (2.99.0)
78
81
  rspec-core (~> 2.99.0)
79
82
  rspec-expectations (~> 2.99.0)
@@ -95,6 +98,7 @@ GEM
95
98
 
96
99
  PLATFORMS
97
100
  ruby
101
+ x86_64-darwin-19
98
102
 
99
103
  DEPENDENCIES
100
104
  coveralls
@@ -107,4 +111,4 @@ DEPENDENCIES
107
111
  simplecov (~> 0.15.1)
108
112
 
109
113
  BUNDLED WITH
110
- 2.1.4
114
+ 2.2.13
data/Guardfile CHANGED
@@ -1,15 +1,10 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
3
6
 
4
- guard :rspec do
5
7
  watch(%r{^spec/.+_spec\.rb$})
6
8
  watch(%r{^lib/(.+)\.rb$}) { "spec" }
7
- ## Uncomment & edit below (and comment out above) to watch particular specs.
8
- # watch(%r{^lib/(.+)\.rb$}) do
9
- # [
10
- # "spec/to_html/asides_spec.rb",
11
- # "spec/to_html/codelistings_spec.rb"
12
- # ]
13
- # end
14
9
  watch('spec/spec_helper.rb') { "spec" }
15
10
  end
data/bin/polytexnic CHANGED
@@ -40,23 +40,26 @@ end.parse!
40
40
  # Returns the file format based on extension.
41
41
  # Should be 'html' or 'tex'.
42
42
  def format(filename)
43
- puts '***********'
44
- puts '***********'
45
- puts '***********'
46
- puts '***********'
47
- puts '***********'
48
- p filename.split('.')
49
43
  filename.split('.').last
50
44
  rescue
51
45
  nil
52
46
  end
53
47
 
54
- puts '$$$$$$$$$$$'
55
- puts '$$$$$$$$$$$'
56
- puts '$$$$$$$$$$$'
57
- puts '$$$$$$$$$$$'
58
- puts '$$$$$$$$$$$'
59
- p options
48
+ # Defines a valid HTML template.
49
+ def html_template(title, body)
50
+ %(<!DOCTYPE html>
51
+ <html>
52
+ <head>
53
+ <title>#{title}</title>
54
+ <meta charset="utf-8">
55
+ </head>
56
+ <body>
57
+ #{body}
58
+ </body>
59
+ </html>
60
+ )
61
+ end
62
+
60
63
  if (infile = options[:infile] || ARGV.shift)
61
64
  puts infile
62
65
  input = File.read(infile)
@@ -68,7 +71,7 @@ puts outfile
68
71
  pipeline = Polytexnic::Pipeline.new(input, article: true)
69
72
  format = options[:format] || format(outfile) || "html"
70
73
  if format == "html"
71
- output = pipeline.to_html
74
+ output = html_template("HTML output", pipeline.to_html)
72
75
  elsif format == "tex"
73
76
  output = pipeline.to_polytex
74
77
  else
@@ -209,6 +209,7 @@ module Polytexnic
209
209
  # For completeness, we handle the case where the author neglects to
210
210
  # use the nonbreak space ~.
211
211
  def hyperrefs(string)
212
+ part = language_labels["part"]
212
213
  chapter = language_labels["chapter"]["word"]
213
214
  section = language_labels["section"]
214
215
  table = language_labels["table"]
@@ -218,7 +219,7 @@ module Polytexnic
218
219
  listing = language_labels["listing"]
219
220
  equation = language_labels["equation"]
220
221
  eq = language_labels["eq"]
221
- linked_item = "(#{chapter}|#{section}|#{table}|#{box}|#{figure}" +
222
+ linked_item = "(#{part}|#{chapter}|#{section}|#{table}|#{box}|#{figure}" +
222
223
  "|#{fig}\.|#{listing}|#{equation}|#{eq}\.)"
223
224
  ref = /(?:#{linked_item}(~| ))*(\\(?:eq)*ref){(.*?)}/i
224
225
  string.gsub!(ref) do
@@ -206,9 +206,17 @@ module Polytexnic
206
206
  # Inline numbers look much better in HTML but are invalid in LaTeX.
207
207
  options['linenos'] = 'inline'
208
208
  end
209
- highlight_cache[key] ||= Pygments.highlight(content, lexer: language,
209
+ if (lines = options['hl_lines'])
210
+ content_lines = content.split("\n")
211
+ if lines.max > content_lines.length
212
+ err = "\nHighlight line(s) out of range: #{lines.inspect}\n"
213
+ err += content
214
+ raise err
215
+ end
216
+ end
217
+ highlight_cache[key] ||= Pygments.highlight(content, lexer: language,
210
218
  formatter: formatter,
211
- options: options)
219
+ options: options)
212
220
  end
213
221
 
214
222
  # Adds some verbatim font info (including size).
@@ -1,3 +1,3 @@
1
1
  module Polytexnic
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.5"
3
3
  end
data/lib/polytexnic.rb CHANGED
@@ -54,7 +54,7 @@ module Polytexnic
54
54
  else
55
55
  default_language_labels.merge(labels)
56
56
  end
57
- tempdir = 'tmp'
57
+ tempdir = 'tmp'
58
58
  FileUtils.mkdir(tempdir) unless File.directory?(tempdir)
59
59
  @highlight_cache_filename = File.join(tempdir, '.highlight_cache')
60
60
  if File.exist?(@highlight_cache_filename)
@@ -109,7 +109,7 @@ module Polytexnic
109
109
 
110
110
  # Returns the default labels for 'Chapter', 'Figure', etc.
111
111
  def default_language_labels
112
- {"chapter"=>{"word"=>"Chapter", "order"=>"standard"},
112
+ {"part"=>"Part","chapter"=>{"word"=>"Chapter", "order"=>"standard"},
113
113
  "section"=>"Section", "table"=>"Table", "figure"=>"Figure",
114
114
  "fig"=>"Fig", "aside"=>"Box", "listing"=>"Listing",
115
115
  "equation"=>"Equation", "eq"=>"Eq", "frontmatter"=>"Frontmatter",
data/polytexnic.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["michael@softcover.io"]
11
11
  gem.description = %q{Core translation engine for the softcover gem}
12
12
  gem.summary = %q{Convert from PolyTeX & Markdown to HTML & LaTeX}
13
- gem.homepage = "https://polytexnic.org/"
13
+ gem.homepage = "https://github.com/softcover/polytexnic"
14
14
  gem.license = "MIT"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -18,10 +18,10 @@ 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.10.8'
22
- gem.add_dependency 'pygments.rb', '~> 1.2.1'
21
+ gem.add_dependency 'nokogiri', '>= 1.6.0', '< 2.0'
22
+ gem.add_dependency 'pygments.rb', '~> 2.1'
23
23
  gem.add_dependency 'msgpack', '~> 1.2.0'
24
- gem.add_dependency 'kramdown', '>= 1.17', '< 3.0'
24
+ gem.add_dependency 'kramdown', '>= 2.0', '< 3.0'
25
25
  gem.add_dependency 'json', '~> 2.3.0'
26
26
 
27
27
  gem.add_development_dependency 'rspec', '~> 2.14'
@@ -98,7 +98,7 @@ describe Polytexnic::Pipeline do
98
98
  <div class="code">
99
99
  <div class="highlight">
100
100
  <pre>
101
- <span></span>
101
+ <span></span>
102
102
  <span class="k">def</span> <span class="nf">foo</span>
103
103
  <span class="s2">"bar"</span>
104
104
  <span class="k">end</span>
@@ -126,15 +126,15 @@ describe Polytexnic::Pipeline do
126
126
  <div class="highlight">
127
127
  <pre>
128
128
  <span></span>
129
- <span class="lineno">1</span>
130
129
  <span class="hll">
130
+ <span class="linenos">1</span>
131
131
  <span class="k">def</span> <span class="nf">foo</span>
132
132
  </span>
133
- <span class="lineno">2</span>
134
133
  <span class="hll">
134
+ <span class="linenos">2</span>
135
135
  <span class="s2">"bar"</span>
136
136
  </span>
137
- <span class="lineno">3</span>
137
+ <span class="linenos">3</span>
138
138
  <span class="k">end</span>
139
139
  </pre>
140
140
  </div>
@@ -143,9 +143,25 @@ describe Polytexnic::Pipeline do
143
143
  end
144
144
  end
145
145
 
146
+ context "when highlighting HTML" do
147
+ let(:polytex) do <<-'EOS'
148
+ %= lang:html, options: "hl_lines": [3], "linenos": true
149
+ \begin{code}
150
+ ---
151
+ layout: default
152
+ title: Gallery for Learn Enough JavaScript to Be Dangerous
153
+ ---
154
+
155
+ <div class="gallery col-three">
156
+ <div class="col col-nav gallery-thumbs" id="gallery-thumbs">
157
+ \end{code}
158
+ end
159
+ it should include('class="linenos"')
160
+ end
161
+
146
162
  context "with highlight line out of range" do
147
163
  let(:polytex) do <<-'EOS'
148
- %= lang:ruby, options: "hl_lines": [17], "linenos": true
164
+ %= lang:ruby, options: "hl_lines": [4], "linenos": true
149
165
  \begin{code}
150
166
  def foo
151
167
  "bar"
@@ -155,7 +171,7 @@ describe Polytexnic::Pipeline do
155
171
  end
156
172
 
157
173
  it "should emit a warning" do
158
-
174
+ expect { processed_text }.to raise_error
159
175
  end
160
176
  end
161
177
 
@@ -238,7 +254,7 @@ describe Polytexnic::Pipeline do
238
254
 
239
255
  context "with custom options" do
240
256
  let(:polytex) do <<-'EOS'
241
- %= <<(polytexnic_commands.sty, lang: tex, options: "hl_lines": [5])
257
+ %= <<(polytexnic_commands.sty, lang: tex, options: "hl_lines": [1])
242
258
  EOS
243
259
  end
244
260
  let(:output) do <<-'EOS'
@@ -377,7 +393,17 @@ describe Polytexnic::Pipeline do
377
393
 
378
394
  context "with repo, tag, lang and options" do
379
395
  let(:polytex) do <<-'EOS'
380
- %= <<(tagged_file.rb, git: {tag: v0.9.4, repo:"repo_path/.git"}, lang: tex, options: "hl_lines": [5])
396
+ %= <<(tagged_file.rb, git: {tag: v0.9.4, repo:"repo_path/.git"}, lang: tex, options: "hl_lines": [2])
397
+ EOS
398
+ end
399
+ let(:output) do <<-'EOS'
400
+ <div class="code">
401
+ <div class="highlight">
402
+ <pre><span></span>Fake data
403
+ <span class="hll">second line
404
+ </span></pre>
405
+ </div>
406
+ </div>
381
407
  EOS
382
408
  end
383
409
  it_behaves_like "an inclusion"
@@ -29,7 +29,7 @@ Make a code listing as in Listing~\ref{code:hello}.
29
29
  \begin{codelisting}
30
30
  \label{code:hello}
31
31
  \codecaption{A hello program in Ruby.}
32
- %= lang:ruby, options: "hl_lines": [17]
32
+ %= lang:ruby, options: "hl_lines": [2]
33
33
  \begin{code}
34
34
  def hello
35
35
  "hello, world!"
@@ -149,11 +149,17 @@ end
149
149
 
150
150
  describe "hyperref links" do
151
151
  let(:polytex) do <<-'EOS'
152
- Chapter~\ref{cha:foo}
152
+ Part~\ref{prt:foo}
153
+ Chapter~\ref{cha:bar}
154
+ Section~\ref{sec:baz}
153
155
  EOS
154
156
  end
155
- let(:output) { '\hyperref[cha:foo]{Chapter~\ref{cha:foo}' }
156
- it { should resemble output }
157
+ let(:part_ref) { '\hyperref[prt:foo]{Part~\ref{prt:foo}' }
158
+ let(:chapter_ref) { '\hyperref[cha:bar]{Chapter~\ref{cha:bar}' }
159
+ let(:section_ref) { '\hyperref[sec:baz]{Section~\ref{sec:baz}' }
160
+ it { should resemble part_ref }
161
+ it { should resemble chapter_ref }
162
+ it { should resemble section_ref }
157
163
  end
158
164
 
159
165
  describe "asides" do
@@ -262,4 +268,4 @@ end
262
268
  it { should_not include 'xmlelement' }
263
269
  end
264
270
  end
265
- end
271
+ 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.6.1
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl
@@ -9,36 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-16 00:00:00.000000000 Z
12
+ date: 2021-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.0
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: 1.10.8
23
+ version: '2.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 1.6.0
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: 1.10.8
33
+ version: '2.0'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: pygments.rb
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - "~>"
33
39
  - !ruby/object:Gem::Version
34
- version: 1.2.1
40
+ version: '2.1'
35
41
  type: :runtime
36
42
  prerelease: false
37
43
  version_requirements: !ruby/object:Gem::Requirement
38
44
  requirements:
39
45
  - - "~>"
40
46
  - !ruby/object:Gem::Version
41
- version: 1.2.1
47
+ version: '2.1'
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: msgpack
44
50
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +65,7 @@ dependencies:
59
65
  requirements:
60
66
  - - ">="
61
67
  - !ruby/object:Gem::Version
62
- version: '1.17'
68
+ version: '2.0'
63
69
  - - "<"
64
70
  - !ruby/object:Gem::Version
65
71
  version: '3.0'
@@ -69,7 +75,7 @@ dependencies:
69
75
  requirements:
70
76
  - - ">="
71
77
  - !ruby/object:Gem::Version
72
- version: '1.17'
78
+ version: '2.0'
73
79
  - - "<"
74
80
  - !ruby/object:Gem::Version
75
81
  version: '3.0'
@@ -283,7 +289,7 @@ files:
283
289
  - tasks/bin/ruby_tests
284
290
  - tasks/run_tests_with_both_rubies.rake
285
291
  - tmp/.gitkeep
286
- homepage: https://polytexnic.org/
292
+ homepage: https://github.com/softcover/polytexnic
287
293
  licenses:
288
294
  - MIT
289
295
  metadata: {}
@@ -302,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
302
308
  - !ruby/object:Gem::Version
303
309
  version: '0'
304
310
  requirements: []
305
- rubygems_version: 3.1.2
311
+ rubygems_version: 3.1.6
306
312
  signing_key:
307
313
  specification_version: 4
308
314
  summary: Convert from PolyTeX & Markdown to HTML & LaTeX