Skip to content

Guess Rouge lexer by filename #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,42 @@ PATH
GEM
remote: http://rubygems.org/
specs:
Ascii85 (1.0.2)
Ascii85 (1.1.0)
afm (0.2.2)
coderay (1.1.2)
diff-lcs (1.3)
coderay (1.1.3)
diff-lcs (1.5.0)
hashery (2.1.2)
method_source (0.9.0)
method_source (1.0.0)
pdf-inspector (1.3.0)
pdf-reader (>= 1.0, < 3.0.a)
pdf-reader (2.0.0)
Ascii85 (~> 1.0.0)
pdf-reader (2.10.0)
Ascii85 (~> 1.0)
afm (~> 0.2.1)
hashery (~> 2.0)
ruby-rc4
ttfunk
pdfkit (0.8.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rake (12.3.3)
rouge (3.3.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
pdfkit (0.8.6)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.6)
rouge (3.29.0)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
ruby-rc4 (0.1.5)
ttfunk (1.5.1)
wkhtmltopdf-binary (0.12.4)
ttfunk (1.7.0)
wkhtmltopdf-binary (0.12.6.5)

PLATFORMS
ruby
Expand All @@ -58,4 +58,4 @@ DEPENDENCIES
rspec

BUNDLED WITH
1.17.1
2.3.16
4 changes: 2 additions & 2 deletions lib/code2pdf/convert_to_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def pdf
end

def syntax_highlight(file)
file_type = File.extname(file.first)[1..-1]
file_lexer = Rouge::Lexer.find(file_type)
file_name = File.basename(file.first)
file_lexer = Rouge::Lexer.guess_by_filename(file_name)
return CGI.escapeHTML(file.last) unless file_lexer

theme = Rouge::Themes::Base16.mode(:light)
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/hello_world/lib/sample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Some javadoc
*/
class Example {
fun sum(): Int {
return 2 + 2
}
}
Binary file modified spec/fixtures/hello_world_original.pdf
Binary file not shown.