Skip to content

Instantly share code, notes, and snippets.

@doolin
Created December 12, 2010 19:51
Show Gist options
  • Select an option

  • Save doolin/738273 to your computer and use it in GitHub Desktop.

Select an option

Save doolin/738273 to your computer and use it in GitHub Desktop.
Using kramdown to process markdown to latex and html
#!/usr/bin/env ruby
# This is what I'm using to process a directory full
# of kramdown (~markdown) files.
#
# Copyright 2010 David M. Doolin (david.doolin@gmail.com)
#
# License: Public domain.
# And a little transclusion demo...
require 'kramdown'
headers = ['chapter','section','subsection','subsubsection',
'paragraph','subparagraph']
filelist = Dir.glob("*.md")
filelist.each { |fl|
fileroot = File.basename(fl,'.*')
file = File.open(fileroot + ".md", "rb")
contents = file.read
document = Kramdown::Document.new(contents,
:latex_headers => headers, :auto_ids => true)
File.open("./tex/" + fileroot + ".tex","w+") { |f|
f.write(document.to_latex)
}
File.open("./epub/OEBPS/" + fileroot + ".html","w+") { |f|
f.write(document.to_html)
}
file.close
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment