Class: AbAdmin::Utils::Sanitizer
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/ab_admin/utils.rb
Constant Summary collapse
- CLEAN_HTML_COMMENTS_REGEXP =
/(<|<)\!--.*?--(>|>)/m
- CLEAN_LINE_BREAKS_REGEXP =
/[^>]\r\n/
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Sanitizer
constructor
A new instance of Sanitizer.
- #normalize_html(raw_html, options = {}) {|doc| ... } ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Sanitizer
Returns a new instance of Sanitizer.
100 101 102 |
# File 'lib/ab_admin/utils.rb', line 100 def initialize( = {}) @options = end |
Instance Method Details
#normalize_html(raw_html, options = {}) {|doc| ... } ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ab_admin/utils.rb', line 104 def normalize_html(raw_html, = {}) return '' if raw_html.blank? cleaned_html = raw_html.gsub(CLEAN_HTML_COMMENTS_REGEXP, '')#.gsub(CLEAN_LINE_BREAKS_REGEXP, '<br/>') html = sanitize(cleaned_html, || {}) doc = Nokogiri::HTML.fragment(html) #doc.xpath('comment()').each { |c| c.remove } yield doc if block_given? doc.search('div').each { |el| el.name = 'p' } doc.to_html end |