我想使用 markdown 作为我的 redmine wiki 引擎。
我安装了markdown插件,效果很好。
唯一的问题是,我怎样才能将那些旧的 wiki(纺织品)转换为 markdown,以便它们可以正确显示?
既然这是一个只有一次的任务,为什么不pandoc -f textile -t markdown
oldfile.text -o newfile.md呢?在Try Pandoc尝试一下。
我编写了一个 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
并运行:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
基于Michaël 的回答,这是一个从 Textile 迁移到 Markdown 的工具。它将迁移所有内容(评论、wiki、问题、消息、新闻、文档、项目和期刊)。它还将修复 Redmine 的 Textile 和 pandoc 之间的几个不兼容问题。
它在那里:https ://github.com/Ecodev/redmine_convert_textile_to_markown
当我尝试通过上面的 pandoc 命令(pandoc 版本为 1.12.4.2)将 markdown 文件转换为纺织文件时,Redmine 无法正确显示 CodeBlock。所以最好把 CodeBlock 写在一个 pre 元素中。
原文如下。
~~~ % 富吧 ~~~
转换后的一个如下。
公元前。% 富吧 % 富吧
-> 这无法在 redmine 中显示为 CodeBlock。
您应该事先将 CodeBlock 编写为前置元素。
<上一页> % 富吧 </pre>