7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/redclothcoderay.rb', line 7
def preprocess_with_syntax_highlighting(text)
text.gsub(SOURCE_TAG_REGEXP) do |m|
all_of_it = $~[1]
whitespace_before = $~[2]
lang = ($~[3] || :ruby).to_sym
code = $~[4].strip
whitespace_after = $~[5]
wrap_in = all_of_it =~ /\n/ ? MULTI_LINE : SINGLE_LINE
if all_of_it =~ /\n/
highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS)
else
options = CODERAY_OPTIONS
options[:line_numbers] = nil
highlighted = wrap_in % CodeRay.scan(code, lang).span(options)
end
"#{whitespace_before}<notextile>#{highlighted}</notextile>#{whitespace_after}"
end
end
|