Skip to content

sphinx replacements render wrong inside button-ref (but not button-link) #66

Closed as not planned

Description

@drammock

Describe the bug

context
If I put a rST substitution (like |wrench|) that expands to raw HTML into the content of a button-ref directive, it gets mis-rendered as a textual version of the HTML (see screenshot below). This doesn't happen for button-link directive.

expectation
I expected button-ref and button-link to behave the same in this regard.

bug
Screenshot 2022-05-25 at 16-17-02 Installing MNE-Python — MNE 1 1 dev0 documentation

problem
This is a problem for people using rST substitutions as shorthand for, e.g., inline icons. I know that sphinx-design provides some support for octicon, font-awesome, etc, but the same thing happens to those! E.g., putting an octicon into the button text of a button-ref yields this:

Screenshot 2022-05-25 at 16-25-24 Installing MNE-Python — MNE 1 1 dev0 documentation

Reproduce the bug

.. |wrench| raw:: html

    <i class="fas fa-wrench"></i>

.. grid:: 3

    .. grid-item-card::

        .. button-link:: https://example.com/

            |wrench| works with button-link


    .. grid-item-card::

        .. button-ref:: name-of-target-anchor
            :ref-type: ref

            |wrench| fails with button-ref

    .. grid-item-card::

        .. button-ref:: name-of-target-anchor
            :ref-type: ref

            :octicon:`download` Fails with octicons in button-ref too

Screenshot 2022-05-25 at 16-34-10 Installing MNE-Python — MNE 1 1 dev0 documentation

List your environment

I'm using sphinx-design via pydata-sphinx-theme, not jupyter-book:

$ mamba list sphinx
jupyter_sphinx            0.3.2           py310hff52083_0    conda-forge
pydata-sphinx-theme       0.8.1                    pypi_0    pypi
sphinx                    4.5.0              pyh6c4a22f_0    conda-forge
sphinx-autobuild          2021.3.14          pyhd8ed1ab_0    conda-forge
sphinx-copybutton         0.5.0                    pypi_0    pypi
sphinx-design             0.1.0              pyhd8ed1ab_0    conda-forge
sphinx-gallery            0.11.0.dev0               dev_0    <develop>
sphinx-sitemap            2.2.0              pyhd8ed1ab_0    conda-forge
sphinx-theme-builder      0.2.0a14           pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-bibtex      2.4.2              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge
sphinxext-rediraffe       0.2.7              pyhd8ed1ab_0    conda-forge

Activity

  1. added
    bug
    on May 25, 2022
  2. welcome commented on May 25, 2022

    @welcome

    Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

    If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

    If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

    Welcome to the EBP community! 🎉

  3. OriolAbril commented on Aug 10, 2022

    @OriolAbril
    Contributor

    Not sure if this is an option for you, but this can be fixed if using myst-parser by changing the ref-type to myst. I don't know how the internals work, and I am also not sure if this might be a "wontfix" type of issue.

    The "workaround" is documented in https://sphinx-design.readthedocs.io/en/sbt-theme/badges_buttons.html#buttons:

    Note that by default sphinx converts the content of references to raw text. For example **Bold text** with ref-type set to ref will be rendered without bold:

    However, if using myst-parser, you can set the ref-type to myst, and the content will be properly rendered:

  4. drammock commented on Aug 10, 2022

    @drammock
    Author

    thanks for pointing out that this is a documented limitation, somehow I missed that (or didn't make the connection that the raw-text problem was the same problem as what I've reported here).

    The workaround is probably a non-starter; translating whole pages of our docs from rST to Myst just to get an icon to display on a button --- I doubt any of our devs will consider that a worthwhile use of their time.

    The docs you quoted say that by default sphinx converts the content of references to raw text... could we do something non-default here? Can you point me to where in sphinx-design (or sphinx) I should look to try to fix this myself?

  5. chrisjsewell commented on Aug 10, 2022

    @chrisjsewell
    Member

    Well you can see my rejected feature request here 😢 sphinx-doc/sphinx#8068

  6. chrisjsewell commented on Aug 15, 2022

    @chrisjsewell
    Member

    Yeh I think supporting such a complex non-default behaviour here would not be feasible, so I am going to move this to won't fix. But I'm open to suggestions on simpler fixes 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions