Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rich-text Insert Hyperlink no target option #477

Open
ayanmta opened this issue Jun 10, 2023 · 6 comments
Open

rich-text Insert Hyperlink no target option #477

ayanmta opened this issue Jun 10, 2023 · 6 comments

Comments

@ayanmta
Copy link

ayanmta commented Jun 10, 2023

Hi ,
when we specify the link via insert hyperlink on rich text option
it lacks the option to specify the target="_blank" or target="_self"
i this this could be a very useful feature to leverage

@ayanmta
Copy link
Author

ayanmta commented Jun 10, 2023

image
kindly find the image of current state which lacks the target option

@tinycoding5
Copy link

You can resolve this issue using render options.

const renderOptions = {
  renderNode: {
    [INLINES.HYPERLINK]: (node: Inline, children: React.ReactNode) => {
       return (
             <a href={node.data.uri}>{children}</a>
        )
    }
  }
}

@ayanmta
Copy link
Author

ayanmta commented Jun 13, 2023

@tinycoding5
but if have 5 hyperlinks in one rich text editor
i want two links to have target "_self " and others target "_blank"

this code you provided will apply for all links the same behaviour but i want a each link to be micro managed for target

@tinycoding5
Copy link

tinycoding5 commented Jun 13, 2023

In this case, you can create new contentful.
For example, the url contentful has the name, href, target short string properties.
After that, you can add this contentful as an EMBEDDED entry.
After that, in renderOption, you can add that.
After review the response, you can parse that in front end

@maximilliangeorge
Copy link

maximilliangeorge commented Jul 26, 2023

For anyone trying to do this using vanilla js and not react:

import { INLINES } from '@contentful/rich-text-types'

const renderOptions = {
      renderNode: {
        [INLINES.HYPERLINK]: (node: any, next: any) => {
           return `<a target="_blank" href=${ node.data.uri }>${ next(node.content) }</a>`
        }
    }
}

documentToHtmlString(json, renderOptions)

@MrX8503
Copy link

MrX8503 commented Nov 7, 2023

Would love to see this feature. It would allow authors to choose which links open in a new tab/window and improve UX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants