mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-27 18:46:23 +09:00
6acad0549d
The editor keeps an attachment's content as it finds it, so a hand-written embed with a url but no href reached the editor with its markup unvalidated, and a mention saved under Trix's editor carried the generic octet-stream content type the editor doesn't permit and was dropped on save. Rebuilding each attachment from its attachable renders the hardened preview partial and restores the mention content type.
34 lines
1.3 KiB
Ruby
34 lines
1.3 KiB
Ruby
module RichTextHelper
|
|
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
|
|
"lexxy:change->typing-notifications#start keydown->composer#submitByKeyboard:capture"
|
|
end
|
|
|
|
def mention_prompt_tag(room)
|
|
tag.lexxy_prompt trigger: "@", name: "mention", src: autocompletable_users_path(room_id: room.id),
|
|
"remote-filtering": true, "empty-results": "No matches"
|
|
end
|
|
|
|
# The editor keeps an attachment's content as it finds it, so every
|
|
# attachment is rebuilt from its attachable before editing: a Trix-era
|
|
# embed carries its details as node attributes the editor doesn't
|
|
# round-trip, a mention edited under Trix carries the generic content type
|
|
# the editor doesn't permit, and a hand-written embed carries whatever
|
|
# markup the author put there.
|
|
def editable_body(message)
|
|
fragment = ActionText::Fragment.wrap(message.body.body_before_type_cast)
|
|
|
|
transformed = fragment.replace(ActionText::Attachment.tag_name) do |node|
|
|
attachment = ActionText::Attachment.from_node(node)
|
|
|
|
node.tap do |n|
|
|
n["content-type"] = attachment.attachable.attachable_content_type
|
|
n["content"] = render_action_text_attachment(attachment)
|
|
end
|
|
end
|
|
|
|
ActionText::RichText.new(body: transformed.to_html)
|
|
end
|
|
end
|