Created
April 23, 2014 07:58
-
-
Save sjaveed/11206222 to your computer and use it in GitHub Desktop.
This file contains 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
# Setup HTML::WhiteListSanitizer | |
ActionView::Base.sanitized_allowed_attributes.add('style') | |
%w/margin padding padding-left padding-right padding-top padding-bottom list-style/.each do |prop| | |
ActionView::Base.sanitized_allowed_css_properties.add(prop) | |
end | |
original_string = %Q|<h1 style="color: #333 !important; font-family: arial !important; font-size: 45px !important; font-style: normal !important; font-weight: normal !important; margin: 0 0 10px 0 !important; line-height:-0.5px !important;">Test heading;<a href="https://www.google.com" style="color: #F3724E !important; font-family: arial !important; text-decoration: none !important;"> link text</a> : </h1>| | |
sanitized_string = ActionView::Base.white_list_sanitizer.sanitize(original_string) | |
# sanitized_string strips out all the css tags from within the h1. Why? All the properties specified | |
# in the h1 tag's style attribute are marked as allowed. At the very least the color should've shown | |
# Turns out it doesn't like getting a negative line-height property |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment