Given the following update to the link mark (and the appropriate update to the prompt in the editor), what I’m finding is that if the user does not fill in the target
field, I get a target
attribute on the HTML anchor tag with no value (not an empty string–an attribute name with no equals or value).
How do I ensure that if there is no value for an optional field/attribute that the attribute is not output to the HTML?
marks = marks.update('link', {
attrs: {
href: {},
target: { default: null }
},
inclusive: false,
parseDOM: [{tag: 'a[href]', getAttrs(dom) {
return {href: dom.getAttribute('href'), target: dom.getAttribute('target')};
}}],
toDOM(node: NodeSpec) { const {href, target} = node.attrs; return ['a', {href, target}, 0]; }
},);
Example output:
<a href="https://duckduckgo.com" target>Some link text here</a>