polytexnic 1.5.15 → 1.6.3

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: 658a70a77afa54b8e643d68cfdf54d91119193ec2f31950eab313a6e1368ce95
4
- data.tar.gz: 1d8ccad2438d6cf9b3d81f079c0c6b74e80bf0d3a3eb191f8a154f72143690ab
3
+ metadata.gz: b5019c283b39dc25f4f2ff80cda181c78c5d77e37b7245faf92c51cfee93bc35
4
+ data.tar.gz: 2c8d5e978e45e28ec12f0b0010ad6f701d5982e15469fedc3291861b09132d2a
5
5
  SHA512:
6
- metadata.gz: ca58630eba2304c132e5d3ee21d4de35df0bce99e37acc3ce164b712155f9a36476bb1ad6613d3920871b2b69a421c58637d6649061806cb93703ff1064f54c2
7
- data.tar.gz: 348eeb92774d793146f981a9af82d698e14b2bcbb0bba3303e6be066acb76cbedb6340ea887f9d393b1ca6d9c3080f7617254110196f8d4cf815833291dac045
6
+ metadata.gz: 127fb2ef04c1d0a1d6848f0c8ad540cccc23c7bb7c680b9ea2460e63b74e699af5cf30b10f594d039f3464b43da088b9aa098c9274ba6f5ac020e50e85779e19
7
+ data.tar.gz: 6ed16fb665fdba858cce00d8c420dffc3f02284384ddd5830c7e3caccdf0b189c569c40c949dca7f85a060f239c9f4642261166d65cbd5612416ccb1088fe21c
data/Gemfile CHANGED
@@ -24,4 +24,4 @@ end
24
24
  group :development do
25
25
  gem 'guard-rspec'
26
26
  gem 'rake'
