I am trying to add a plugin into CK Editor where I can alter the textContent of the mention to be the value of the attribute label.
function MENTION_ENGINE(
editor: Parameters<
// @ts-ignore
Parameters<typeof ClassicEditor.create>[1]["plugins"][number]
>[0]
) {
editor.conversion.for("upcast").elementToAttribute({
view: {
name: "span",
classes: "mention",
attributes: {}
},
model: {
key: "mention",
value: (viewItem) => {
console.log({ viewItem });
const mentionAttribute = editor.plugins
.get("Mention")
.toMentionAttribute(viewItem, {
// Add any other properties that you need.
});
return mentionAttribute;
}
},
converterPriority: "high"
});
editor.conversion.for("downcast").attributeToElement({
model: "mention",
view: function (modelAttributeValue, { writer }) {
if (!modelAttributeValue) {
return;
}
console.log({modelAttributeValue})
return writer.createAttributeElement(
"span",
{
class: "mention",
"data-mention": modelAttributeValue.id,
"data-jsonpath": modelAttributeValue.jsonpath,
"data-label": modelAttributeValue.label
},
{
priority: 20, // Mention's priority in relation to other attributes
id: modelAttributeValue.uid // Unique ID to prevent merging mentions
}
);
},
converterPriority: "high"
});
}
The upcast is model value function is also not running.
Expected the writer.createAttributeElement to return a HTML Element where I could just directly modify the textContent and set the label