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
|
# File 'app/helpers/admin/atreides/github_helper.rb', line 15
def gfm(text)
= {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
[md5] = match
"{gfm-extraction-#{md5}}"
end
text.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x|
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
end
text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
x.gsub(/^(.+)$/, "\\1 ")
end
text.gsub!(/\{gfm-extraction-([0-9a-f]{32})\}/) do
[$1]
end
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(GH_OPTIONS), GH_OPTIONS)
markdown.render(text)
end
|