27
- end
27
+ end
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polytexnic (1.5.15)
5
- json (~> 1.8.1)
6
- kramdown (~> 1.17)
4
+ polytexnic (1.6.3)
5
+ json (~> 2.3.0)
6
+ kramdown (>= 1.17, < 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/
13
13
  specs:
14
- coderay (1.1.2)
14
+ coderay (1.1.3)
15
15
  columnize (0.9.0)
16
16
  coveralls (0.7.2)
17
17
  multi_json (~> 1.3)
@@ -23,9 +23,9 @@ GEM
23
23
  debugger2 (1.0.0.beta2)
24
24
  columnize (>= 0.3.1)
25
25
  debugger-linecache (~> 1.2.0)
26
- diff-lcs (1.3)
26
+ diff-lcs (1.4.4)
27
27
  docile (1.1.5)
28
- ffi (1.12.2)
28
+ ffi (1.15.0)
29
29
  formatador (0.2.5)
30
30
  growl (1.0.3)
31
31
  guard (2.16.2)
@@ -42,36 +42,37 @@ GEM
42
42
  guard (~> 2.1)
43
43
  guard-compat (~> 1.1)
44
44
  rspec (>= 2.99.0, < 4.0)
45
- json (1.8.6)
46
- kramdown (1.17.0)
47
- listen (3.2.1)
45
+ json (2.3.1)
46
+ kramdown (2.3.0)
47
+ rexml
48
+ listen (3.4.1)
48
49
  rb-fsevent (~> 0.10, >= 0.10.3)
49
50
  rb-inotify (~> 0.9, >= 0.9.10)
50
- lumberjack (1.2.4)
51
+ lumberjack (1.2.8)
51
52
  method_source (1.0.0)
52
53
  mime-types (3.3.1)
53
54
  mime-types-data (~> 3.2015)
54
- mime-types-data (3.2019.1009)
55
- mini_portile2 (2.4.0)
55
+ mime-types-data (3.2021.0225)
56
56
  msgpack (1.2.10)
57
- multi_json (1.14.1)
57
+ multi_json (1.15.0)
58
58
  nenv (0.3.0)
59
- nokogiri (1.10.9)
60
- mini_portile2 (~> 2.4.0)
59
+ nokogiri (1.11.1-x86_64-darwin)
60
+ racc (~> 1.4)
61
61
  notiffany (0.1.3)
62
62
  nenv (~> 0.1)
63
63
  shellany (~> 0.0)
64
- pry (0.13.0)
64
+ pry (0.14.0)
65
65
  coderay (~> 1.1)
66
66
  method_source (~> 1.0)
67
- pygments.rb (1.2.1)
68
- multi_json (>= 1.0.0)
69
- rake (13.0.1)
70
- rb-fsevent (0.10.3)
67
+ pygments.rb (2.1.0)
68
+ racc (1.5.2)
69
+ rake (13.0.3)
70
+ rb-fsevent (0.10.4)
71
71
  rb-inotify (0.10.1)
72
72
  ffi (~> 1.0)
73
73
  rest-client (1.6.7)
74
74
  mime-types (>= 1.16)
75
+ rexml (3.2.4)
75
76
  rspec (2.99.0)
76
77
  rspec-core (~> 2.99.0)
77
78
  rspec-expectations (~> 2.99.0)
@@ -92,7 +93,7 @@ GEM
92
93
  tins (0.13.2)
93
94
 
94
95
  PLATFORMS
95
- ruby
96
+ x86_64-darwin-19
96
97
 
97
98
  DEPENDENCIES
98
99
  coveralls
@@ -105,4 +106,4 @@ DEPENDENCIES
105
106
  simplecov (~> 0.15.1)
106
107
 
107
108
  BUNDLED WITH
108
- 2.1.4
109
+ 2.2.13
data/bin/polytexnic CHANGED
@@ -1,19 +1,84 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "polytexnic"
3
+ require 'optparse'
4
+ require 'fileutils'
3
5
 
4
- def latex_to_html(latex)
5
- Polytexnic::Pipeline.new(latex, article: true).to_html
6
+ # polytexnic command-line script
7
+ # The polytexnic script converts Markdown to HTML or LaTeX
8
+ # using the PolyTeXnic HTML pipeline.
9
+
10
+ examples = %(
11
+ The polytexnic script converts Markdown to HTML or LaTeX
12
+ using the PolyTeXnic HTML pipeline.
13
+
14
+ Examples:
15
+ polytexnic example.md example.html
16
+ polytexnic example.md > example.html
17
+ polytexnic < example.md > example.html
18
+ cat example.md | polytexnic > example.html
19
+ polytexnic -i example.md > example.html
20
+ polytexnic -i example.md -o example.tex
21
+ polytexnic -f tex example.md)
22
+
23
+ options = {}
24
+ OptionParser.new do |opts|
25
+ opts.banner = "Usage: polytexnic [options]\n#{examples}\n\n"
26
+
27
+ opts.on("-i", "--input=INPUT", "Use file input") do |infile|
28
+ options[:infile] = infile
29
+ end
30
+
31
+ opts.on("-o", "--output=OUTPUT", "Use file output") do |outfile|
32
+ options[:outfile] = outfile
33
+ end
34
+
35
+ opts.on("-f", "--format", "Use output format [html, tex]") do |format|
36
+ options[:format] = format
37
+ end
38
+ end.parse!
39
+
40
+ # Returns the file format based on extension.
41
+ # Should be 'html' or 'tex'.
42
+ def format(filename)
43
+ filename.split('.').last
44
+ rescue
45
+ nil
46
+ end
47
+
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
+ )
6
61
  end
7
62
 
8
- if ARGV.empty?
9
- puts latex_to_html(STDIN.read)
63
+ if (infile = options[:infile] || ARGV.shift)
64
+ puts infile
65
+ input = File.read(infile)
10
66
  else
11
- filename = ARGV.shift
12
- latex = File.read(filename)
13
- html = latex_to_html(latex)
14
- if (outfile = ARGV.shift)
15
- File.write(outfile, html)
16
- else
17
- puts html.strip
18
- end
67
+ input = STDIN.read
68
+ end
69
+ outfile = options[:outfile] || ARGV.shift
70
+ puts outfile
71
+ pipeline = Polytexnic::Pipeline.new(input, article: true)
72
+ format = options[:format] || format(outfile) || "html"
73
+ if format == "html"
74
+ output = html_template("HTML output", pipeline.to_html)
75
+ elsif format == "tex"
76
+ output = pipeline.to_polytex
77
+ else
78
+ raise ArgumentError, "Invalid format: #{format}"
79
+ end
80
+ if outfile
81
+ File.write(outfile, output)
82
+ else
83
+ puts output.strip
19
84
  end
@@ -95,7 +95,7 @@ module Polytexnic
95
95
  def small_caps(doc)
96
96
  doc.xpath('//hi[@rend="sc"]').each do |node|
