Skip to content

Instantly share code, notes, and snippets.

@chiastolite
Created January 20, 2014 13:19
Show Gist options
  • Save chiastolite/8519728 to your computer and use it in GitHub Desktop.
Save chiastolite/8519728 to your computer and use it in GitHub Desktop.
Redcarptでgfmしたときの
def md(content)
gfm.render(content).html_safe
end
private
class XHTMLwithPygments < Redcarpet::Render::XHTML
def block_code(code, language)
::Pygments.highlight(code, lexer: language)
end
def postprocess(document)
document.gsub(/:([a-z0-9\+\-_]+):/) do |match|
if Emoji.names.include?($1)
"<img src='/assets/emoji/#{$1}.png'>"
else
match
end
end
end
end
def gfm
::Redcarpet::Markdown.new(
XHTMLwithPygments,
no_intra_emphasis: true,
tables: true,
fenced_code_blocks: true,
autolink: true,
strikethrough: true,
lax_spacing: true,
space_after_headers: true,
hard_wrap: true
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment