mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-03 21:33:37 +09:00
Ensure backwards compatibility with Trix
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
class ContentFilters::RemoveSoloUnfurledLinkText < ActionText::Content::Filter
|
||||
TWITTER_DOMAINS = %w[ x.com twitter.com ]
|
||||
TWITTER_DOMAIN_MAPPING = { "x.com" => "twitter.com" }
|
||||
|
||||
def applicable?
|
||||
normalize_tweet_url(solo_unfurled_url) == normalize_tweet_url(content.to_plain_text)
|
||||
end
|
||||
@@ -12,9 +15,6 @@ class ContentFilters::RemoveSoloUnfurledLinkText < ActionText::Content::Filter
|
||||
end
|
||||
|
||||
private
|
||||
TWITTER_DOMAINS = %w[ x.com twitter.com ]
|
||||
TWITTER_DOMAIN_MAPPING = { "x.com" => "twitter.com" }
|
||||
|
||||
def solo_unfurled_url
|
||||
ActionText::Attachment::OpengraphEmbed.from_node(unfurled_links.first)&.href if unfurled_links.size == 1
|
||||
end
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
class ContentFilters::SanitizeTags < ActionText::Content::Filter
|
||||
ALLOWED_TAGS = %w[ a abbr acronym address b big blockquote br cite code dd del dfn div dl dt em h1 h2 h3 h4 h5 h6 hr i ins kbd li ol
|
||||
p pre samp small span strong sub sup time tt ul var ] + ContentFilters::EDITOR_FORMATTING_TAGS +
|
||||
[ ActionText::Attachment.tag_name, "figure", "figcaption" ]
|
||||
|
||||
def applicable?
|
||||
true
|
||||
end
|
||||
@@ -8,10 +12,6 @@ class ContentFilters::SanitizeTags < ActionText::Content::Filter
|
||||
end
|
||||
|
||||
private
|
||||
ALLOWED_TAGS = %w[ a abbr acronym address b big blockquote br cite code dd del dfn div dl dt em h1 h2 h3 h4 h5 h6 hr i ins kbd li ol
|
||||
p pre samp small span strong sub sup time tt ul var ] + ContentFilters::EDITOR_FORMATTING_TAGS +
|
||||
[ ActionText::Attachment.tag_name, "figure", "figcaption" ]
|
||||
|
||||
def not_allowed_tags_css_selector
|
||||
ALLOWED_TAGS.map { |tag| ":not(#{tag})" }.join("")
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
module RichTextHelper
|
||||
LEGACY_EMBED_SELECTOR = "action-text-attachment[content-type='#{ActionText::Attachment::OpengraphEmbed::OPENGRAPH_EMBED_CONTENT_TYPE}'][href]"
|
||||
|
||||
def rich_text_data_actions
|
||||
# submitByKeyboard runs in the capture phase so it can submit on Enter
|
||||
# before the editor turns the keystroke into a newline
|
||||
@@ -9,4 +11,17 @@ module RichTextHelper
|
||||
tag.lexxy_prompt trigger: "@", name: "mention", src: autocompletable_users_path(room_id: room.id),
|
||||
"remote-filtering": true, "empty-results": "No matches"
|
||||
end
|
||||
|
||||
# Trix-era opengraph embeds carry their details as node attributes, which
|
||||
# the editor doesn't round-trip. Rendering them into the content attribute
|
||||
# lets the editor preserve them like any embed it created itself.
|
||||
def editable_body(message)
|
||||
fragment = ActionText::Fragment.wrap(message.body.body_before_type_cast)
|
||||
|
||||
transformed = fragment.replace(LEGACY_EMBED_SELECTOR) do |node|
|
||||
node.tap { |n| n["content"] = render_action_text_attachment(ActionText::Attachment.from_node(n)) }
|
||||
end
|
||||
|
||||
ActionText::RichText.new(body: transformed.to_html)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user