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

Improve function handling #683

Merged
merged 12 commits into from
Jan 25, 2024
Merged

Improve function handling #683

merged 12 commits into from
Jan 25, 2024

Conversation

frankharkins
Copy link
Member

This PR improves how the API generation script handles functions.

Changes

Demote some h2 tags to strong

We currently convert all .rubric elements to h2, but this makes some headings higher-level than they should be (specifically "Example" and "References" headings). For an example see api/qiskit/converters.

Screenshot 2024-01-23 at 17 37 33

This PR converts rubrics to strong (rather than h2) if the name is "Example(s)" or "Reference(s)". This is a bit hacky, but it seems to work and I can't think of a better way of doing it. The Sphinx LaTeX writer also takes a similar approach.

I've regenerated the docs using this new logic and I can see no false positives (that is, cases in which we use strong where we should use h2).

Add function names as headings

Functions currently have no headings. This PR adds a h3 with the function name, which improves readability, gives anchor tag icons, and will add more functions to the right sidebar.

I've also included some logic to avoid adding function names when the page is already dedicated to the function (such as least_busy).

One quirk with this I spotted was some function names not appearing in the sidebar in /api/qiskit/utils (see add_deprecation_to_docstring in the screenshot). This is possibly because the title hierarchy skips h2.

Screenshot 2024-01-23 at 18 00 37


Closes #231

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.

This looks great - excellent improvement! Please do not merge until we've finished regenerating all historical API docs with prior queued changes.

scripts/lib/api/processHtml.ts Outdated Show resolved Hide resolved
scripts/lib/api/processHtml.ts Show resolved Hide resolved
scripts/lib/api/processHtml.ts Show resolved Hide resolved
scripts/lib/api/processHtml.ts Show resolved Hide resolved
frankharkins and others added 3 commits January 24, 2024 10:06
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.

💜 This will be ready to merge once Arnau puts up the last PR for Qiskit 0.19.

doc.expectHtml(`<strong>Example</strong>
<strong>Examples</strong>
<strong>References</strong>
<h2>Reference</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be <strong> because it's "member-specific", similar to an example. Rather than signifying the start of a new section with its own "code members", this is only added info about the current member.

scripts/lib/api/processHtml.test.ts Outdated Show resolved Hide resolved
scripts/lib/api/processHtml.test.ts Show resolved Hide resolved
scripts/lib/api/processHtml.test.ts Outdated Show resolved Hide resolved
@arnaucasau
Copy link
Collaborator

All Qiskit versions have been regenerated so this can be merged when you both think it's ready 👍. Thank you so much @frankharkins for waiting!

@Eric-Arellano
Copy link
Collaborator

You'll need to regenerate the Qiskit 0.45 docs. You can run this:

npm run gen-api -- -p qiskit -v 0.45.2 -a https://github.com/Qiskit/qiskit/actions/runs/7626116665/artifacts/1188676326

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.

🚀 Arnau is working on automating regeneration of historical API docs. So he can help with applying this fix to the historical docs.

Great job with this! Huge improvement.

@frankharkins frankharkins added this pull request to the merge queue Jan 25, 2024
Merged via the queue into main with commit 8208fe2 Jan 25, 2024
5 checks passed
@frankharkins frankharkins deleted the FH/api-functions branch January 25, 2024 13:25
github-merge-queue bot pushed a commit that referenced this pull request Jan 25, 2024
- Restore `_package.json` that was accidentally deleted in #683
frankharkins added a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
This PR improves how the API generation script handles functions.

## Changes

### Demote some `h2` tags to `strong`

We currently convert all `.rubric` elements to `h2`, but this makes some
headings higher-level than they should be (specifically "Example" and
"References" headings). For an example see
[api/qiskit/converters](https://docs.quantum.ibm.com/api/qiskit/converters).

<img width="197" alt="Screenshot 2024-01-23 at 17 37 33"
src="https://github.com/Qiskit/documentation/assets/36071638/618a256b-9bdf-481b-bb49-e3eea7476b8e">

This PR converts rubrics to `strong` (rather than `h2`) if the name is
"Example(s)" or "Reference(s)". This is a bit hacky, but it seems to
work and I can't think of a better way of doing it. The Sphinx LaTeX
writer also takes a [similar
approach](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-rubric).

I've regenerated the docs using this new logic and I can see no false
positives (that is, cases in which we use `strong` where we should use
`h2`).


### Add function names as headings

Functions currently have no headings. This PR adds a `h3` with the
function name, which improves readability, gives anchor tag icons, and
will add more functions to the right sidebar.

I've also included some logic to avoid adding function names when the
page is already dedicated to the function (such as
[least_busy](https://docs.quantum.ibm.com/api/qiskit-ibm-provider/qiskit_ibm_provider.least_busy)).

One quirk with this I spotted was some function names not appearing in
the sidebar in `/api/qiskit/utils` (see `add_deprecation_to_docstring`
in the screenshot). This is possibly because the title hierarchy skips
`h2`.

![Screenshot 2024-01-23 at 18 00
37](https://github.com/Qiskit/documentation/assets/36071638/c189dfc1-3535-4e2e-9edb-889ba855ef10)

***

Closes Qiskit#231

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
frankharkins added a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
- Restore `_package.json` that was accidentally deleted in Qiskit#683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

API docs need to handle functions better
3 participants