Created
May 13, 2012 16:12
-
-
Save Lysander/2689105 to your computer and use it in GitHub Desktop.
Small Converter to generate markdown for MoinMoin from github's markdown dialect using Redcarpet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'redcarpet' | |
class MoinMoin < Redcarpet::Render::Base | |
def header(text, level) | |
prefix = "=" * level | |
"\n\n#{prefix} #{text} #{prefix}\n" | |
end | |
def paragraph(text) | |
"\n#{text}\n" | |
end | |
def block_code(code, language) | |
"\n{{{#!#{language}\n#{code}}}}\n" | |
end | |
def block_quote(quote) | |
quote.each_line.map {|l| " #{l}"}.join | |
end | |
def list(contents, list_type) | |
contents | |
end | |
def list_item(text, list_type) | |
"\n * #{text}" | |
end | |
def link(link, title, content) | |
"[[#{link}|#{content}]]" | |
end | |
def double_emphasis(text) | |
"'''#{text}'''" | |
end | |
def emphasis(text) | |
"''#{text}''" | |
end | |
end | |
File.open(ARGV[0], "r") do |f| | |
markdown = Redcarpet::Markdown.new(MoinMoin, :fenced_code_blocks => true, | |
:hard_wrap => true) | |
puts markdown.render(f.read) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment