Created
November 24, 2011 07:02
-
-
Save tjdett/1390798 to your computer and use it in GitHub Desktop.
Convert Trac wiki syntax to Markdown
This file contains 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 | |
# Based on: https://gist.github.com/619537 | |
body = STDIN.read | |
body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '`\1`') | |
body.gsub!(/\{\{\{(.+?)\}\}\}/m){|m| m.each_line.map{|x| "\t#{x}".gsub(/[\{\}]{3}/,'')}.join} | |
body.gsub!(/\=\=\=\=\s(.+?)\s\=\=\=\=/, '### \1') | |
body.gsub!(/\=\=\=\s(.+?)\s\=\=\=/, '## \1') | |
body.gsub!(/\=\=\s(.+?)\s\=\=/, '# \1') | |
body.gsub!(/\=\s(.+?)\s\=[\s\n]*/, '') | |
body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, '[\2](\1)') | |
body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1') | |
body.gsub!(/'''(.+)'''/, '*\1*') | |
body.gsub!(/''(.+)''/, '_\1_') | |
body.gsub!(/^\s\*/, '*') | |
body.gsub!(/^\s\d\./, '1.') | |
STDOUT.write(body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment