Sha256: b5b25b079d66ed569a1bf69477f814409ab74c89fc228cd829d9d6350cd2c1e7
Contents?: true
Size: 913 Bytes
Versions: 6
Compression:
Stored size: 913 Bytes
Contents
class Rad::TextUtils::GithubFlavouredMarkdown < Rad::TextUtils::Processor def process markdown, env # Extract pre blocks extractions = {} markdown.gsub!(%r{<pre>.*?</pre>}m) do |match| md5 = Digest::MD5.hexdigest(match) extractions[md5] = match "{gfm-extraction-#{md5}}" end # prevent foo_bar_baz from ending up with an italic word in the middle markdown.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x| x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__' end # in very clear cases, let newlines become <br /> tags markdown.gsub!(/^[\w\<\!][^\n]*\n+/) do |x| if x =~ /\>[\n\r]*/ x else x =~ /\n{2}/ ? x : (x.strip!; x << " \n") end end # Insert pre block extractions markdown.gsub!(/\{gfm-extraction-([0-9a-f]{32})\}/) do "\n\n" + extractions[$1] end call_next markdown, env end end
Version data entries
6 entries across 6 versions & 1 rubygems