aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/app/helpers/action_text/content_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actiontext/app/helpers/action_text/content_helper.rb')
-rw-r--r--actiontext/app/helpers/action_text/content_helper.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/actiontext/app/helpers/action_text/content_helper.rb b/actiontext/app/helpers/action_text/content_helper.rb
new file mode 100644
index 0000000000..b3335601f9
--- /dev/null
+++ b/actiontext/app/helpers/action_text/content_helper.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module ActionText
+ module ContentHelper
+ SANITIZER = Rails::Html::Sanitizer.white_list_sanitizer
+ ALLOWED_TAGS = SANITIZER.allowed_tags + [ ActionText::Attachment::TAG_NAME, "figure", "figcaption" ]
+ ALLOWED_ATTRIBUTES = SANITIZER.allowed_attributes + ActionText::Attachment::ATTRIBUTES
+
+ def render_action_text_content(content)
+ content = content.render_attachments do |attachment|
+ unless attachment.in?(content.gallery_attachments)
+ attachment.node.tap do |node|
+ node.inner_html = render(attachment, in_gallery: false).chomp
+ end
+ end
+ end
+
+ content = content.render_attachment_galleries do |attachment_gallery|
+ render(layout: attachment_gallery, object: attachment_gallery) do
+ attachment_gallery.attachments.map do |attachment|
+ attachment.node.inner_html = render(attachment, in_gallery: true).chomp
+ attachment.to_html
+ end.join("").html_safe
+ end.chomp
+ end
+
+ sanitize content.to_html, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES
+ end
+ end
+end