Rely on the Redcarpet plugin instead of hard-coding
To avoid code duplication and have to keep tracking of the API change of Rouge, let's rely on the Redcarpet plugin and customize the output on our needs.
This commit is contained in:
parent
4bf716c2ad
commit
bd442680ea
|
@ -38,16 +38,15 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
module WithRouge
|
module WithRouge
|
||||||
|
require 'rouge'
|
||||||
|
require 'rouge/plugins/redcarpet'
|
||||||
|
|
||||||
|
include Rouge::Plugins::Redcarpet
|
||||||
include CommonMethods
|
include CommonMethods
|
||||||
|
|
||||||
def block_code(code, lang)
|
def block_code(code, lang)
|
||||||
require 'rouge'
|
|
||||||
|
|
||||||
lexer = Rouge::Lexer.find_fancy(lang, code) || Rouge::Lexers::PlainText
|
|
||||||
formatter = Rouge::Formatters::HTML.new
|
|
||||||
|
|
||||||
output = "<div class=\"highlight\">"
|
output = "<div class=\"highlight\">"
|
||||||
output << add_code_tags(formatter.render(lexer.lex(code)), lang)
|
output << add_code_tags(super, lang)
|
||||||
output << "</div>"
|
output << "</div>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue