TSK-1673 Fix missing mentions (#4340)

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-01-11 21:28:52 +07:00 committed by GitHub
parent 4b7ebd0bf4
commit 06f6f6a222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,26 +49,35 @@ export function extractReferences (content: ProseMirrorNode): Array<Reference> {
return result
}
export interface ReferenceOptions {
renderLabel: (props: { options: ReferenceOptions, node: any }) => string
suggestion: { char: string }
}
/**
* @public
*/
export const ReferenceNode = Node.create({
export const ReferenceNode = Node.create<ReferenceOptions>({
name: 'reference',
group: 'inline',
content: 'inline*',
inline: true,
addAttributes () {
return {
id: getDataAttribute('id'),
objectclass: getDataAttribute('objectclass'),
label: getDataAttribute('label'),
class: { default: null }
}
},
class: {
default: null
}
addOptions () {
return {
renderLabel ({ options, node }) {
// eslint-disable-next-line
return `${options.suggestion.char}${node.attrs.label ?? node.attrs.id}`
},
suggestion: { char: '@' }
}
},
@ -80,7 +89,22 @@ export const ReferenceNode = Node.create({
]
},
renderHTML ({ HTMLAttributes }) {
return ['span', mergeAttributes({ 'data-type': this.name }, HTMLAttributes), 0]
renderHTML ({ node, HTMLAttributes }) {
const options = this.options
return [
'span',
mergeAttributes(
{
'data-type': this.name
},
HTMLAttributes
),
this.options.renderLabel({ options, node })
]
},
renderText ({ node }) {
const options = this.options
return options.renderLabel({ options, node })
}
})