Method: Lookbook::CodeFormatter.highlight
- Defined in:
- lib/lookbook/code_formatter.rb
.highlight(source, language, opts = {}) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/lookbook/code_formatter.rb', line 7 def highlight(source, language, opts = {}) source&.strip! unless opts[:strip] == false source&.gsub!(">", ">")&.gsub!("<", "<") language ||= "ruby" formatter = Formatter.new(opts) lexer = Rouge::Lexer.find(language.to_s) || Rouge::Lexer.find("plaintext") formatter.format(lexer.lex(source)).html_safe end |