13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/flavoured_markdown.rb', line 13
def flavoured_markdown(str)
str = RDiscount.new(str, :smart, :filter_styles, :filter_html).to_html
str = (str, :pre)
str.gsub!(%r{<br\s*\/?>}m, "<br/>")
str.gsub!(%r{<a\s(.*?)</a>}m) do
match = $1
match =~ %r{\son\w}m ? "<a #{match}</a>" : "<a #{match}</a>"
end
str = (str, :a)
str = auto_link(str, :all) do |txt|
txt.size < 55 ? txt : truncate(txt, :length => 50, :omission => "...")
end
str = (str, :a)
str.gsub!(%r{<(p|li)\b[^>]*>(.*?)</\1>}m) do |match|
last_space_index = match.rindex(' ')
if last_space_index
match = match.slice(0, last_space_index) + " " + match.slice(last_space_index + 1, match.length - last_space_index - 1)
end
match
end
str.sub!(%r{<p>(.*?)</p>\Z}, "<p class=\"last\">\\1</p>")
str = hellip(str)
str = (str)
str
end
|