Created
May 23, 2013 17:04
-
-
Save geraldb/5637657 to your computer and use it in GitHub Desktop.
patchfigs.rb - pandoc progit perl oneliner converted to ruby
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
# | |
# see http://johnmacfarlane.net/pandoc/epub.html | |
# | |
# perl -i -0pe 's/^Insert\s*(.*)\.png\s*\n([^\n]*)$/!\[\2](..\/figures\/\1-tn.png)/mg' */*.markdown | |
# | |
# converted to "verbose" ruby | |
# encoding: UTF-8 | |
Dir['*/*.markdown'].each do |filename| | |
puts " patching #{filename}..." | |
text = File.read( filename ) | |
text = text.gsub( /^Insert\s*(.*)\.png\s*\n([^\n]*)$/ ) do |_| | |
puts " 1: #{$1}" | |
puts " 2: #{$2}" | |
"!\[#{$2}](..\/figures\/#{$1}-tn.png)" | |
end | |
File.open( filename, 'w' ) do |file| | |
file.write( text ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment