Skip to content

Instantly share code, notes, and snippets.

@xiaohanyu
Created March 30, 2014 02:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xiaohanyu/9866531 to your computer and use it in GitHub Desktop.
Save xiaohanyu/9866531 to your computer and use it in GitHub Desktop.
Improved nanoc pandoc filter
# This file provide two pandoc filters for html and pdf output
module Nanoc::Filters
class PandocHtml < Nanoc::Filter
identifier :pandoc_html
type :text => :text
def run(content, params = {})
input_format = case item[:extension]
when 'org'
'org'
when 'md', 'markdown'
'markdown'
end
`pandoc --mathjax -f #{input_format} -t html5 < #{item.raw_filename}`
end
end
class PandocPdf < Nanoc::Filter
identifier :pandoc_pdf
type :text => :binary
require 'tempfile'
def run(content, params = {})
temp_pdf_file = Tempfile.new(['nanoc_temp_pdf_file', '.pdf'], '/tmp')
input_format = case item[:extension]
when 'org'
'org'
when 'md', 'markdown'
'markdown'
end
`pandoc --mathjax -f #{input_format} -t latex --latex-engine xelatex -V geometry:margin=1in < #{item.raw_filename} -o #{temp_pdf_file.path}`
FileUtils.mv(temp_pdf_file, output_filename)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment