mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-07 07:10:10 +09:00
Replace Trix with Lexxy
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# The rich text editor produces formatting that Rails' default Action Text
|
||||
# sanitizer strips on render. The additions are declared once in
|
||||
# ContentFilters, shared by every sanitization layer.
|
||||
Rails.application.config.to_prepare do
|
||||
defaults = Class.new.include(ActionText::ContentHelper).new
|
||||
|
||||
ActionText::ContentHelper.allowed_tags =
|
||||
(ActionText::ContentHelper.allowed_tags || defaults.sanitizer_allowed_tags) | ContentFilters::EDITOR_FORMATTING_TAGS
|
||||
ActionText::ContentHelper.allowed_attributes =
|
||||
(ActionText::ContentHelper.allowed_attributes || defaults.sanitizer_allowed_attributes) | ContentFilters::EDITOR_FORMATTING_ATTRIBUTES
|
||||
end
|
||||
@@ -14,12 +14,32 @@ class ActionText::Attachment::OpengraphEmbed
|
||||
end
|
||||
|
||||
private
|
||||
# Trix serialized the embed's details as attributes of the
|
||||
# <action-text-attachment> node. Lexxy only serializes the sgid, content
|
||||
# and content-type, so newer attachments carry the details in their
|
||||
# content markup instead.
|
||||
def attributes_from_node(node)
|
||||
if node["href"].present?
|
||||
{
|
||||
href: web_url(node["href"]),
|
||||
url: web_url(node["url"]),
|
||||
filename: node["filename"],
|
||||
description: node["caption"]
|
||||
}
|
||||
else
|
||||
attributes_from_content(node["content"].to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def attributes_from_content(content)
|
||||
fragment = Nokogiri::HTML.fragment(content)
|
||||
link = fragment.at_css(".og-embed__title a")
|
||||
|
||||
{
|
||||
href: web_url(node["href"]),
|
||||
url: web_url(node["url"]),
|
||||
filename: node["filename"],
|
||||
description: node["caption"]
|
||||
href: web_url(link&.[]("href")),
|
||||
url: web_url(fragment.at_css(".og-embed__image img")&.[]("src")),
|
||||
filename: link&.text&.strip,
|
||||
description: fragment.at_css(".og-embed__description")&.text&.strip
|
||||
}
|
||||
end
|
||||
|
||||
@@ -79,8 +99,4 @@ class ActionText::Attachment::OpengraphEmbed
|
||||
def to_partial_path
|
||||
"action_text/attachables/opengraph_embed"
|
||||
end
|
||||
|
||||
def to_trix_content_attachment_partial_path
|
||||
"action_text/attachables/opengraph_embed"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user