我想将Markdown作为我的Redmine wiki引擎。
我已经安装了Markdown插件,并且它运行良好。
唯一的问题是,如何将旧的维基(Textile格式)转换为Markdown格式,以便可以正确显示?
由于这是一项一次性任务,为什么不使用pandoc -f textile -t markdown
oldfile.text -o newfile.md呢?您可以在Try Pandoc上尝试。
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
然后运行:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
choco install pandoc
在Michaël的回答的基础上,这里提供了一种从Textile迁移到Markdown的工具。它将迁移所有内容(评论、wiki、问题、消息、新闻、文档、项目和日志)。并且还会修复Redmine的Textile和pandoc之间的几个不兼容问题。
工具在这里:https://github.com/Ecodev/redmine_convert_textile_to_markown
刚在一个带有 Ruby 2.6.6 的 Redmine 4.1.1 系统上使用了 redmine_reformat,看起来运行良好。但它目前不支持 Redmine 5.0。在我们的情况下,我们正在迁移到 Redmine 5.x,所以我们在 4.1.1 系统中进行了切换,删除了插件,然后再进行了迁移。