Module: RedclothWithCoderay

Defined in:
lib/redcloth_with_coderay.rb

Constant Summary collapse

SINGLE_LINE =
'<code class="inline_code">%s</code>'
MULTI_LINE =
'<pre><code class="multiline_code">%s</code></pre>'
WRAPPER =
'<notextile>%s</notextile>'
SOURCE_TAG_REGEXP =
/([\t\n]?<source(?:\:([a-z]+))?>(.+?)<\/source>[\t\n]?)/m

Instance Method Summary collapse

Instance Method Details

#refs_syntax_highlighter(text) ⇒ Object

The RedCloth extension that performs the syntax highlighting.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/redcloth_with_coderay.rb', line 15

def refs_syntax_highlighter(text)
  text.gsub!(SOURCE_TAG_REGEXP) do |m|
    all_of_it = $~[1]
    lang = ($~[2] || :ruby).to_sym
    code = $~[3].strip
    
    wrap_in = all_of_it.contains_newlines? ? MULTI_LINE : SINGLE_LINE
    highlighted = wrap_in % CodeRay.scan(code, lang).div(:wrap => nil, :css => :class)
    WRAPPER % highlighted
  end
end