Assume I have the mark type font in my schema, if I use toggleMark to toggle the font mark, I will have to provide all three attributes, and it will override all attributes if the marks already exist in the selection.
marks: {
font: {
attrs: {
fontFamily: { default: 'Helvetica, sans-serif' },
color: { default: 'black' },
fontSize: { default: '12pt' }
},
toDOM(node) {
return ['span', { style: `font-family: ${node.attrs.fontFamily}; font-size: ${node.attrs.fontSize}; color: ${node.attrs.color};` }, 0];
},
parseDOM: [
{
tag: 'span',
getAttrs(dom) {
return {
fontFamily: dom.style.fontFamily,
fontSize: dom.style.fontSize,
color: dom.style.color,
};
},
},
],
},
What I want is a way to just update the attributes that I want to update, for instance, if there’s a font mark in my current selection with attributes:
fontSize = '36pt', color = 'red', fontFamily = 'blahblah, sans-serif'
if I toggle it with font mark with color = ‘green’, that mark will be updated to
fontSize = '36pt', color = 'green', fontFamily = 'blahblah, sans-serif'
and the rest of the selection will be toggled with a mark with the given color attribute and attrubutes with default values
fontSize = '12pt', color = 'green', fontFamily = 'Helvetica, sans-serif'
I’ve browsed the forum and Googled it for few days, but didn’t see any issue related to this, so I’m here for some advice, thanks!
FYI, what I’m currently doing is have 3 different marks fontSize, fontFamily, fontColor, but it will be excellent if I can combine three of them with just font, which can make my template much cleaner.