Class: Charming::Presentation::Markdown::SyntaxHighlighter

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

Instance Method Summary collapse

Constructor Details

#initialize(theme: UI::Theme.default) ⇒ SyntaxHighlighter

Returns a new instance of SyntaxHighlighter.



9
10
11
# File 'lib/charming/presentation/markdown/syntax_highlighter.rb', line 9

def initialize(theme: UI::Theme.default)
  @theme = theme || UI::Theme.default
end

Instance Method Details

#render(code, language: nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/charming/presentation/markdown/syntax_highlighter.rb', line 13

def render(code, language: nil)
  lexer = lexer_for(language, code)
  lexer.lex(code.to_s).map do |token, value|
    style_for(token).render(value)
  end.join
end