Sanitize content with a new TrixScrubber

specifically made for trix editor with its allowed tags
This commit is contained in:
Jean-Baptiste Bellet
2023-05-26 14:39:28 +02:00
parent f26ecdf4f9
commit 6b29f7e3c5
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
class TrixScrubber < Rails::Html::PermitScrubber
ALLOWED_TAGS = ["p", "b", "strong", "em", "i", "a", "u", "br", "del", "h1", "blockquote", "pre",
"ul", "ol", "li"].freeze
ALLOWED_ATTRIBUTES = ["href", "target", "src", "alt"].freeze
def initialize
super
self.tags = ALLOWED_TAGS
self.attributes = ALLOWED_ATTRIBUTES
end
end

View File

@@ -1,3 +1,3 @@
.content
.row
= @distributor.custom_tab.content.html_safe if @distributor.custom_tab&.content.present?
= sanitize(@distributor.custom_tab&.content, scrubber: TrixScrubber.new)