Sha256: eb0feceeed74d4f78c278c78def953c25f35a0de5452d4acb953ba535762dd78

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metadown-1.1.0.beta lib/metadown/renderer.rb
metadown-1.0.1 lib/metadown/renderer.rb
metadown-1.0.0 lib/metadown/renderer.rb