Class: SyntaxHighlighter

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_highlighter.rb

Overview

syntax highlighting class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSyntaxHighlighter

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

#formatterObject (readonly)

Returns the value of attribute formatter.



5
6
7
# File 'lib/syntax_highlighter.rb', line 5

def formatter
  @formatter
end

#lexerObject (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