Question

I want to use markdown as my redmine wiki engine.

I installed the markdown plugin and it worked well.

The only question is, how can I convert those old wiki (textile) into markdown so they can be displayed correctly?

Was it helpful?

Solution

Since this is a once-only task why not pandoc -f textile -t markdown oldfile.text -o newfile.md? Try it at Try Pandoc.

OTHER TIPS

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
  end
end

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

When I tried to convert the markdown file into textile file by above pandoc command(pandoc version is 1.12.4.2),Redmine could not display CodeBlock properly. So it is better that had been written CodeBlock in a pre element.

original is bellow.

~~~
% foo bar
~~~

converted one is bellow.

bc. % foo bar
% foo bar

-> This could not be displayed in redmine as a CodeBlock.

You should write CodeBlock as a pre element beforehand.

<pre>
 % foo bar
</pre>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top