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

🐛 Fix tab-item label with nested syntax #135

Merged
merged 10 commits into from
May 20, 2024

Conversation

Praecordi
Copy link
Contributor

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.

@welcome
Copy link

welcome bot commented Jul 21, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

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! 🎉

@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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

❗ 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.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chrisjsewell
Copy link
Member

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.

@Praecordi
Copy link
Contributor Author

Praecordi commented Jul 27, 2023

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
Copy link
Contributor Author

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
Copy link
Contributor Author

@chrisjsewell What do you think?

@codecov-commenter
Copy link

codecov-commenter commented May 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great cheers, finally got round to this, and added a test case 👍

@chrisjsewell chrisjsewell changed the title [FIX] tab-item label error 🐛 Fix tab-item label with nested syntax May 20, 2024
@chrisjsewell chrisjsewell merged commit be1b85d into executablebooks:main May 20, 2024
11 of 15 checks passed
Copy link

welcome bot commented May 20, 2024

Congrats on your first merged pull request in this project! 🎉
congrats

Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants