Skip to content

Instantly share code, notes, and snippets.

@geraldb
Created May 23, 2013 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldb/5637657 to your computer and use it in GitHub Desktop.
Save geraldb/5637657 to your computer and use it in GitHub Desktop.
patchfigs.rb - pandoc progit perl oneliner converted to ruby
#
# 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