Permalink
Browse files

Made renderer work properly.

  • Loading branch information...
1 parent 1474100 commit bf1e9594dd8bc14676d416791ea27b3012e91e81 @steveklabnik committed Jan 22, 2012
Showing with 25 additions and 4 deletions.
  1. +10 −1 lib/metadown/renderer.rb
  2. +15 −3 spec/renderer_spec.rb
View
@@ -1,6 +1,15 @@
-require "redcarpet"
+require 'redcarpet'
+require 'yaml'
module Metadown
class Renderer < Redcarpet::Render::HTML
+ attr_accessor :metadata
+
+ def preprocess(full_document)
+ full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
+ @metadata = YAML.load($1) if $1
+
+ $' or full_document
+ end
end
end
View
@@ -7,9 +7,21 @@
end
it "renders markdown" do
- r = Redcarpet::Markdown.new(subject)
- r.render("hello world").should eql("<p>hello world</p>\n")
+ r = Redcarpet::Markdown.new(subject)
+ r.render("hello world").should eql("<p>hello world</p>\n")
end
- it "extracts YAML"
+ it "extracts YAML" do
+ r = Redcarpet::Markdown.new(subject)
+ text = <<-MARKDOWN
+---
+key: "value"
+---
+hello world
+MARKDOWN
+
+ r.render text
+
+ subject.metadata.should eql({"key"=>"value"})
+ end
end

0 comments on commit bf1e959

Please sign in to comment.