Skip to content

Instantly share code, notes, and snippets.

@2called-chaos
Last active December 27, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2called-chaos/7281878 to your computer and use it in GitHub Desktop.
Save 2called-chaos/7281878 to your computer and use it in GitHub Desktop.
# create a custom renderer that allows highlighting of code blocks
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
if language.to_s.end_with?("CHL")
language = language[0...-3]
code = Pygments.highlight(code, lexer: language, options: { linespans: Digest::SHA1.base64digest(code) })
code = code.gsub(/<span class="(?:[a-z]+)">==<\/span>(.*?)<span class="(?:[a-z]+)">==<\/span>/, %{<span class="highlight">\\1</span>}.html_safe)
else
Pygments.highlight(code, lexer: language, options: { linespans: Digest::SHA1.base64digest(code) })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment