Skip to content

Instantly share code, notes, and snippets.

@glebm
Created September 9, 2013 20:50
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 glebm/6501313 to your computer and use it in GitHub Desktop.
Save glebm/6501313 to your computer and use it in GitHub Desktop.
Convert all markdown code blocks from indented to the syntax-highlighted ``` blocks
#!/usr/bin/env ruby
def convert(lang, md)
md.gsub(/\t/, ' ' * 4).gsub(/((?:^\s{4}[^\n]*\n)+)/) {
"\n```#{lang}#{$1.gsub(/^[ ]{4}/, '')}```\n"
}
end
argv = ARGV.dup
path = argv.pop or raise 'pass path'
lang = argv.pop || 'ruby'
puts convert(lang, File.read(path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment