1232

C code posted by 3213
created at 15 Feb 00:23

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'coderay'
module EntriesHelper
  
  def parse_message(entry)
    message = entry.content
    if entry.code_entry?
      message = syntax_highlight(message)
    elsif !entry.file_entry?
     message = convert_hyperlinks(message)
    end
    message
  end 
  
  def color_class(entry)
    !entry.topic.nil? ? "color#{entry.topic.color}" : "color0"
  end
    
    
  private
  
    def convert_hyperlinks(message)
      parts = message.split "\n"
      parts.map {|s| h(s)}.join(" <br/>").gsub(/(http|https|ftp)([^ ]+)/i) {|s| "<a target='_blank' href='#{s}'     rel='nofollow'>#{s}</a>"}
    end
    
    def syntax_highlight(message)
      tokens = CodeRay.scan message, :ruby
      page = tokens.html :line_numbers => :inline   
      page = "<div class='CodeRay'><pre>#{page}</pre></div>"
    end
 


    
end
854 Bytes in 3 ms with coderay