-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Allow the target attribute on <a> tags. #8125
Conversation
@@ -18,7 +18,7 @@ const phrasingContentSchema = { | |||
em: {}, | |||
del: {}, | |||
ins: {}, | |||
a: { attributes: [ 'href' ] }, | |||
a: { attributes: [ 'href', 'target' ] }, |
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.
We don't have the UI to add other kinds of targets (aside _blank
). We also add rel="noreferrer noopener"
to these links. The question is: Should we allow only target="_blank"
and normalize the "rel" attribute in that case? or it's fine to just pick the target and keep the link as is?
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.
Those are good questions. Perhaps we should perform some normalization, as there is an expectation — given the precedents when pasting from word processors, etc. — that Gutenberg generally cleans up markup. I was looking at the raw-handling pipeline and am guessing that an acceptable place to normalize target
and rel
would be phrasing-content-reducer
, next to where special rules are applied to b
and i
tags:
gutenberg/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js
Lines 24 to 28 in 09db904
} else if ( node.nodeName === 'B' ) { | |
node = replaceTag( node, 'strong', doc ); | |
} else if ( node.nodeName === 'I' ) { | |
node = replaceTag( node, 'em', doc ); | |
} |
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.
Good idea, @mcsf, I added normalisation here.
Well as an accessibility person I'd very happy to see these links have also a visually hidden text |
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.
LGTM 👍
I would have liked to see this filter only on block conversion, not on paste. I'm not sure if the user intends these link to open in a new window if the source does. |
It might be a good idea to add some styling to links that are set to open in a new window, so the author can easily see which links are set to do that. |
Description
Sine we have UI for adding
target="_blank"
to<a>
elements, we should allow it to stay when converting existing posts to blocks.This PR partially address #4498.
How has this been tested?
Create a post in the Classic Editor with this content:
<a href="https://wordpress.org" target="_blank">Hi!</a>
Open the post in Gutenberg, and convert it to blocks.
Click on the link, check that the "Open in new window" setting is enabled.
Preview the post, check that clicking the link opens it in a new window.
Checklist: