Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created August 5, 2011 18:46
Show Gist options
  • Save ashaw/1128208 to your computer and use it in GitHub Desktop.
Save ashaw/1128208 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'sanitize'
get '/' do
<<-HTML
<form method="post" action="/sanitize">
<textarea name="dirty" style="width:100%;height:800px;"></textarea>
<input type="submit" value="Submit">
</form>
HTML
end
post '/sanitize' do
dirty = params[:dirty]
clean = Sanitize.clean(dirty,
:elements => ['a', 'p', 'b', 'i', 'blockquote'],
:attributes => {'a' => ['href']},
:allow_comments => false,
:transformers => lambda {|env|
env[:node].remove if env[:node].name == 'style' # fixes https://github.com/rgrove/sanitize/issues/17
{}
}
)
<<-HTML
<textarea name="dirty" style="width:100%;height:800px;">#{clean}</textarea>
HTML
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment