Skip to content

Instantly share code, notes, and snippets.

@Lysander
Created May 13, 2012 16:12
Show Gist options
  • Save Lysander/2689105 to your computer and use it in GitHub Desktop.
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.
#!/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