Skip to content

Instantly share code, notes, and snippets.

@jacqui
Forked from ashaw/dirtyword.rb
Created March 4, 2013 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqui/5086678 to your computer and use it in GitHub Desktop.
Save jacqui/5086678 to your computer and use it in GitHub Desktop.
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