editor-js / paragraph

Paragraph Tool for Editor.js 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Link target _blank

jurrid opened this issue · comments

In the editor there is no option te set a inline link to target _blank. Is this something which is on the roadmap?

commented

This issue would better to transfer to the Editor.js Core repo

editorjs-hyperlink my package. Add url with target & rel attribute

editorjs-hyperlink my package. Add url with target & rel attribute

appreciate the great job and friendly support! thanks

editorjs-hyperlink my package. Add url with target & rel attribute

appreciate the great job and friendly support! thanks

Okey thank you

commented

editorjs-hyperlink my package. Add url with target & rel attribute

Good job @trinhtam. I have mention your package in awesome-editorjs list.

editorjs-hyperlink my package. Add url with target & rel attribute

Good job @trinhtam. I have mention your package in awesome-editorjs list.

Thank you very good

thank you @trinhtam !!!!

Any chance this could be implemented still?
While the editor-hyperlink package looks nice, I somehow doubt that non-techies know that target blank means open link in new tab.

hi, you should process paragraph data block in json before save to store
it works for me

const processAHref = (text = ''): string => {
  const el = document.createElement('div')
  el.innerHTML = text

  for (let i = 0; i < el.childNodes.length; i++) {
    const child = el.childNodes.item(i) as HTMLElement

    const nodeName = getNodeName(child)
    if (nodeName !== 'a') {
      continue
    }
    const att = child.getAttribute('target')
    if (att) {
      continue
    }

    child.setAttribute('target', '_blank')
  }

  return el.innerHTML
}
export const getNodeName = (el: HTMLElement): string => {
  return (el.nodeName || '').toLocaleLowerCase()
}

Slightly cleaner JS solution for modern browsers

export const blankTargetAllLinks = (body: string): string => {
  const html = document.createElement('div');
  html.innerHTML = body;
  const links = html.getElementsByTagName('a');
  for (let i = 0, len = links.length; i < len; i += 1) {
    links[i].target = '_blank';
    links[i].rel = 'noopener noreferrer';
  }
  return html.innerHTML;
};