Class: SyntaxHighlighter
- Inherits:
-
Object
- Object
- SyntaxHighlighter
- Defined in:
- lib/syntax_highlighter.rb
Overview
syntax highlighting class
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#lexer ⇒ Object
readonly
Returns the value of attribute lexer.
Instance Method Summary collapse
- #highlight(code) ⇒ Object
-
#initialize ⇒ SyntaxHighlighter
constructor
A new instance of SyntaxHighlighter.
Constructor Details
#initialize ⇒ SyntaxHighlighter
Returns a new instance of SyntaxHighlighter.
7 8 9 10 |
# File 'lib/syntax_highlighter.rb', line 7 def initialize @formatter = Rouge::Formatters::Terminal256.new @lexer = Rouge::Lexers::Shell.new end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
5 6 7 |
# File 'lib/syntax_highlighter.rb', line 5 def formatter @formatter end |
#lexer ⇒ Object (readonly)
Returns the value of attribute lexer.
5 6 7 |
# File 'lib/syntax_highlighter.rb', line 5 def lexer @lexer end |
Instance Method Details
#highlight(code) ⇒ Object
12 13 14 |
# File 'lib/syntax_highlighter.rb', line 12 def highlight(code) formatter.format(lexer.lex(code)) end |