mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
25 lines
514 B
Ruby
25 lines
514 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ContentScrubber < Rails::Html::PermitScrubber
|
|
ALLOWED_TAGS = ["p", "b", "strong", "em", "i", "a", "u", "img"].freeze
|
|
ALLOWED_ATTRIBUTES = ["href", "target", "src", "alt"].freeze
|
|
|
|
def initialize
|
|
super
|
|
self.tags = ALLOWED_TAGS
|
|
self.attributes = ALLOWED_ATTRIBUTES
|
|
end
|
|
|
|
def scrub(node)
|
|
if node.name == 'p' && (node.children.empty? || node.text.blank?)
|
|
node.remove
|
|
else
|
|
super
|
|
end
|
|
end
|
|
|
|
def skip_node?(node)
|
|
node.text?
|
|
end
|
|
end
|