Class: Journeybook::HtmlSanitizer

Inherits:
Object
  • Object
show all
Defined in:
app/services/journeybook/html_sanitizer.rb

Constant Summary collapse

ALLOWED_TAGS =
%w[
  a abbr article blockquote br button code dd div dl dt em figcaption figure form h1 h2 h3 h4 h5 h6 i
  hr iframe img input kbd label li ol p pre span strong table tbody td textarea th thead tr ul
  section
].freeze
ALLOWED_ATTRIBUTES =
%w[
  action allow allowfullscreen alt autocomplete class height href id loading method name placeholder referrerpolicy rel required rows src target title type value width
].freeze
ALLOWED_IFRAME_HOSTS =
%w[
  www.youtube.com youtube.com www.youtube-nocookie.com youtube-nocookie.com player.vimeo.com
].freeze

Instance Method Summary collapse

Instance Method Details

#sanitize(html) ⇒ String

Parameters:

  • html (String)

Returns:

  • (String)


19
20
21
# File 'app/services/journeybook/html_sanitizer.rb', line 19

def sanitize(html)
  remove_unsafe_iframes(sanitizer.sanitize(html.to_s, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES).to_s)
end