Skip to content

Instantly share code, notes, and snippets.

@mudge
Created September 14, 2010 18:50
Show Gist options
  • Select an option

  • Save mudge/579549 to your computer and use it in GitHub Desktop.

Select an option

Save mudge/579549 to your computer and use it in GitHub Desktop.
JRuby class for using pegdown as the Rails Markdown processor.
require 'markdown'
module ApplicationHelper
def markdown(text)
if text.present?
Markdown.new(text).to_html
else
text
end
end
end
require 'parboiled4j-0.9.8.2'
require 'pegdown-0.8.5.3'
class Markdown
def initialize(text)
@text = text
@processor = Java::OrgPegdown::PegDownProcessor.new(Java::OrgPegdown::Extensions::AUTOLINKS | Java::OrgPegdown::Extensions::HARDWRAPS)
end
def to_html
@processor.markdownToHtml(@text)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment