diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-11-24 04:40:17 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-11-24 04:40:17 -0500 |
commit | c46222fd2c1e02f695b544576f8605676be4d502 (patch) | |
tree | 29893a84cbc8d06c138306ddad63eecabda0d50c /pagerender.rb | |
parent | fee8f8267106650d24b5047ee7e0abfa905f5760 (diff) |
Switch from rdiscount to Pandoc.
But, I am still using ERB for the templating; I wrote my own Ruby Pandoc
bindings because pandoc-ruby sucks; it has more code but does less.
This was slightly painful, as I had to switch all of the articles from my
hacked-on metadata format to Pandoc's format.
Diffstat (limited to 'pagerender.rb')
-rwxr-xr-x | pagerender.rb | 54 |
1 files changed, 17 insertions, 37 deletions
diff --git a/pagerender.rb b/pagerender.rb index ecedaae..d63bcad 100755 --- a/pagerender.rb +++ b/pagerender.rb @@ -1,58 +1,38 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- -require 'rdiscount' +load 'pandoc.rb' require 'erb' +require 'date' license_urls = { "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', 'WTFPL-2' => "http://www.wtfpl.net/txt/copying/", } +author_urls = { + "Luke Shumaker" => "mailto:lukeshu@sbcglobal.net", +} template = 'template.erb' -input = ARGV.first - -lines = File.read(input).split("\n") +infile = ARGV.first -footnote_start = /^\[\^/ -footnote_cont = /^(\t| {2,4})/ +Pandoc::prog='pandoc' -markdown = '' -tags = {} -footnotes = {} -footnote_label = nil -for line in lines do - if (line =~ /^:/) - (key, val) = line.sub(/^:/, '').split(/\s+/, 2) - tags[key] = val - else - if (line =~ footnote_start) - footnote_label, footnote_body = line.split(':', 2) - footnote_label.gsub!(/[\^\[\]:]/, '') - footnotes[footnote_label] = footnote_body+"\n" - markdown += "[^#{footnote_label}]: 555PHONYFOOTNOTE555#{footnote_label}\n" - elsif (!footnote_label.nil? and line =~ footnote_cont) - footnotes[footnote_label] += line.sub(footnote_cont, '')+"\n" - else - footnote_label = nil - markdown += line+"\n" - end - end -end +input = File.read(infile) +doc = Pandoc::load('markdown-markdown_in_html_blocks', input) -@title = tags['title'] || lines.first -@copyright = tags['copyright'] || "Luke Shumaker" -@license = tags['license'] || "CC BY-SA-3.0" +@title = doc['title'] || input.split("\n",2).first +@author = doc['author'] || "Luke Shumaker" +@date = Date.parse(doc['date']) unless doc['date'].nil? +@license = doc['license'] || "CC BY-SA-3.0" unless license_urls[@license].nil? @license="<a href=\"#{license_urls[@license]}\">#{@license}</a>" end - -renderer = RDiscount.new(markdown) -renderer.footnotes = true; -@content = renderer.to_html -footnotes.each do |label, body| - @content.gsub!("555PHONYFOOTNOTE555#{label}", RDiscount.new(body).to_html) +unless author_urls[@author].nil? + @author="<a href=\"#{author_urls[@author]}\">#{@author}</a>" end +@content = doc.to('html5') + erb = ERB.new(File.read(template)); erb.filename = template erb.run() |