Tôi đã viết một tác vụ cào để chuyển đổi tất cả các trang wiki và các phiên bản của họ thành markdown.
Đặt này vào 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
Và chạy:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
Nguồn
2013-11-09 12:36:03
Đó lóe lên trong óc tôi tại địa điểm đầu tiên, nhưng tôi đã không làm cabal cài đặt cabal-cài đặt trên CentOS của tôi 5. Tôi sẽ cung cấp cho nó một thử thời gian tới. – hSATAC
Chỉ cần lưu ý nhanh: Nếu có ai đó đang sử dụng plugin [Redmine CKEditor] (http://www.redmine.org/plugins/redmine-ckeditor), tất cả các phiên bản kể từ [1.0.18] (https: // github .com/a-ono/redmine_ckeditor/commit/383da5d60b2832757493cf65dc418c8ce2cff91C# diff-cb3e0f2c76a671c083e8f001970f4631) bao gồm tác vụ cào cho phép xác định định dạng nguồn và đích. – ZaLiTHkA