Sha256: 8e79f711fadf35e575292d5a5ff2a6459f07dec0a379b32bf77890d1dfc06421
Contents?: true
Size: 827 Bytes
Versions: 1
Compression:
Stored size: 827 Bytes
Contents
begin require 'linguist' rescue LoadError $stderr.puts "You need to install linguist before using the SyntaxHighlightFilter. See README.md for details" exit 1 end module HTML class Pipeline # HTML Filter that syntax highlights code blocks wrapped # in <pre lang="...">. class SyntaxHighlightFilter < Filter def call doc.search('pre').each do |node| next unless lang = node['lang'] next unless lexer = Pygments::Lexer[lang] text = node.inner_text html = highlight_with_timeout_handling(lexer, text) next if html.nil? node.replace(html) end doc end def highlight_with_timeout_handling(lexer, text) lexer.highlight(text) rescue Timeout::Error => boom nil end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
html-pipeline-0.0.7 | lib/html/pipeline/syntax_highlight_filter.rb |