app*_*ive 11
既然这是一次性的任务,为什么不是pandoc -f textile -t markdownoldfile.text -o newfile.md?在Try Pandoc尝试一下.
Mic*_*ant 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
Run Code Online (Sandbox Code Playgroud)
并运行:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
Run Code Online (Sandbox Code Playgroud)