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.
92 93 94 |
# File 'lib/ab_admin/utils.rb', line 92 def initialize( = {}) @options = end |
Instance Method Details
#normalize_html(raw_html, options = {}) {|doc| ... } ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ab_admin/utils.rb', line 96 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 |