How to convert existing redmine wiki from textile to markdown?
Since this is a once-only task why not pandoc -f textile -t markdown
oldfile.text -o newfile.md? Try it at Try Pandoc.
I wrote a rake task to convert all wiki pages and their versions to markdown.
Put this into lib/tasks/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", "--no-wrap", "--smart", "--strict", "-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 endend
And run:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
Building upon Michaƫl's answer, here is a tool to migrate from Textile to Markdown. It will migrate all content (comment, wiki, issue, message, news, document, project and journal). And it will also fixes several incompatibility between Redmine's Textile and pandoc's.
It's over there: https://github.com/Ecodev/redmine_convert_textile_to_markown