Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created July 22, 2012 07:20
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mxswd/3158772 to your computer and use it in GitHub Desktop.
Save mxswd/3158772 to your computer and use it in GitHub Desktop.
Convert Markdown to Creole
#!/usr/bin/env ruby
# Invoke with `ruby md2cre.rb filename.md`
#
# Setup: `gem install redcarpet`
require 'rubygems'
require 'redcarpet'
class Creole < Redcarpet::Render::Base
def normal_text(text)
text
end
def link(link, title, content)
"[[#{link}|#{content}]]"
end
def block_code(code, language)
"\n{{{\n#{normal_text(code)}\n}}}\n"
end
def codespan(code)
block_code(code, nil)
end
def header(title, level)
case level
when 1
"\n= #{title} =\n"
when 2
"\n== #{title} ==\n"
when 3
"\n=== #{title} ===\n"
end
end
def double_emphasis(text)
"**#{text}**"
end
def emphasis(text)
"//#{text}//"
end
def linebreak
"\n"
end
def paragraph(text)
"\n#{text}\n"
end
def list(content, list_type)
case list_type
when :ordered
"\n#{content}\n"
when :unordered
"\n#{content}\n"
end
end
def list_item(content, list_type)
case list_type
when :ordered
"##{content.strip}\n"
when :unordered
"*#{content.strip}\n"
end
end
end
markdown = Redcarpet::Markdown.new(Creole, :fenced_code_blocks => true)
puts markdown.render(File.read(ARGV[0]))
@vramana
Copy link

vramana commented Jul 28, 2013

Can you please write a similar script which converts markdown to creole??

@timbru31
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment