Module: Fustrate::Rails::Concerns::SanitizeHtml

Extended by:
ActiveSupport::Concern
Defined in:
lib/fustrate/rails/concerns/sanitize_html.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.normalize(html) ⇒ Object

Remove non-breaking & ideographic spaces before sanitizing, and un-fancy quotes.



15
# File 'lib/fustrate/rails/concerns/sanitize_html.rb', line 15

def self.normalize(html) = html.tr('‘’“”', %q(''"")).gsub(/(?:[\u00A0\u3000]| ) ?/, ' ')

.sanitize(html, config) ⇒ Object



12
# File 'lib/fustrate/rails/concerns/sanitize_html.rb', line 12

def self.sanitize(html, config) = smart_strip ::Sanitize.fragment(normalize(html), config)

.smart_strip(html) ⇒ Object

There shouldn’t be whitespace or newlines at the beginning or end of the text



18
# File 'lib/fustrate/rails/concerns/sanitize_html.rb', line 18

def self.smart_strip(html) = html.gsub(/\A(?:[[:space:]]|<br>)+|(?:[[:space:]]|<br>)+\z/, '')