Skip to content

Commit

Permalink
Merge pull request #153 from pchaigno/linguist-lexers
Browse files Browse the repository at this point in the history
Use Linguist lexers
  • Loading branch information
jch committed Oct 5, 2014
2 parents aeadfbd + 956be5b commit 68b876f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/html/pipeline/syntax_highlight_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def call
doc.search('pre').each do |node|
default = context[:highlight] && context[:highlight].to_s
next unless lang = node['lang'] || default
next unless lexer = Pygments::Lexer[lang]
next unless lexer = lexer_for(lang)
text = node.inner_text

html = highlight_with_timeout_handling(lexer, text)
Expand All @@ -34,6 +34,10 @@ def highlight_with_timeout_handling(lexer, text)
rescue Timeout::Error => boom
nil
end

def lexer_for(lang)
(Linguist::Language[lang] && Linguist::Language[lang].lexer) || Pygments::Lexer[lang]
end
end
end
end

0 comments on commit 68b876f

Please sign in to comment.