Created
October 1, 2012 20:21
-
-
Save agmarrugo/3814178 to your computer and use it in GitHub Desktop.
A script for writing Day One footnotes inline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def e_sh(str) | |
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\') | |
end | |
input = STDIN.read | |
footnotes = input.scan(/\(\*(.*?)\*\)/m) | |
# existing = input.scan(/^\[\^fn(\d+)\]: /i) | |
# counter = existing.empty? ? 1 : existing.uniq.sort[-1].join.to_i + 1 | |
counter = 1 | |
output = [] | |
footnotes.each {|note| | |
output << {'orig' => note[0], 'title' => "#{counter}", 'footnote' => note[0] } | |
counter += 1 | |
} | |
o = [] | |
output.each_with_index { |x,i| | |
o.push("#{x['title']}. #{x['footnote'].gsub(/\n\n(\s*.)/,"\n\n\t\\1")}") | |
input.gsub!(/\(\*#{e_sh x['orig']}\*\)/m,"^#{x['title']}") | |
} | |
puts input.strip + "\n\n\*\*\*\*" + "\n\n#{o.join("\n\n")}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment