diff options
Diffstat (limited to 'pagerender.rb')
-rwxr-xr-x | pagerender.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/pagerender.rb b/pagerender.rb index 021f66c..ecedaae 100755 --- a/pagerender.rb +++ b/pagerender.rb @@ -13,14 +13,29 @@ input = ARGV.first lines = File.read(input).split("\n") +footnote_start = /^\[\^/ +footnote_cont = /^(\t| {2,4})/ + markdown = '' tags = {} +footnotes = {} +footnote_label = nil for line in lines do if (line =~ /^:/) (key, val) = line.sub(/^:/, '').split(/\s+/, 2) tags[key] = val else - markdown += "\n"+line + 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 @@ -31,7 +46,12 @@ unless license_urls[@license].nil? @license="<a href=\"#{license_urls[@license]}\">#{@license}</a>" end -@content = RDiscount.new(markdown).to_html +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) +end erb = ERB.new(File.read(template)); erb.filename = template |