Tui.editor: (Feature Request): add properties 'target' and 'rel' for link element 'a'

Created on 31 Aug 2018  ·  7Comments  ·  Source: nhn/tui.editor

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.

Feature P 1

Most helpful comment

It is available to add attribute at anchor element by using linkAttribute of option,
like this:

        linkAttribute: {
          target: '_blank',
          contenteditable: 'false',
          rel: 'noopener noreferrer'
        }

All 7 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igasparetto picture igasparetto  ·  4Comments

dioscuroi picture dioscuroi  ·  3Comments

Yeongjae-Shin picture Yeongjae-Shin  ·  3Comments

nilhave picture nilhave  ·  3Comments

koliyo picture koliyo  ·  4Comments