|
1 |
| -#!/usr/bin/ruby |
2 |
| -# encoding: utf-8 |
| 1 | +#!/usr/bin/env ruby |
3 | 2 |
|
4 | 3 | # workflow.rb: Create rich css-enabled html and pdfs from markdown documents
|
5 | 4 |
|
6 | 5 | require 'kramdown'
|
| 6 | +require 'kramdown-parser-gfm' |
7 | 7 | require 'optparse'
|
8 | 8 |
|
9 | 9 | options = {}
|
10 | 10 | OptionParser.new do |opts|
|
11 | 11 | opts.banner = "Usage: workflow.rb [options] [filename]"
|
12 | 12 |
|
| 13 | + opts.on("-c", "--code-highlighting", "Use code syntax highlighting") { options[:highlighting] = true } |
13 | 14 | opts.on("-f", "--fixes", "Fixes some common display problems with pdfs") { options[:fixes] = true }
|
14 | 15 | opts.on("-h", "--header TEXT", "Add arbitrary header text to top of each pdf page") { |v| options[:header] = v }
|
15 | 16 | opts.on("-o", "--output NAME", "Basename of output file (by default same as input file)") { |v| options[:output] = v }
|
|
52 | 53 | $css = ' <link href="https://dohliam.github.io/dropin-minimal-css/min/' + name + '.min.css" type="text/css" rel="stylesheet">' + padding + fixes + close_tag
|
53 | 54 | end
|
54 | 55 |
|
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(/^/, " ") |
57 | 64 |
|
58 | 65 | output = ERB.new(File.read(script_dir + "template.rhtml")).result
|
59 | 66 |
|
|
66 | 73 |
|
67 | 74 | if options[:pdf]
|
68 | 75 | 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'` |
70 | 77 | elsif options[:header]
|
71 | 78 | 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'` |
73 | 80 | else
|
74 |
| - `wkhtmltopdf '#{basename}.html' '#{outfile}.pdf'` |
| 81 | + `wkhtmltopdf --enable-local-file-access '#{basename}.html' '#{outfile}.pdf'` |
75 | 82 | end
|
76 | 83 | end
|
0 commit comments