class RailsMarkdownTemplates::Renderer
Custom Redcarpet HTML renderer for Markdown with a metadata block
Attributes
metadata[RW]
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
# File lib/rails_markdown_templates/renderer.rb, line 31 def initialize(options={}) super options @metadata = {} end
Public Instance Methods
doc_header()
click to toggle source
Render before any other elements
# File lib/rails_markdown_templates/renderer.rb, line 49 def doc_header nil end
metadata_json()
click to toggle source
Get JSON for the metadata
# File lib/rails_markdown_templates/renderer.rb, line 44 def metadata_json metadata.to_json.html_safe end
preprocess(full_document)
click to toggle source
Preprocess the whole document before the rendering process
# File lib/rails_markdown_templates/renderer.rb, line 59 def preprocess(full_document) # Extract and store metadata block from start of document # # N.B. Implementation "borrowed" from Metadown: # # https://github.com/steveklabnik/metadown full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m self.metadata = YAML.load($1) if $1 # Return the document without the leading metadata block $POSTMATCH or full_document end