12

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

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

唯一的问题是,我怎样才能将那些旧的 wiki(纺织品)转换为 markdown,以便它们可以正确显示?

4

4 回答 4

13

既然这是一个只有一次的任务,为什么不pandoc -f textile -t markdownoldfile.text -o newfile.md呢?在Try Pandoc尝试一下。

于 2012-03-20T18:07:14.770 回答
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

并运行:

bundle exec rake convert_textile_to_markdown RAILS_ENV=production
于 2013-11-09T12:36:03.637 回答
2

基于Michaël 的回答,这是一个从 Textile 迁移到 Markdown 的工具。它将迁移所有内容(评论、wiki、问题、消息、新闻、文档、项目和期刊)。它还将修复 Redmine 的 Textile 和 pandoc 之间的几个不兼容问题。

它在那里:https ://github.com/Ecodev/redmine_convert_textile_to_markown

于 2016-07-18T07:23:21.520 回答
1

当我尝试通过上面的 pandoc 命令(pandoc 版本为 1.12.4.2)将 markdown 文件转换为纺织文件时,Redmine 无法正确显示 CodeBlock。所以最好把 CodeBlock 写在一个 pre 元素中。

原文如下。

~~~
% 富吧
~~~

转换后的一个如下。

公元前。% 富吧
% 富吧

-> 这无法在 redmine 中显示为 CodeBlock。

您应该事先将 CodeBlock 编写为前置元素。

<上一页>
 % 富吧
</pre>
于 2015-01-09T11:25:36.367 回答