Skip to content

Commit

Permalink
Ok, so we do this the regexp way.
Browse files Browse the repository at this point in the history
  • Loading branch information
techbelly committed Jul 12, 2011
1 parent 4942286 commit 4117770
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lib/govspeak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,40 @@

module Govspeak

class Document < Kramdown::Document
class Document

@@extensions = []

def initialize(source,options = {})
@doc = Kramdown::Document.new(preprocess(source),options)
super
end

def to_html
@doc.to_html
end

def preprocess(source)
@@extensions.each do |title,block|
regexp = %r${::#{title}}(.*?){:/#{title}}$m
source.gsub!(regexp) {|match|
block.call($1)
}
end
source
end

def self.extension(title,&block)
@@extensions << [title,block]
end

extension('reverse') { |body|
body.reverse
}

end



end

6 changes: 6 additions & 0 deletions test/govspeak_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ class GovspeakTest < Test::Unit::TestCase
assert_equal "<p><em>this is markdown</em></p>\n", rendered
end

test "simple block extension" do
rendered = Govspeak::Document.new("this \n{::reverse}\n*is*\n{:/reverse}\n markdown").to_html
assert_equal "<p>this </p>\n\n<p><em>si</em></p>\n\n<p>markdown</p>\n", rendered
end


end

0 comments on commit 4117770

Please sign in to comment.