Class: Metadown::Renderer

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/metadown/renderer.rb

Overview

This class is our own flavor of Redcarpet. It grabs out all the metadata before letting the rest of Redcarpet do all the work.

Instance Method Summary collapse

Instance Method Details

#metadataObject

This accessor lets us access our metadata after the processing is all done.



22
23
24
# File 'lib/metadown/renderer.rb', line 22

def 
  @metadata || {}
end

#preprocess(full_document) ⇒ Object

This hook is provided to us by Redcarpet. We get access to the whole text before anything else kicks off, which means we can snag out the YAML at the beginning.



13
14
15
16
17
18
# File 'lib/metadown/renderer.rb', line 13

def preprocess(full_document)
  full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
  @metadata = YAML.load($1) if $1

  $' or full_document
end