Class: Rote::Filters::Syntax

Inherits:
MacroFilter show all
Defined in:
lib/rote/filters/syntax.rb

Overview

Page filter that supports syntax highlighting for Ruby code, XML and YAML via the (extensible) Syntax (syntax.rubyforge.org/) library. Code is expected to be enclosed by the code macro:

#:code#ruby#
  def amethod(arg)
    puts arg
  end
#:code#

Where the macro argument may be ‘ruby’, ‘xml’, ‘yaml’, or a custom identifier registered (with Syntax) for a custom highlighter.

The macro output will resemble:

<pre class='#{lang}'><code class=#{lang}'>
  ...
</code></pre>

Syntax uses <span> tags for highlighting, with CSS classes used to apply formatting. See syntax.rubyforge.org/chapter-2.html for a list of recognised classes.

Instance Attribute Summary

Attributes inherited from MacroFilter

#handler_blk, #names

Instance Method Summary collapse

Methods inherited from MacroFilter

#filter, #handler

Constructor Details

#initialize(macro_re = MACRO_RE) ⇒ Syntax

Returns a new instance of Syntax.



41
42
43
# File 'lib/rote/filters/syntax.rb', line 41

def initialize(macro_re = MACRO_RE)
  super([],macro_re)
end

Instance Method Details

#macro_code(lang, body, raw) ⇒ Object

Implementation of the code macro.



46
47
48
49
# File 'lib/rote/filters/syntax.rb', line 46

def macro_code(lang,body,raw)
  converter = ::Syntax::Convertors::HTML.for_syntax(lang)
  "<pre class='#{lang}'><code class='#{lang}'>#{converter.convert(body,false)}</code></pre>"
end