diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index f979680399..f40b2f3cad 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -270,6 +270,13 @@ }); }; + const getMentionText = ({ node, suggestion }) => { + const id = node.attrs.id ?? ''; + const label = node.attrs.label ?? id; + const char = id.includes('|') ? '$' : (suggestion?.char ?? '@'); + return `${char}${label}`; + }; + export let onSelectionUpdate = (e) => {}; export let id = ''; @@ -455,9 +462,6 @@ if (text === '') { editor.commands.clearContent(); } else { - // Regex to find serialized mention tags: <@id>, <#id>, <$id|label> - const mentionReG = /<([@#$])([\w.\-:/]+)(?:\|([^>]*))?>/g; - // Convert each line to a

, replacing mention tags with proper // TipTap mention spans that the editor's DOMParser will recognise. const lines = text.split('\n'); @@ -470,10 +474,14 @@ const escaped = line.replace(/&/g, '&').replace(//g, '>'); // Now replace the escaped mention patterns back into real spans const withMentions = escaped.replace( - /<([@#$])([\w.\-:/]+)(?:\|([^&]*?))?>/g, - (_, ch, id, label) => { - const display = label?.length ? label : id; - return `${ch}${display}`; + /<([@#$])([\w.\-:/]+)(?:\|([^&]*?))?>|<\/([\w.\-:/]+)\|([^&]*?)>/g, + (_, ch, id, label, slashSkillId, slashSkillLabel) => { + const mentionChar = ch || '$'; + const mentionId = id || slashSkillId; + const display = (label || slashSkillLabel)?.length + ? label || slashSkillLabel + : mentionId; + return `${mentionChar}${display}`; } ); return `

${withMentions}

`; @@ -782,6 +790,12 @@ ? [ Mention.configure({ HTMLAttributes: { class: 'mention' }, + renderText: getMentionText, + renderHTML: ({ options, node, suggestion }) => [ + 'span', + options.HTMLAttributes, + getMentionText({ node, suggestion }) + ], suggestions: suggestions }) ]