Skip to content

Commit 080bfab

Browse files
renatopento
authored andcommitted
FIX: paste mention from post to rich editor (#34184)
Prioritizes the mention `parseDOM` handler so it happens before the link mark parser, and makes sure to get the username from `textContent` when `data-name` isn't available.
1 parent 5970558 commit 080bfab

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/assets/javascripts/discourse/app/static/prosemirror/extensions/mention.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const extension = {
2424
selectable: false,
2525
parseDOM: [
2626
{
27+
priority: 60,
2728
tag: "a.mention",
2829
preserveWhitespace: "full",
2930
getAttrs: (dom) => {
3031
return {
31-
name: dom.getAttribute("data-name"),
32+
name: dom.getAttribute("data-name") ?? dom.textContent.slice(1),
3233
};
3334
},
3435
},

spec/system/composer/prosemirror_editor_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,21 @@ def body(title)
666666
end
667667

668668
describe "pasting content" do
669+
it "creates a mention when pasting an HTML anchor with class mention" do
670+
cdp.allow_clipboard
671+
open_composer
672+
673+
html = %(<a href="/u/#{current_user.username}" class="mention">@#{current_user.username}</a>)
674+
cdp.copy_paste(html, html: true)
675+
676+
expect(rich).to have_css("a.mention", text: current_user.username)
677+
expect(rich).to have_css("a.mention[data-name='#{current_user.username}']")
678+
expect(rich).to have_no_css("a.mention[href]")
679+
680+
composer.toggle_rich_editor
681+
expect(composer).to have_value("@#{current_user.username}")
682+
end
683+
669684
it "does not freeze the editor when pasting markdown code blocks without a language" do
670685
with_logs do |logger|
671686
open_composer

0 commit comments

Comments
 (0)