Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upgrading to Redcarpet v2.0 with highlighting of code blocks with Albino/Pygments
module ApplicationHelper
def markdown(text, *renderer)
rndr_flags = {
hard_wrap: true,
gh_blockcode: true,
safe_links_only: true,
filter_html: true
}
case renderer[0]
when :authored
rndr_flags[:filter_html] = false
else
rndr_flags.merge({:no_images => true, :no_styles => true})
end
rndr = HTMLwithAlbino.new(rndr_flags)
redcarpet = Redcarpet::Markdown.new(rndr, :space_after_headers => true,
:fenced_code_blocks => true, :autolink => true, :no_intra_emphasis => true,
:strikethrough => true, :superscripts => true)
redcarpet.render(text).html_safe
end
end
# create a custom renderer that allows highlighting of code blocks
class HTMLwithAlbino < Redcarpet::Render::HTML
def block_code(code, language)
Albino.colorize(code, language)
end
end
@bsodmike

This comment has been minimized.

Copy link
Owner Author

bsodmike commented Dec 12, 2011

Calling markdown without any arguments will assume publicly created content, hence, it filters out as much as possible; still doing Albino.colorize() instead of Albino.safe_colorize() as I haven't upgraded it yet.

@bsodmike

This comment has been minimized.

Copy link
Owner Author

bsodmike commented Dec 13, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.