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

tippy-header class only added to the first header in tip excerpt #24

Open
NamelessIV opened this issue Sep 13, 2024 · 0 comments
Open

Comments

@NamelessIV
Copy link

We want to change the font size of the different headers in the tips but only the first header of the excerpt has the tippy-header class added to it.

The cause appears to be in the _get_header_html() function line 470

                output += _get_header_html(sub_header, False)

In its context:

def _get_header_html(header: Tag | NavigableString, _start: bool = True) -> str:
    """Get the HTML for a header tag, including itself and some following content."""
    if not _start or not isinstance(header, Tag):
        output = str(header)
    else:
        header_copy = header.__copy__()
        header_copy["style"] = "margin-top: 0;"
        # add a class
        if "class" in header_copy.attrs:
            header_copy["class"].append("tippy-header")  # type: ignore[union-attr]
        else:
            header_copy["class"] = ["tippy-header"]
        output = str(header_copy)
    for sibling in header.next_siblings:
        if not isinstance(sibling, Tag):
            continue
        if sibling.name == "section":
            if sub_header := sibling.find(["h1", "h2", "h3", "h4", "h5", "h6"]):
                output += _get_header_html(sub_header, False)
            break
        if sibling.name == "p":
            output += str(sibling)
            if (next_sibling := next_sibling_tag(sibling)) and next_sibling.name == "p":
                output += str(next_sibling)
            break
    return output

If the False is replaced by True the tippy-header class is added to each header level.

Line 470 becomes:

                output += _get_header_html(sub_header, True)

Where in the source file: https://github.com/sphinx-extensions2/sphinx-tippy/blob/17770ce8f641b844f83d09624a388cdfca374531/src/sphinx_tippy.py#L452C5-L477C21

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

No branches or pull requests

1 participant