I want to use markdown as my redmine wiki engine.
I installed the markdown plugin and it worked well.
The only question is, how can I convert those old wiki (textile) into markdown so they can be displayed correctly?
I want to use markdown as my redmine wiki engine.
I installed the markdown plugin and it worked well.
The only question is, how can I convert those old wiki (textile) into markdown so they can be displayed correctly?
Since this is a once-only task why not pandoc -f textile -t markdown
oldfile.text -o newfile.md? Try it at Try Pandoc.
I wrote a rake task to convert all wiki pages and their versions to markdown.
Put this into 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
And run:
bundle exec rake convert_textile_to_markdown RAILS_ENV=production
apt-get install pandoc
first. –
Milstone choco install pandoc
* for some files pandoc failed - i changed raise "pandoc failed" to puts "pandoc failed" to ignore these errors * bulleted lists (using *) contained slashes (\) at the end of lines –
Vespiary Building upon Michaël's answer, here is a tool to migrate from Textile to Markdown. It will migrate all content (comment, wiki, issue, message, news, document, project and journal). And it will also fixes several incompatibility between Redmine's Textile and pandoc's.
It's over there: https://github.com/Ecodev/redmine_convert_textile_to_markown
When I tried to convert the markdown file into textile file by above pandoc command(pandoc version is 1.12.4.2),Redmine could not display CodeBlock properly. So it is better that had been written CodeBlock in a pre element.
original is bellow.
~~~ % foo bar ~~~
converted one is bellow.
bc. % foo bar % foo bar
-> This could not be displayed in redmine as a CodeBlock.
You should write CodeBlock as a pre element beforehand.
<pre> % foo bar </pre>
Just used redmine_reformat on a redmine 4.1.1 system with ruby 2.6.6 and it seemed to work fine. It does not currently work for redmine 5.0. In our case we were migrating to redmine 5.x so we did the switch in the 4.1.1 system, deleted the plugin and then migrated to 5.x.
© 2022 - 2024 — McMap. All rights reserved.