Class: TTY::Markdown::Highlighter Private
- Inherits:
-
Object
- Object
- TTY::Markdown::Highlighter
- Defined in:
- lib/tty/markdown/highlighter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for highlighting terminal code snippets
Instance Method Summary collapse
-
#highlight(code, language = nil) ⇒ String
Highlight the code snippet.
-
#initialize(decorator, mode: 256) ⇒ Highlighter
constructor
Create a Highlighter instance.
Constructor Details
#initialize(decorator, mode: 256) ⇒ Highlighter
Create a TTY::Markdown::Highlighter instance
24 25 26 27 |
# File 'lib/tty/markdown/highlighter.rb', line 24 def initialize(decorator, mode: 256) @decorator = decorator @mode = mode end |
Instance Method Details
#highlight(code, language = nil) ⇒ String
Highlight the code snippet
42 43 44 45 46 47 |
# File 'lib/tty/markdown/highlighter.rb', line 42 def highlight(code, language = nil) return code unless @decorator.enabled? lexer = select_lexer(code, language) formatter.format(lexer.lex(code)) end |