-
-
Notifications
You must be signed in to change notification settings - Fork 195
Adding target="_blank" on anchor tags #667
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
base: main
Are you sure you want to change the base?
Conversation
|
: namedCodesToUnicode | ||
|
||
options.createElement = options.createElement || React.createElement | ||
options.targetBlank = options.targetBlank || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than a boolean for a single use case, a better option would be to provide a string, and the options
could specify a target window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I'd probably accomplish this is more like:
options={{overrides: {a: {props: {target: '_blank'}}}}}
key={state.key} | ||
href={options.sanitizer(node.target, 'a', 'href')} | ||
title={node.title} | ||
target={options.targetBlank ? '_blank' : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if targetBlank were a string | undefined, we wouldn't need to do checks here and just set target to options.target
IMO, this would be nice, but in many cases we need to override it anyway. Opening a new window is a common use case, but this can be handled pretty easily with overrides. This is what mine does, where openLink runs javascript to create a UI confirmation dialog about linking outside the current application:
|
First, thanks for your time on this project. It is the best markdown converter for React in my opinion due to its light weight.
I am not familiar with open source contributing and yarn, hopefully the PR still conveys the (simple) idea and code changes, even though contributing guidelines are not fully met.
The change allows for the ability to add the target="_blank" on anchor tags, and have them open in a new tag upon click. This makes the links a lot more usable in certain contexts, notably AI generated markdown with links.