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

inline classes: fix header hierarchy #1215

Closed
Tracked by #479
Eric-Arellano opened this issue Apr 19, 2024 · 0 comments · Fixed by #1283
Closed
Tracked by #479

inline classes: fix header hierarchy #1215

Eric-Arellano opened this issue Apr 19, 2024 · 0 comments · Fixed by #1283

Comments

@Eric-Arellano
Copy link
Collaborator

Part of #199.

Right now, we hardcode methods/attributes/exceptions to have an h3 header no matter what. For classes, we don't add any header. That does not work though when you for example a function documented on a module page inside an h3 section already.

Instead, the header should take into account the parent header. Top-level functions / classes / exceptions should be one heading level lower than the parent. If the parent is the h1, then classes/exceptions should probably be h2 and functions h3.

Methods and Attributes should have a lower heading level than their class. Right now, we add the Methods and Attributes headers. That would mean the class should be -1 from the parent header, Methods/Attributes headers should be -2, and Function/Attribute components should be -2. We might want to remove the Methods/Attributes headers for inline classes, though, to reduce the amount of heading levels.

@javabster javabster moved this to In Review in Docs Planning May 6, 2024
github-merge-queue bot pushed a commit that referenced this issue May 7, 2024
The PR adds a method to autogenerate the correct level for the headers
of the MDX components (Attribute, Function, and Class) and regenerates
the API docs.

### How to find the heading level

Before setting the header, the script looks for the level of the
previous header to determine which one corresponds to the component that
is being generated. The script looks at all the siblings of the
`Cheerio` element we use to define the component to find the previous
header that wasn't created by the script before. We need to skip the
generated headers to avoid the case where we have multiple
methods/attributes/classes at the same level which shouldn't be mixed
with the header of the previous level.

If there's no header found in the first step, it means that we are
dealing with a component inside of an inline class, and therefore, the
script searches for the last header that corresponds to an inline class
to determine the new level. This is true because when we are inside an
inline class, there are no headers that haven't been generated by the
script.

Notice that the script always sets the header of an inline class in the
parent level instead of creating another sibling, so we cannot search
for generated siblings' headers.

To distinguish between the headers of the different components, an
attribute called `data-header-type` is used. This attribute is useful in
the last search.

Closes #1215

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from In Review to Done in Docs Planning May 7, 2024
frankharkins pushed a commit to frankharkins/documentation that referenced this issue Jul 22, 2024
The PR adds a method to autogenerate the correct level for the headers
of the MDX components (Attribute, Function, and Class) and regenerates
the API docs.

### How to find the heading level

Before setting the header, the script looks for the level of the
previous header to determine which one corresponds to the component that
is being generated. The script looks at all the siblings of the
`Cheerio` element we use to define the component to find the previous
header that wasn't created by the script before. We need to skip the
generated headers to avoid the case where we have multiple
methods/attributes/classes at the same level which shouldn't be mixed
with the header of the previous level.

If there's no header found in the first step, it means that we are
dealing with a component inside of an inline class, and therefore, the
script searches for the last header that corresponds to an inline class
to determine the new level. This is true because when we are inside an
inline class, there are no headers that haven't been generated by the
script.

Notice that the script always sets the header of an inline class in the
parent level instead of creating another sibling, so we cannot search
for generated siblings' headers.

To distinguish between the headers of the different components, an
attribute called `data-header-type` is used. This attribute is useful in
the last search.

Closes Qiskit#1215

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
@javabster javabster removed this from Docs Planning Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants