removing all tags from redcloth pages

git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@7 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
master
andrew 2007-10-03 05:43:33 +00:00
parent da95e5dc7b
commit 77a8931fd8
4 changed files with 86 additions and 2 deletions

View File

@ -27,7 +27,7 @@ class Page < ActiveRecord::Base
# #
def update_html def update_html
# need to filter HTML first... remove <script> and chunks and the like... # need to filter HTML first... remove <script> and chunks and the like...
res = RedCloth.new(self.redcloth.to_s, [ :no_span_caps ]) res = RedCloth.new(self.redcloth.to_s.strip_tags, [ :no_span_caps ])
self.html = res.to_html( self.html = res.to_html(
# no link references. messes up lines starting with [[WikiWord]] # no link references. messes up lines starting with [[WikiWord]]
:block_textile_table, :block_textile_lists, :block_textile_prefix, :block_textile_table, :block_textile_lists, :block_textile_prefix,

View File

@ -8,3 +8,4 @@ Rails::Initializer.run do |config|
end end
require 'redcloth' require 'redcloth'
require 'actionview_text_helper'

View File

@ -0,0 +1,77 @@
# ActionView Text Helpers are great!
# Let's extend the String class to allow us to call
# some of these methods directly on a String.
# Note:
# - cycle-related methods are not included
# - concat is not included
# - pluralize is not included because it is in
# ActiveSupport String extensions already
# (though they differ).
# - markdown requires BlueCloth
# - textilize methods require RedCloth
# Example:
# "<b>coolness</b>".strip_tags -> "coolness"
require 'singleton'
# Singleton to be called in wrapper module
class TextHelperSingleton
include Singleton
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper #tag_options needed by auto_link
end
# Wrapper module
module MyExtensions #:nodoc:
module CoreExtensions #:nodoc:
module String #:nodoc:
module TextHelper
def auto_link(link = :all, href_options = {}, &block)
TextHelperSingleton.instance.auto_link(self, link, href_options, &block)
end
def excerpt(phrase, radius = 100, excerpt_string = "")
TextHelperSingleton.instance.excerpt(self, phrase, radius, excerpt_string)
end
def highlight(phrase, highlighter = '<strong class="highlight">\1</strong>')
TextHelperSingleton.instance.highlight(self, phrase, highlighter)
end
begin
require_library_or_gem 'bluecloth'
def markdown
TextHelperSingleton.instance.markdown(self)
end
rescue LoadError
# do nothing. method will be undefined
end
def sanitize
TextHelperSingleton.instance.sanitize(self)
end
def simple_format
TextHelperSingleton.instance.simple_format(self)
end
def strip_tags
TextHelperSingleton.instance.strip_tags(self)
end
begin
require_library_or_gem 'redcloth'
def textilize
TextHelperSingleton.instance.textilize(self)
end
def textilize_without_paragraph
TextHelperSingleton.instance.textilize_without_paragraph(self)
end
rescue LoadError
# do nothing. methods will be undefined
end
def truncate(length = 30, truncate_string = "")
TextHelperSingleton.instance.truncate(self, length, truncate_string)
end
def word_wrap(line_width = 80)
TextHelperSingleton.instance.word_wrap(self, line_width)
end
end
end
end
end
# extend String with the TextHelper functions
class String #:nodoc:
include MyExtensions::CoreExtensions::String::TextHelper
end

View File

@ -10,4 +10,10 @@ class PageTest < Test::Unit::TestCase
def test_destroy def test_destroy
assert_destroy('Page') assert_destroy('Page')
end end
def test_no_html_in_tag
p = Page.new :title => 'test page', :redcloth => '<ul><li>list</li></ul>'
p.save
assert p.html !~ /ul/
end
end end