Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
metadown/lib/metadown/renderer.rb /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (22 sloc)
724 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'redcarpet' | |
| require 'yaml' | |
| module Metadown | |
| # This class is our own flavor of Redcarpet. It grabs out | |
| # all the metadata before letting the rest of Redcarpet do | |
| # all the work. | |
| class Renderer < Redcarpet::Render::HTML | |
| # 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. | |
| def preprocess(full_document) | |
| full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m | |
| @metadata = YAML.load($1) if $1 | |
| $' or full_document | |
| end | |
| # This accessor lets us access our metadata after the | |
| # processing is all done. | |
| def metadata | |
| @metadata || {} | |
| end | |
| end | |
| end |