Class: Govspeak::HtmlSanitizer::TableCellTextAlignWhitelister

Inherits:
Object
  • Object
show all
Defined in:
lib/govspeak/html_sanitizer.rb

Instance Method Summary collapse

Instance Method Details

#call(sanitize_context) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/govspeak/html_sanitizer.rb', line 25

def call(sanitize_context)
  return unless ["td", "th"].include?(sanitize_context[:node_name])
  node = sanitize_context[:node]

  # Kramdown uses text-align to allow table cells to be aligned
  # http://kramdown.gettalong.org/quickref.html#tables
  if invalid_style_attribute?(node['style'])
    node.remove_attribute('style')
  end
end

#invalid_style_attribute?(style) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/govspeak/html_sanitizer.rb', line 36

def invalid_style_attribute?(style)
  style && !style.match(/^text-align:\s*(center|left|right)$/)
end