It's not a bug so I don't follow the issue template.
For the command AddLink, it currently only accepts two parameters - {url, linkText}, which is not enough for the link purpose.
I'm wondering if we can support two properties target and rel in that object, and add them when creating the link element. These both properties are usually used in the real world. A typical case is <a target="_blank" rel="noopener noreferrer">.
That must be useful if we can support it. Thanks.
This is a much needed feature.
I'd like to add that links aren't clickable on the editor view. That can be fixed by adding the contenteditable="false" to the links.
I ended up fixing this issue with a horrible hack that looks like this:
fixLinks() {
for (let i = 0; i < this.links.length; i++) {
let link = this.links[i];
if (!link.getAttribute('target')) {
link.setAttribute('target', '_blank');
}
if (!link.getAttribute('rel')) {
link.setAttribute('rel', 'noopener noreferrer');
}
// we don't need to add `contenteditable="false"` on the viewer mode
if (!this.get('viewer') && !link.getAttribute('contenteditable')) {
link.setAttribute('contenteditable', 'false');
}
}
}
where this.links is obtained by
let editorElement = document.getElementById(this.uniqueId);
this.links = editorElement.getElementsByTagName('a');
// this.links is a live collection, so no need to be constantly retrieving it
fixLinks is ran on all value updates (using the onchange action).
+1
It is available to add attribute at anchor element by using linkAttribute of option,
like this:
linkAttribute: {
target: '_blank',
contenteditable: 'false',
rel: 'noopener noreferrer'
}
this doesn't seem available in the viewer. can we get that option as well?
@gregroyal Oh, thank you. linkAttribute option do not work in viewer. This is bug. I will fix it.
@gregroyal I will resolve it at https://github.com/nhn/tui.editor/issues/527.
Awesome thank you!
Most helpful comment
It is available to add attribute at anchor element by using
linkAttributeof option,like this: