Link attributes are appearing/disappearing unexpectedly.
My goal is to have links open in a new window.
I have imported markdown-it-link-attributes and am successfully adding ‘target = “_blank”’ to links - see schema below.
<p>Click this link to <a href="http://www.google.com" title="google" target="_blank" rel="noopener">google</a> now.</p>
However, if I add another mark (such as bold) to the text BEFORE the link, the target and rel attributes disappear.
<p><span class="uw-editor-bold"> Click </span> this link to <a href="http://www.google.com" title="google">google</a> now.</p>
If I remove the bold mark then the link attributes reappear.
<p>Click this link to <a href="http://www.google.com" title="google" target="_blank" rel="noopener">google</a> now.</p>
If I put a bold mark AFTER the link, the attributes remain as one would expect.
<p>Click this link to <a href="http://www.google.com" title="google" target="_blank" rel="noopener">google</a> <span class="uw-editor-bold"> now </span>.</p>
Here is the link schema that I’ve defined
link: {
attrs: {
href: {},
title: {default: null},
target: {default: '_blank'},
rel: {default: 'noopener'}
},
inclusive: false,
parseDOM: [{tag: 'a[href]', getAttrs(dom: HTMLAnchorElement) {
return {
href: dom.getAttribute('href'),
title: dom.getAttribute('title'),
target: dom.getAttribute('target'),
rel: dom.getAttribute('rel')
};
}}],
toDOM(node) {
const {href, title, target, rel} = node.attrs;
return ['a', {href, title, target, rel}, 0];
}
}
Questions:
- Can anyone see what I’m doing wrong?
- Did I create my schema properly?
- Did I need to import the extra library in order to have markdown link attributes?
Thank you for any help.