How to convert existing redmine wiki from textile to markdown?
Asked Answered
F

5

12

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?

Fard answered 20/3, 2012 at 6:12 Comment(0)
T
13

Since this is a once-only task why not pandoc -f textile -t markdown oldfile.text -o newfile.md? Try it at Try Pandoc.

Thaddeus answered 20/3, 2012 at 18:7 Comment(2)
That came to my mind at the first place, but I failed to do cabal install cabal-install on my centOs 5. I'll give it a try next time.Fard
Just a quick note: If anyone happens to be using the Redmine CKEditor plugin, all versions since 1.0.18 include a rake task that allows a source and target format to be specified.Dragging
C
11

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
Chammy answered 9/11, 2013 at 12:36 Comment(3)
This works great in redmine 2.5.2 (after my edit of filename and the RAILS_ENV)Concatenate
Worked flawlessly for our Redmine 2.6. I had to apt-get install pandoc first.Milstone
This worked nice (redmine 2.6.1.stable on windows), but with a few quirks: * I had to install pandoc, eg. with chocolatey: 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 linesVespiary
S
2

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

Scarabaeid answered 18/7, 2016 at 7:23 Comment(0)
S
1

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>
Schofield answered 9/1, 2015 at 11:25 Comment(0)
L
0

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.

Liaoning answered 27/8, 2022 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.