From f40e5cff5f48a424e6f8636a48f5a20c3b1d9447 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 7 Nov 2022 12:24:19 +0530 Subject: [PATCH] Cleanup highlight tag (#9177) Merge pull request 9177 --- lib/jekyll/tags/highlight.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 321a49f8..fcea81ff 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -82,16 +82,16 @@ module Jekyll def render_rouge(code) require "rouge" - formatter = ::Rouge::Formatters::HTML.new + formatter = Rouge::Formatters::HTML.new formatter = line_highlighter_formatter(formatter) if @highlight_options[:mark_lines] 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)) end def line_highlighter_formatter(formatter) - ::Rouge::Formatters::HTMLLineHighlighter.new( + Rouge::Formatters::HTMLLineHighlighter.new( formatter, :highlight_lines => mark_lines ) @@ -106,13 +106,11 @@ module Jekyll end def table_formatter(formatter) - ::Rouge::Formatters::HTMLTable.new( + Rouge::Formatters::HTMLTable.new( formatter, - { - :css_class => "highlight", - :gutter_class => "gutter", - :code_class => "code", - } + :css_class => "highlight", + :gutter_class => "gutter", + :code_class => "code" ) end @@ -121,12 +119,8 @@ module Jekyll end def add_code_tag(code) - code_attributes = [ - "class=\"language-#{@lang.to_s.tr("+", "-")}\"", - "data-lang=\"#{@lang}\"", - ].join(" ") - "
" \
-          "#{code.chomp}
" + code_attrs = %(class="language-#{@lang.tr("+", "-")}" data-lang="#{@lang}") + %(
#{code.chomp}
) end end end