Class: Wiki2Go::SyntaxHighlighter

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

Overview

Wiki2Go plugin to syntax-highlight code. plugin format: &lt;–Syntax:<language> <code>–&gt; requires ‘syntax’ gem rubyforge.org/projects/syntax/ Currently supported languages:

  • ruby

  • xml

  • yaml

Instance Method Summary collapse

Instance Method Details

#process(config, web, content) ⇒ Object

Process the content through the syntax code->html convertor



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/Wiki2Go/SyntaxHighlighter.rb', line 21

def process(config,web,content)
  if content =~  /^([^\s]*)\s/ then
    language = $1.downcase
    code = $POSTMATCH 
    convertor = Syntax::Convertors::HTML.for_syntax(language)
    formatted = convertor.convert(code,true)
    return "<div class=\"#{language}\">" + $/ + formatted + $/ + "</div>" + $/
  else 
    config.errorlog("SyntaxHighlighter: Could not determine code language of #{content}")
    return '<pre>' + $/ + content + $/ + "</pre>" + $/
  end
end

#save(config, web, content) ⇒ Object

Process the content through the syntax code->html convertor Identical to #process



36
37
38
# File 'lib/Wiki2Go/SyntaxHighlighter.rb', line 36

def save(config,web,content)
  process(config,web,content)
end