Skip to content

Commit

Permalink
HTML syntax highlighters should store the default language in the opt…
Browse files Browse the repository at this point in the history
…s parameter
  • Loading branch information
gettalong committed Apr 18, 2016
1 parent e285a4e commit c7cef4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/kramdown/converter/syntax_highlighter.rb
Expand Up @@ -46,6 +46,9 @@ module Converter
# :block type text correctly wrapped (i.e. normally inside a pre-tag, but may
# also be a table-tag or just a div-tag) but :span type text *without* a
# code-tag!
#
# Also, a syntax highlighter should store the default highlighting language for
# the invocation in the +opts+ hash under the key :default_lang.
module SyntaxHighlighter
end

Expand Down
6 changes: 3 additions & 3 deletions lib/kramdown/converter/syntax_highlighter/coderay.rb
Expand Up @@ -21,14 +21,14 @@ module Coderay
AVAILABLE = false # :nodoc:
end

def self.call(converter, text, lang, type, _unused_opts)
def self.call(converter, text, lang, type, call_opts)
return nil unless converter.options[:enable_coderay]

if type == :span && lang
::CodeRay.scan(text, lang.to_sym).html(options(converter, :span)).chomp
elsif type == :block && (lang || options(converter, :default_lang))
lang = (lang || options(converter, :default_lang)).to_s.gsub(/-/, '_').to_sym
::CodeRay.scan(text, lang).html(options(converter, :block)).chomp << "\n"
lang ||= call_opts[:default_lang] = options(converter, :default_lang)
::CodeRay.scan(text, lang.to_s.gsub(/-/, '_').to_sym).html(options(converter, :block)).chomp << "\n"
else
nil
end
Expand Down
3 changes: 2 additions & 1 deletion lib/kramdown/converter/syntax_highlighter/rouge.rb
Expand Up @@ -21,8 +21,9 @@ module Rouge
AVAILABLE = false # :nodoc:
end

def self.call(converter, text, lang, type, _unused_opts)
def self.call(converter, text, lang, type, call_opts)
opts = options(converter, type)
call_opts[:default_lang] = opts[:default_lang]
lexer = ::Rouge::Lexer.find_fancy(lang || opts[:default_lang], text)
return nil if opts[:disable] || !lexer

Expand Down

0 comments on commit c7cef4f

Please sign in to comment.