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
|
# File 'lib/github-flavored-markdown/code.rb', line 6
def self.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
text
end
|