lib/makeup/syntax_highlighter.rb in makeup-0.4.0 vs lib/makeup/syntax_highlighter.rb in makeup-0.4.1

- old
+ new

@@ -35,16 +35,15 @@ end def highlight(path, code, options = {}) options[:lexer] ||= lexer(path, code) lexer = Pygments::Lexer.find(options[:lexer]) - code = lexer.nil? ? code : Pygments.highlight(code, highlight_options(options)) - CodeBlock.new(lexer && lexer.aliases.first, code) - rescue MentosError => e - # "MentosError" is what Pyments.rb raises when an unknown lexer is - # attempted used - CodeBlock.new(nil, @entities.encode(code)) + return unknown_lexer(code) unless lexer + code = Pygments.highlight(code, highlight_options(options)) + CodeBlock.new(lexer.aliases.first, code) + rescue MentosError + unknown_lexer(code) end def lexer(path, code = nil, mode = nil) self.class.lexer(path, code, mode) end @@ -53,9 +52,14 @@ lexer = Linguist::Language.detect(path, code, mode) lexer && (lexer.aliases.first || lexer.name) end private + + def unknown_lexer(code) + CodeBlock.new(nil, @entities.encode(code)) + end + def highlight_options(options = {}) options[:options] ||= {} options[:options][:nowrap] = true options[:options][:encoding] ||= "utf-8" options