Last active
August 29, 2016 05:28
-
-
Save krismeister/6e33e7c0f4a1f8e4a8708779f253e1ca to your computer and use it in GitHub Desktop.
Extend the Redcarpet HTML Renderer to output language-XXX class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PreCodeLanguageMarkdown < Redcarpet::Render::HTML | |
def block_code(code, language) | |
[ | |
'<pre>', | |
"<code class='language-#{language}'>#{html_escape(code)}</code>", | |
'</pre>' | |
].join() | |
end | |
private | |
# Doesn't seem dangerous, keep an eye on it. | |
def html_escape(string) | |
string.gsub(/['&\"<>\/]/, { | |
'&' => '&', | |
'<' => '<', | |
'>' => '>', | |
'"' => '"', | |
"'" => ''', | |
"/" => '/', | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this file in Rail's
./lib
Require the file where you need to render:
Then be sure to add the file to the watch list, so when you change it , your development env will reload it: