summaryrefslogtreecommitdiff
path: root/pagerender.rb
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-10-13 14:11:12 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-10-13 14:11:12 -0400
commit8aa76ebdabbe6d65d1d520948b3e4ad598f46003 (patch)
tree02aa165f08ff44d447e557e1537481407a134894 /pagerender.rb
parent27cde747eb3f46ca44bde0ba727a0b644bce91ef (diff)
pagerender.rb: add footnote support, arch-systemd.md: use it.
I saw that the new version of rdiscount supported php-markdown-extra style footnotes and got excited. However, when I enabled it, I was disappointed to learn that it didn't support multi-line footnotes. Lame! So, I implemented that as a pre/post processor.
Diffstat (limited to 'pagerender.rb')
-rwxr-xr-xpagerender.rb24
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