如何将现有的redmine wiki从textile转换为markdown?

hSA*_*TAC 11 ruby markdown textile redmine

我想使用markdown作为我的redmine wiki引擎.

我安装了markdown插件,效果很好.

唯一的问题是,我如何将这些旧维基(纺织品)转换为降价,以便正确显示?

Mic*_*ant 11

我写了一个rake任务,将所有wiki页面及其版本转换为markdown.

把它放入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
Run Code Online (Sandbox Code Playgroud)

并运行:

bundle exec rake convert_textile_to_markdown RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)