parent
4c42559a51
commit
f40e5cff5f
|
|
@ -82,16 +82,16 @@ module Jekyll
|
||||||
|
|
||||||
def render_rouge(code)
|
def render_rouge(code)
|
||||||
require "rouge"
|
require "rouge"
|
||||||
formatter = ::Rouge::Formatters::HTML.new
|
formatter = Rouge::Formatters::HTML.new
|
||||||
formatter = line_highlighter_formatter(formatter) if @highlight_options[:mark_lines]
|
formatter = line_highlighter_formatter(formatter) if @highlight_options[:mark_lines]
|
||||||
formatter = table_formatter(formatter) if @highlight_options[:linenos]
|
formatter = table_formatter(formatter) if @highlight_options[:linenos]
|
||||||
|
|
||||||
lexer = ::Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
lexer = Rouge::Lexer.find_fancy(@lang, code) || Rouge::Lexers::PlainText
|
||||||
formatter.format(lexer.lex(code))
|
formatter.format(lexer.lex(code))
|
||||||
end
|
end
|
||||||
|
|
||||||
def line_highlighter_formatter(formatter)
|
def line_highlighter_formatter(formatter)
|
||||||
::Rouge::Formatters::HTMLLineHighlighter.new(
|
Rouge::Formatters::HTMLLineHighlighter.new(
|
||||||
formatter,
|
formatter,
|
||||||
:highlight_lines => mark_lines
|
:highlight_lines => mark_lines
|
||||||
)
|
)
|
||||||
|
|
@ -106,13 +106,11 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def table_formatter(formatter)
|
def table_formatter(formatter)
|
||||||
::Rouge::Formatters::HTMLTable.new(
|
Rouge::Formatters::HTMLTable.new(
|
||||||
formatter,
|
formatter,
|
||||||
{
|
:css_class => "highlight",
|
||||||
:css_class => "highlight",
|
:gutter_class => "gutter",
|
||||||
:gutter_class => "gutter",
|
:code_class => "code"
|
||||||
:code_class => "code",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -121,12 +119,8 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_code_tag(code)
|
def add_code_tag(code)
|
||||||
code_attributes = [
|
code_attrs = %(class="language-#{@lang.tr("+", "-")}" data-lang="#{@lang}")
|
||||||
"class=\"language-#{@lang.to_s.tr("+", "-")}\"",
|
%(<figure class="highlight"><pre><code #{code_attrs}>#{code.chomp}</code></pre></figure>)
|
||||||
"data-lang=\"#{@lang}\"",
|
|
||||||
].join(" ")
|
|
||||||
"<figure class=\"highlight\"><pre><code #{code_attributes}>" \
|
|
||||||
"#{code.chomp}</code></pre></figure>"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue