sphinx-design icon indicating copy to clipboard operation
sphinx-design copied to clipboard

[FIX] tab-item label error

Open Praecordi opened this issue 2 years ago • 6 comments

I'm not used to submitting pull requests so please excuse me if I've made any mistakes.

For my project, I had created a custom role which changed the color of specific words. Using such words in tab labels was not possible. I noticed in the code that the regions which did not allow this were missing arguments in nodes.rubric and sd_tab_label, both of which are nodes.TextElement.

Praecordi avatar Jul 21 '23 05:07 Praecordi

Thanks for submitting your first pull request! You are awesome! :hugs:
If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.
Welcome to the EBP community! :tada:

welcome[bot] avatar Jul 21 '23 05:07 welcome[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (5ad542b) 89.97% compared to head (37a3104) 89.97%.

:exclamation: Current head 37a3104 differs from pull request most recent head 0dce35b. Consider uploading reports for the commit 0dce35b to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #135   +/-   ##
=======================================
  Coverage   89.97%   89.97%           
=======================================
  Files          11       11           
  Lines         948      948           
=======================================
  Hits          853      853           
  Misses         95       95           
Flag Coverage Δ
pytests 89.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 27 '23 12:07 codecov[bot]

Heya thanks for the PR, so your change relates to https://github.com/live-clones/docutils/blob/6de53a0de5415174d58e775110d89e13dd76fc83/docutils/docutils/nodes.py#L1129:

class Element:
    def __init__(self, rawsource='', text='', *children, **attributes):
        if text != '':
            textnode = Text(text)
            Element.__init__(self, rawsource, textnode, *children,
                             **attributes)
        else:
            Element.__init__(self, rawsource, *children, **attributes)

By adding the extra "", I don't see what this will change, since in both cases text == ""?

Do you have a "minimally reproducible example" of the problem? i.e. it would be ideal to be able to write (an initially failing) test for this issue, then add code that makes the test parse.

chrisjsewell avatar Jul 27 '23 12:07 chrisjsewell

Not necessarily. When we call tab_label = nodes.rubric(self.arguments[0], *textnodes, classes=["sd-tab-label"] + self.options.get("class-label", [])) (without the extra ""), it uses the first element of textnodes since the arbitrary argument is processed first, and then its first element is set as the positional argument text. Explicitly putting "" sets the text = "" by virtue of its position.

def test(rawsource = '', text = '', *children, **attributes):
    print("text", text)
    print(children)

lst = ["hello.1", "hello.2", "hello.3"]

test("", *lst)
'''
Outputs
text hello.1
('hello.2', 'hello.3')
'''
test("", "", *lst)
"""
Outputs
text 
('hello.1', 'hello.2', 'hello.3')
"""

Please let me know if this explanation is enough, or if you would still like me to provide minimally reproducible example of the initial issue.

Praecordi avatar Jul 27 '23 20:07 Praecordi

Due to a lack of reply, I thought I may as well provide an example. This is a snippet of rst which I use

.. role:: custom-role
.. default-role:: custom-role

Minimally Reproducible Example for Tab Error
--------------------------------------------

This snippet is placed in _static directory titled "custom-role.css" and the line :code:`html_css_files = ["custom-role.css"]` in the conf.py

.. code:: css

    .custom-role {
        color: red;
        font-style: italic;
    }

.. tab-set::
    
    .. tab-item:: :custom-role:`Tab 1`
    
        This tab is supposed to be colored red and italicized, similar to :custom-role:`this`.
        
    .. tab-item:: Tab 2
    
        This is not

To make the custom-role more noticeable I add a css snippet in the configuration file by the name of custom-role.css. I have the snippet in the rst above.

This is an image of the output before the fix: image

And this an image after: image

Let me know if this is okay for the test.

Praecordi avatar Sep 04 '23 10:09 Praecordi

@chrisjsewell What do you think?

Praecordi avatar May 05 '24 10:05 Praecordi

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.97%. Comparing base (89aaa26) to head (37a3104).

:exclamation: Current head 37a3104 differs from pull request most recent head 3914144

Please upload reports for the commit 3914144 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   89.15%   89.97%   +0.82%     
==========================================
  Files          11       11              
  Lines         959      948      -11     
==========================================
- Hits          855      853       -2     
+ Misses        104       95       -9     
Flag Coverage Δ
pytests 89.97% <ø> (+0.82%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 20 '24 22:05 codecov-commenter

Congrats on your first merged pull request in this project! :tada: congrats
Thank you for contributing, we are very proud of you! :heart:

welcome[bot] avatar May 20 '24 23:05 welcome[bot]