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

Support adding a target to a link (to open in new tab) #12477

Closed
dylanh724 opened this issue Jun 25, 2024 · 9 comments
Closed

Support adding a target to a link (to open in new tab) #12477

dylanh724 opened this issue Jun 25, 2024 · 9 comments
Labels
type:proposal a feature suggestion

Comments

@dylanh724
Copy link

dylanh724 commented Jun 25, 2024

Is your feature request related to a problem? Please describe.

In 1997, HTML 4.0 first introduced external links

In 2024, you generally don't need to deep Google just to see if they support external links, a feature as old as the internet. This seems to possibly be the only web project that has no native external link support: I believe it's time.

Describe the solution you'd like

Please include native support for external links opposed to dirty js workarounds.

Describe alternatives you've considered

Creating a custom .js file.

@dylanh724 dylanh724 added the type:proposal a feature suggestion label Jun 25, 2024
@chrisjsewell
Copy link
Member

Heya, I'm afraid you are going to be more specific here:
what is the use-case, what exactly is it that you want to achieve?

@chrisjsewell chrisjsewell added the awaiting:response Waiting for a response from the author of this issue label Jun 25, 2024
@dylanh724
Copy link
Author

dylanh724 commented Jun 25, 2024

Heya, I'm afraid you are going to be more specific here:
what is the use-case, what exactly is it that you want to achieve?

Currently, all links are internal from the same browser tab. The feature request is for an equivalent of html link target="_new" (new tab).

@electric-coder
Copy link

The feature request is for an equivalent of html link target="_new" (new tab).

This is one of those cases where browser tech with right+click "open in new tab" ends up giving almost the same result.

This seems to possibly be the only web project that has no native external link support: I believe it's time.

I suppose it would be a pretty dope feature to have in Sphinx core. However, I don't know of another documentation generation tool that's open source, multi-language, tries to support the whole Python ecosystem, and has a ton of free features like search, automatic index, i18n , etc... And actually works as well as Sphinx does.

This leads me to think that the builtin nicety that's "open link in new tab" was never considered a priority by the community because simple workarounds are available, but pretty much every other feature/fix in Sphinx would leave devs without viable alternatives elsewhere.

Did someone in the ecosystem write a custom extension that allows this? Is there some previous work somewhere?

@chrisjsewell
Copy link
Member

chrisjsewell commented Jun 25, 2024

Well, actually, I believe this is already in myst-parser 😉 executablebooks/MyST-Parser#857

and sphinx already supports having a target attribute on a reference node:

if 'target' in node:
atts['target'] = node['target']

(not a rel though I don't think 🤔)

So then, for reStructureText, it just depends how do you want to set target: I believe you could already add a Transfrom that adds it to all reference nodes if you want

@chrisjsewell chrisjsewell changed the title External link support Support adding a target to a link (to open in new tab) Jun 25, 2024
@electric-coder
Copy link

@chrisjsewell a couple of old SO threads Add open-in-new-tab links in Sphinx/reStructuredText and Open a link in a new window in reStructuredText which has an answer from SHIMIZUKAWA himself :) linking back to #1634

@jayaddison
Copy link
Contributor

@dylanh724 have you encountered https://github.com/ftnext/sphinx-new-tab-link ? I think it might do what you want here - it's an extension (available on PyPi) that processes hyperlinks in your project and adds target="_blank" (and also rel="noopener noreferer") to the external ones. I also notice in their bugtracker that there's a feature request to add custom HTML styling for those.

@dylanh724
Copy link
Author

dylanh724 commented Jun 25, 2024

@dylanh724 have you encountered https://github.com/ftnext/sphinx-new-tab-link ? I think it might do what you want here - it's an extension (available on PyPi) that processes hyperlinks in your project and adds target="_blank" (and also rel="noopener noreferer") to the external ones. I also notice in their bugtracker that there's a feature request to add custom HTML styling for those.

Great find! Thank you! It's up to you guys whether you want to keep this open or closed: Closed since I'm satisfied, or open if you wanted to absorb it into your main product (it still feels strange this isn't a native feat!). Cheers!

A real scenario of when you'd want to use this: We may have "Chat With Us Now!" -- You don't know if it's a Discord link or an in-app chat box, for example. You could look at the bottom-left url preview, but the average person just clicks before they think.

@jayaddison jayaddison removed awaiting:response Waiting for a response from the author of this issue labels Jun 25, 2024
@electric-coder
Copy link

(it still feels strange this isn't a native feat!)

It seems there are accessibility concerns over the feature, as one of the more experienced maintainers said here. (IOW it might work fine for the average user but would be problematic for folks using screen readers...)

In another point of view, accessibility guideline recommended that target attribute should not be used until user agents allow users to turn off spawned windows [1]_.

.. [1] http://www.w3.org/TR/2000/NOTE-WCAG10-TECHS-20001106/#gl-interim-accessibility

Noting the W3C recommendation against it, more specifically:

12.6 Page updates and new windows

10.1 Until user agents allow users to turn off spawned windows, do not cause pop-ups or other windows to appear and do not change the current window without informing the user. [Priority 2]

@jayaddison
Copy link
Contributor

Not planned as a feature for core sphinx, although as noted during discussion, there are extensions available that may be able to help on a per-project basis.

@jayaddison jayaddison closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

4 participants