Class: Markabb::SyntaxHighlighter

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

Overview

Super class for syntax highlighters

All syntax highlighters need to inherit from this class

Direct Known Subclasses

Highlighters::Coderay, Highlighters::Raw

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SyntaxHighlighter

Returns a new instance of SyntaxHighlighter.



19
20
21
# File 'lib/markabb/classes/syntax_highlighter.rb', line 19

def initialize(config)
    @config = config
end

Instance Method Details

#run(s) ⇒ Object

Runs the syntax highlighter

Finds all instances of the code tag and passes it to the parse function



26
27
28
29
30
31
32
# File 'lib/markabb/classes/syntax_highlighter.rb', line 26

def run(s)
    out = s
    out.scan(/\[code lang=(.+?)\](.+?)\[\/code\]/m).each do |lang, parse|
        out = out.gsub("[code lang=#{lang}]#{parse}[/code]", parse(lang, parse))
    end
    return out
end