Class: Henshin::HighlightPlugin

Inherits:
Generator show all
Defined in:
lib/henshin/plugins/highlight.rb

Instance Attribute Summary

Attributes inherited from Plugin

#config, #extensions, #priority

Instance Method Summary collapse

Methods inherited from Plugin

#<=>, subclasses

Constructor Details

#initialize(site) ⇒ HighlightPlugin

Returns a new instance of HighlightPlugin.



6
7
8
9
10
# File 'lib/henshin/plugins/highlight.rb', line 6

def initialize(site)
  @extensions = {:input => ['*']}
  @config = {}
  @priority = 1
end

Instance Method Details

#generate(content) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/henshin/plugins/highlight.rb', line 12

def generate( content )
  content =~ /(\$highlight)\s+(.+)((\n.*)+)(\$end)/
  if $1
    lang = $2.to_sym
    code = $3[1..-1] # removes first new line
    insert = '<pre><code>' + Simplabs::Highlight.highlight(lang, code) + '</code></pre>'
    content.gsub(/(\$highlight.*\$end)/m, insert)
  else
    content
  end
end