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

add role for custom hyperlinks #340

Open
2bndy5 opened this issue Apr 12, 2024 · 1 comment
Open

add role for custom hyperlinks #340

2bndy5 opened this issue Apr 12, 2024 · 1 comment
Labels
enhancement New feature or request feat: upstream a feature that exists upstream but is not well supported in sphinx-immaterial

Comments

@2bndy5
Copy link
Collaborator

2bndy5 commented Apr 12, 2024

Currently, setting the docutils.nodes.refernce class' reftitle attribute can only be used via docutils API. Some extensions already use this attribute to add tooltips for hyperlinks, namely intersphinx and a bunch of extensions exclusive to this theme.

The rST specs do not allow doc authors to specify custom hyperlink tooltips. This is actually pretty standard in markdown:

[link text](https://example.com "tooltip text")

renders as link text

It shouldn't be too hard to implement this as a sphinx extension. I'm imagining a href role that behaves similarly to ref role with this added behavior.

proposed syntax

.. with link text
:href:`link text <link_url "tooltip text">`

.. without link text (where link_url becomes the link text)
:href:`<link_url "tooltip text">`

It would be nice to actually derive from the ref role and just add some extra content parsing where appropriate.


PS - marking this as a comparable upstream feature because mkdocs-material release "improved toolips" support in v9.5.0

@2bndy5 2bndy5 added enhancement New feature or request feat: upstream a feature that exists upstream but is not well supported in sphinx-immaterial labels Apr 12, 2024
@2bndy5
Copy link
Collaborator Author

2bndy5 commented Apr 13, 2024

I think it would also be cool if we could allow custom CSS class(es) to create buttons.

:href:`link text <link_url "tooltip text">;md-button`

Although, a case could be made that a derivative of our si-icon would be more useful to embed inline icons with text in a hyperlink. I'm not sure how this syntax would look since rST doesn't support nested syntax (& substitutions are limited in that roles cannot be used as substitutions' values). Maybe something like

:si-href:`link text {material/logo} <link_url "tooltip text">;custom-class`

Using rst-class treats a rogue hyperlink as a paragraph:

.. rst-class:: md-button md-button-primary

`Subscribe to our newsletter <#>`_

renders as the following HTML:

<p class="md-button md-button-primary">
  <a class="reference external" href="#">Subscribe to our newsletter</a>
</p>

@2bndy5 2bndy5 changed the title add role for custom tooltips in hyperlinks add role for custom hyperlinks Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat: upstream a feature that exists upstream but is not well supported in sphinx-immaterial
Projects
None yet
Development

No branches or pull requests

1 participant