Module: RedclothCoderay
- Defined in:
- lib/redclothcoderay.rb
Constant Summary collapse
- SINGLE_LINE =
'<code class="inline_code">%s</code>'
- MULTI_LINE =
'<div class="multiline_code">%s</div>'
- SOURCE_TAG_REGEXP =
/(([\t\n])?<source(?:\:([a-z]+))?>(.+?)<\/source>([\t\n])?)/m
- CODERAY_OPTIONS =
{:wrap => nil, :css => :class}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.coderay_options(options) ⇒ Object
22 23 24 |
# File 'lib/redclothcoderay.rb', line 22 def self.() CODERAY_OPTIONS.replace() end |
Instance Method Details
#preprocess_with_syntax_highlighting(text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 highlighted = wrap_in % CodeRay.scan(code, lang).div(CODERAY_OPTIONS) "#{whitespace_before}<notextile>#{highlighted}</notextile>#{whitespace_after}" end end |