Created
September 9, 2013 20:50
-
-
Save glebm/6501313 to your computer and use it in GitHub Desktop.
Convert all markdown code blocks from indented to the syntax-highlighted ``` blocks
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 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