Skip to content

Commit 36f2f0f

Browse files
committed
add support for syntax highlighting
1 parent 5baec4a commit 36f2f0f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

template.rhtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<%=$css%>
7+
<%=$pygments%>
78
<title><%=$title%></title>
89
</head>
910
<body>

workflow.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
#!/usr/bin/ruby
2-
# encoding: utf-8
1+
#!/usr/bin/env ruby
32

43
# workflow.rb: Create rich css-enabled html and pdfs from markdown documents
54

65
require 'kramdown'
6+
require 'kramdown-parser-gfm'
77
require 'optparse'
88

99
options = {}
1010
OptionParser.new do |opts|
1111
opts.banner = "Usage: workflow.rb [options] [filename]"
1212

13+
opts.on("-c", "--code-highlighting", "Use code syntax highlighting") { options[:highlighting] = true }
1314
opts.on("-f", "--fixes", "Fixes some common display problems with pdfs") { options[:fixes] = true }
1415
opts.on("-h", "--header TEXT", "Add arbitrary header text to top of each pdf page") { |v| options[:header] = v }
1516
opts.on("-o", "--output NAME", "Basename of output file (by default same as input file)") { |v| options[:output] = v }
@@ -52,8 +53,14 @@
5253
$css = ' <link href="https://dohliam.github.io/dropin-minimal-css/min/' + name + '.min.css" type="text/css" rel="stylesheet">' + padding + fixes + close_tag
5354
end
5455

55-
html = Kramdown::Document.new(content).to_html
56-
$content = html.gsub(/^/, " ")
56+
if options[:highlighting]
57+
$pygments = ' <link rel="stylesheet" type="text/css" class="pygments-css" href="https://dohliam.github.io/pygments-css/solarized-light.css">'
58+
end
59+
60+
# html = Kramdown::Document.new(content).to_html
61+
html = Kramdown::Document.new(content, input: 'GFM').to_html
62+
$content = html
63+
# $content = html.gsub(/^/, " ")
5764

5865
output = ERB.new(File.read(script_dir + "template.rhtml")).result
5966

@@ -66,11 +73,11 @@
6673

6774
if options[:pdf]
6875
if options[:numbers]
69-
`wkhtmltopdf --footer-center "[page]" '#{basename}.html' '#{outfile}.pdf'`
76+
`wkhtmltopdf --enable-local-file-access --footer-center "[page]" '#{basename}.html' '#{outfile}.pdf'`
7077
elsif options[:header]
7178
header = options[:header]
72-
`wkhtmltopdf --header-right "#{header}" '#{basename}.html' '#{outfile}.pdf'`
79+
`wkhtmltopdf --enable-local-file-access --header-right "#{header}" '#{basename}.html' '#{outfile}.pdf'`
7380
else
74-
`wkhtmltopdf '#{basename}.html' '#{outfile}.pdf'`
81+
`wkhtmltopdf --enable-local-file-access '#{basename}.html' '#{outfile}.pdf'`
7582
end
7683
end

0 commit comments

Comments
 (0)