From ee65dadc9a5ae5fc8f19848754f7175ebd630375 Mon Sep 17 00:00:00 2001 From: Kevin Marsh Date: Thu, 12 Feb 2009 18:21:40 -0500 Subject: [PATCH] Add textilize filter for transforming input into HTML via RedCloth, so you can have Textile-formatted attributes other than the page's content (for example, an excerpt) --- README.textile | 6 ++++++ lib/jekyll/filters.rb | 4 ++++ test/test_filters.rb | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/README.textile b/README.textile index c08efb6b..e856345e 100644 --- a/README.textile +++ b/README.textile @@ -306,6 +306,12 @@ Convert an array into a sentence. becomes foo, bar, and baz + +h3. Textilize + +Convert a Textile-formatted string into HTML, formatted via RedCloth + + {{ page.excerpt | textilize }} h3. Include (Tag) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index cb7c5d51..6bb08096 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -1,6 +1,10 @@ module Jekyll module Filters + def textilize(input) + RedCloth.new(input).to_html + end + def date_to_string(date) date.strftime("%d %b %Y") end diff --git a/test/test_filters.rb b/test/test_filters.rb index 9cd25f6d..e6700191 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -10,6 +10,10 @@ class TestFilters < Test::Unit::TestCase @filter = JekyllFilter.new end + def test_textilize_with_simple_string + assert_equal "

something really simple

", @filter.textilize("something *really* simple") + end + def test_array_to_sentence_string_with_no_args assert_equal "", @filter.array_to_sentence_string([]) end