2012-03-20 60 views

回答

11

由於這是一次只爲什麼不是pandoc -f textile -t markdown oldfile.text -o newfile.md?試試Try Pandoc

+0

那來到我的腦海中第一個地方,但我沒有做到小集團安裝在我的CentOS 5小集團安裝,我給它一個嘗試下一次。 – hSATAC 2012-03-21 05:41:52

+0

只是一個快速提示:如果有人恰好在使用[Redmine CKEditor](http://www.redmine.org/plugins/redmine-ckeditor)插件,所有版本自[1.0.18](https:// github) .com/a-ono/redmine_ckeditor/commit/383da5d60b2832757493cf65dc418c8ce2cff91c#diff-cb3e0f2c76a671c083e8f001970f4631)包含一個rake任務,該任務允許指定源格式和目標格式。 – ZaLiTHkA 2015-05-22 09:29:01

11

我寫了一個rake任務,將所有wiki頁面及其版本轉換爲降價。

將這個成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 
+0

這對redmine 2.5.2非常有用(在我編輯文件名和RAILS_ENV後) – 2014-07-29 07:48:55

+0

完美地爲我們的Redmine 2.6工作。我必須先「安裝pandoc」。 – tvdeyen 2014-12-19 10:09:18

+0

這工作很好(在Windows上redmine 2.6.1.stable),但有一些怪癖: *我不得不安裝pandoc,例如。巧克力:'choco install pandoc' *對於某些文件而言,pandoc失敗 - 我改變了提升「pandoc失敗」以使「pandoc失敗」忽略這些錯誤*項目符號列表(使用*)包含斜槓(\\)線 – qbik 2015-01-22 09:17:48

0

當我試圖通過上述pandoc命令降價文件轉換成紡織品文件(pandoc版本是1.12.4.2) Redmine無法正確顯示CodeBlock。所以最好在代碼塊中寫入CodeBlock。

原始是波紋管。

 
~~~ 
% foo bar 
~~~ 

轉換後的一個是波紋管。

 
bc. % foo bar 
% foo bar 

- >這不能作爲CodeBlock在redmine中顯示。

您應該事先將代碼塊編寫爲預元素。

 
<pre> 
% foo bar 
</pre>