editor-js / paragraph

Paragraph Tool for Editor.js 2.0
MIT License
41 stars 124 forks source link

Link target _blank #18

Closed jurrid closed 5 years ago

jurrid commented 5 years ago

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

neSpecc commented 5 years ago

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

trinhtam commented 3 years ago

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

mykhailo-monchak commented 3 years ago

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

appreciate the great job and friendly support! thanks

trinhtam commented 3 years ago

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

appreciate the great job and friendly support! thanks

Okey thank you

talyguryn commented 3 years ago

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

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

trinhtam commented 3 years ago

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

calrloco commented 3 years ago

thank you @trinhtam !!!!

philipaarseth commented 3 years ago

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.

or4 commented 1 year ago

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()
}
gilluminate commented 1 year ago

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;
};