97
97
  node.name = 'span'
98
- node['class'] = 'sc'
98
+ node['class'] = 'smallcaps'
99
99
  node.remove_attribute('rend')
100
100
  end
101
101
  end
@@ -140,7 +140,7 @@ module Polytexnic
140
140
  # Removes commented-out lines.
141
141
  # Contents of the special sequence `%=` are converted to literal HTML.
142
142
  def remove_comments(output)
143
- output.gsub!(/[^\\]%[^=].*$/, '')
143
+ output.gsub!(/([^\\])(%[^=].*$)/, '\1')
144
144
  output.gsub!(/[^\\]%=(.*)$/) do
145
145
  key = digest($1)
146
146
  literal_html_cache[key] = $1
@@ -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.5.15"
2
+ VERSION = "1.6.3"
3
3
  end
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,11 +18,11 @@ 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'
25
- gem.add_dependency 'json', '~> 1.8.1'
24
+ gem.add_dependency 'kramdown', '>= 1.17', '< 3.0'
25
+ gem.add_dependency 'json', '~> 2.3.0'
26
26
 
27
27
  gem.add_development_dependency 'rspec', '~> 2.14'
28
28
  gem.add_development_dependency 'simplecov', '~> 0.15.1'
@@ -9,6 +9,15 @@ describe 'Polytexnic::Pipeline#to_html' do
9
9
  let(:polytex) { "% A LaTeX comment" }
10
10
  it { should eq '' }
11
11
 
12
+ context "occurring a the end of a line" do
13
+ let(:polytex) do <<-'EOS'
14
+ lorem ipsum
15
+ dolor sit amet.%this is a comment
16
+ EOS
17
+ end
18
+ it { should include("amet.") }
19
+ end
20
+
12
21
  context "with a section and label" do
13
22
  let(:polytex) do <<-'EOS'
14
23
  % \section{Foo}
@@ -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 @@ describe 'Polytexnic::Pipeline#to_html' do
29
29
 
30
30
  describe "small caps" do
31
31
  let(:polytex) { '\textsc{small caps}' }
32
- it { should resemble '<span class="sc">small caps</span>' }
32
+ it { should resemble '<span class="smallcaps">small caps</span>' }
33
33
  end
34
34
 
35
35
  describe "small text" do
@@ -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!"
@@ -262,4 +262,4 @@ end
262
262
  it { should_not include 'xmlelement' }
263
263
  end
264
264
  end
265
- end
265
+ 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.5.15
4
+ version: 1.6.3
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: 2020-03-31 00:00:00.000000000 Z
12
+ date: 2021-03-07 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
@@ -57,30 +63,36 @@ dependencies:
57
63
  name: kramdown
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
- - - "~>"
66
+ - - ">="
61
67
  - !ruby/object:Gem::Version
62
68
  version: '1.17'
69
+ - - "<"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.0'
63
72
  type: :runtime
64
73
  prerelease: false
65
74
  version_requirements: !ruby/object:Gem::Requirement
66
75
  requirements:
67
- - - "~>"
76
+ - - ">="
68
77
  - !ruby/object:Gem::Version
69
78
  version: '1.17'
79
+ - - "<"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
70
82
  - !ruby/object:Gem::Dependency
71
83
  name: json
72
84
  requirement: !ruby/object:Gem::Requirement
73
85
  requirements:
74
86
  - - "~>"
75
87
  - !ruby/object:Gem::Version
76
- version: 1.8.1
88
+ version: 2.3.0
77
89
  type: :runtime
78
90
  prerelease: false
79
91
  version_requirements: !ruby/object:Gem::Requirement
80
92
  requirements:
81
93
  - - "~>"
82
94
  - !ruby/object:Gem::Version
83
- version: 1.8.1
95
+ version: 2.3.0
84
96
  - !ruby/object:Gem::Dependency
85
97
  name: rspec
86
98
  requirement: !ruby/object:Gem::Requirement
@@ -277,7 +289,7 @@ files:
277
289
  - tasks/bin/ruby_tests
278
290
  - tasks/run_tests_with_both_rubies.rake
279
291
  - tmp/.gitkeep
280
- homepage: https://polytexnic.org/
292
+ homepage: https://github.com/softcover/polytexnic
281
293
  licenses:
282
294
  - MIT
283
295
  metadata: {}