Skip to content

Instantly share code, notes, and snippets.

@othree
Created June 4, 2015 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save othree/8563b7f9018730666b95 to your computer and use it in GitHub Desktop.
Save othree/8563b7f9018730666b95 to your computer and use it in GitHub Desktop.
redmine_convert_textile_to_markdown.rake
task :convert_textile_to_markdown => :environment do
require 'tempfile'
WikiContent.all.each do |wiki|
([wiki] + wiki.versions).each do |version|
textile = version.text
src = Tempfile.new('textile')
src.write(textile)
src.close
dst = Tempfile.new('markdown')
dst.close
command = [
"pandoc",
"-f",
"textile",
"-t",
"markdown",
src.path,
"-o",
dst.path,
]
system(*command) or raise "pandoc failed"
dst.open
markdown = dst.read
# remove the \ pandoc puts before * and > at begining of lines
markdown.gsub!(/^((\\[*>])+)/) { $1.gsub("\\", "") }
# add a blank line before lists
markdown.gsub!(/^([^*].*)\n\*/, "\\1\n\n*")
version.update_attribute(:text, markdown)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment