Class: GstKitchen::Feed::ShownotesRenderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/gst-kitchen/feed.rb

Constant Summary collapse

TWITTER_HANDLE_PATTER =
/(\W)@(\w+)\b/

Instance Method Summary collapse

Instance Method Details

#preprocess(full_document) ⇒ Object



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
# File 'lib/gst-kitchen/feed.rb', line 9

def preprocess(full_document)
  return full_document if full_document.nil?

  # Duplicate the string so we don't alter the original, then call to_str
  # to cast it back to a String instead of a SafeBuffer. This is required
  # for gsub calls to work as we need them to.
  full_document = full_document.dup.to_str

  # Extract pre blocks so they are not altered
  # from http://github.github.com/github-flavored-markdown/
  extractions = {}
  full_document.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) do |match|
    md5 = Digest::MD5.hexdigest(match)
    extractions[md5] = match
    "{gfm-extraction-#{md5}}"
  end

  full_document = parse(full_document)

  # Insert pre block extractions
  full_document.gsub!(/\{gfm-extraction-(\h{32})\}/) do
    extractions[$1]
  end

  return full_document
end