Skip to content

Instantly share code, notes, and snippets.

@delba
Created July 9, 2013 20:19
Show Gist options
  • Select an option

  • Save delba/5960902 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5960902 to your computer and use it in GitHub Desktop.
Markdown to HTML
require 'markdown'
class Article < ActiveRecord::Base
before_save do
self.html = Markdown.new(content).to_html
end
end
class Markdown
attr_reader :text
def initialize(text)
@text = text
end
def to_html
markdown.render(text)
end
private
def markdown
Redcarpet::Markdown.new HTMLWithPants.new(hard_wrap: true), {
no_intra_emphasis: true,
fenced_code_blocks: true,
hard_wrap: true
}
end
end
class HTMLWithPants < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment