-
-
Save jacqui/5086678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'sanitize' | |
TO_REMOVE = ["", " ", " "] | |
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| | |
# fixes https://github.com/rgrove/sanitize/issues/17 | |
env[:node].remove if env[:node].name == 'style' | |
{} | |
}, | |
lambda {|env| | |
env[:node].remove if env[:node].content == " " || env[:node].content == "" || env[:node].content == " " | |
} | |
] | |
) | |
<<-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