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

Opening link in a new tab #65

Closed
ghost opened this issue Mar 21, 2017 · 7 comments
Closed

Opening link in a new tab #65

ghost opened this issue Mar 21, 2017 · 7 comments

Comments

@ghost
Copy link

ghost commented Mar 21, 2017

Is it possible to add target="blank" to Markdown links?

For example I wish to have the following URL open in a new browser tab when I left click:
[link to website](http://www.website.com)

Cheers

@rexxars
Copy link
Collaborator

rexxars commented Mar 21, 2017

You can use a custom renderer:

function LinkRenderer(props) {
  return <a href={props.href} target="_blank">{props.children}</a>
}

<ReactMarkdown
  source="Click [here](https://espen.codes/) to visit external site"
  renderers={{link: LinkRenderer}}
/>

@eseQ
Copy link

eseQ commented Dec 26, 2017

@rexxars renderers={{Link: LinkRenderer}} is incorrect, Link: => link: to lowercase =)
just for this issue`s other viewers

@abourget
Copy link

it works here with the capital L in Links:

@chenop
Copy link

chenop commented Feb 8, 2019

Can you please consider re-open this ticket in order to implementing support for opening a link in a new tab:
[link](url){:target="_blank"}

Is this feature make sense?
I'm willing to give it a try implementing this.

@joelbowen
Copy link

joelbowen commented Mar 15, 2021

For anyone else that ends up here via google search (like I did) and didn't notice this in the docs, you can now use the prop linkTarget to achieve this like so:

<ReactMarkdown linkTarget="_blank" children={...} />

See the docs for more info.

@huuphongsan
Copy link

For anyone else that ends up here via google search (like I did) and didn't notice this in the docs, you can now use the prop linkTarget to achieve this like so:

<ReactMarkdown linkTarget="_blank" children={...} />

See the docs for more info.

Does React Markdown automatically add rel=”noopener noreferrer” when using linkTarget="_blank" for secure?

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Aug 19, 2023

This answer is pretty outdated, and should no longer be used as a reference.
The current recommendation is to use https://github.com/rehypejs/rehype-external-links which can apply rel, but the recommendation may change in the future.

I'm locking this thread as outdated.
Feel free to take follow up questions to the discussion forum https://github.com/orgs/remarkjs/discussions

@remarkjs remarkjs locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

7 participants