Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 == "&nbsp;" || 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