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 header hierarchy for the API docs #1283

Merged
merged 44 commits into from
May 7, 2024

Conversation

arnaucasau
Copy link
Collaborator

@arnaucasau arnaucasau commented May 2, 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

@arnaucasau arnaucasau changed the title [WIP] Fix header hierarchy Fix header hierarchy for the API docs May 3, 2024
@arnaucasau arnaucasau marked this pull request as ready for review May 3, 2024 17:51
@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌

docs/api/qiskit/0.19/logging.mdx Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/generateApiComponents.ts Outdated Show resolved Hide resolved
scripts/lib/api/htmlToMd.test.ts Outdated Show resolved Hide resolved
arnaucasau and others added 3 commits May 6, 2024 22:13
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

🚀

@arnaucasau arnaucasau added this pull request to the merge queue May 7, 2024
Merged via the queue into Qiskit:main with commit 1da5a40 May 7, 2024
5 checks passed
@arnaucasau arnaucasau deleted the AC/header-levels branch May 7, 2024 12:52
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2024
This PR adds the header of a class that was missing its id. The id was
manually fixed in Box by modifying the HTML, and this is the
regeneration as a follow-up of #1283
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2024
This PR refactors the dispatch table used to prepare the props of each
API component in order to simplify the `generateApiComponents.ts`
script. The functions for "functions" and "methods" cannot be merged
trivially because they check in different ways the `isDedicatedPage`
prop. Using the same method for that gives us false positives on pages
like [this](https://docs.quantum.ibm.com/api/qiskit/0.36/execute).
Moreover, functions don't need any header in those cases.

Thanks @Eric-Arellano for the idea on #1283

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Eric-Arellano pushed a commit that referenced this pull request May 7, 2024
This PR adds the header of a class that was missing its id. The id was
manually fixed in Box by modifying the HTML, and this is the
regeneration as a follow-up of #1283
Eric-Arellano added a commit that referenced this pull request May 7, 2024
This PR refactors the dispatch table used to prepare the props of each
API component in order to simplify the `generateApiComponents.ts`
script. The functions for "functions" and "methods" cannot be merged
trivially because they check in different ways the `isDedicatedPage`
prop. Using the same method for that gives us false positives on pages
like [this](https://docs.quantum.ibm.com/api/qiskit/0.36/execute).
Moreover, functions don't need any header in those cases.

Thanks @Eric-Arellano for the idea on #1283

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request 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>
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
This PR adds the header of a class that was missing its id. The id was
manually fixed in Box by modifying the HTML, and this is the
regeneration as a follow-up of Qiskit#1283
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
This PR refactors the dispatch table used to prepare the props of each
API component in order to simplify the `generateApiComponents.ts`
script. The functions for "functions" and "methods" cannot be merged
trivially because they check in different ways the `isDedicatedPage`
prop. Using the same method for that gives us false positives on pages
like [this](https://docs.quantum.ibm.com/api/qiskit/0.36/execute).
Moreover, functions don't need any header in those cases.

Thanks @Eric-Arellano for the idea on Qiskit#1283

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

inline classes: fix header hierarchy
3 participants