Skip to content

API generation should remove Matplotlib figure captions #732

@Eric-Arellano

Description

@Eric-Arellano

This RST results in this Sphinx-generated HTML:

Screenshot 2024-01-30 at 4 36 11 PM

Note the Fig 1 caption and how it has 3 links to download source files for the image:

Screenshot 2024-01-30 at 4 36 59 PM

This is how we render that RST in our platform after running the HTML through our pipeline:

Screenshot 2024-01-30 at 4 37 40 PM

The 3 URLs all are 404s. Instead, we should remove the caption entirely. The 3 URLs are not useful and we don't plan to support them—you can download the image directly. That would only leave the text Fig. 1, which we decided isn't a priority.

--

This impacts the Runtime 0.18 docs in #729, along with some historical docs if you run rg '_downloads' -l, e.g.:

![../\_images/qiskit-transpiler-passes-DynamicalDecoupling-1\_00.png](/images/api/qiskit/0.42/qiskit-transpiler-passes-DynamicalDecoupling-1_00.png)
Fig. 23 ([`png`](_downloads/dc45751fb822be8815f217a267bae356/qiskit-transpiler-passes-DynamicalDecoupling-1_00.png), [`hires.png`](_downloads/16422e7545ee14003706693459de64e2/qiskit-transpiler-passes-DynamicalDecoupling-1_00.hires.png), [`pdf`](_downloads/e872644fa4d73ec0d7933d354c8b5059/qiskit-transpiler-passes-DynamicalDecoupling-1_00.pdf))[](#id1 "Permalink to this image")
![../\_images/qiskit-transpiler-passes-DynamicalDecoupling-1\_01.png](/images/api/qiskit/0.42/qiskit-transpiler-passes-DynamicalDecoupling-1_01.png)
Fig. 24 ([`png`](_downloads/53fd5fc6bb784c9ab811978842d9b3d1/qiskit-transpiler-passes-DynamicalDecoupling-1_01.png), [`hires.png`](_downloads/26516316e2c0c58fddd6ab262df0a289/qiskit-transpiler-passes-DynamicalDecoupling-1_01.hires.png), [`pdf`](_downloads/de66a83309cd3c854ee1dc534a5d465d/qiskit-transpiler-passes-DynamicalDecoupling-1_01.pdf))[](#id2 "Permalink to this image")

--

Example HTML from Sphinx for a single figure:

<figure class="align-default" id="id1">
    <img alt="../_images/fake_provider-1_00.png" class="plot-directive" src="../_images/fake_provider-1_00.png" />
    <figcaption>
        <p>
            <span class="caption-number">Fig. 1 </span>
            <span class="caption-text">
                (
                <a class="reference download internal" download="" href="../_downloads/a640acbc08577560dc62a3c02c6ca2ac/fake_provider-1_00.png">
                    <code class="xref download docutils literal notranslate"><span class="pre">png</span></code>
                </a>
                ,
                <a class="reference download internal" download="" href="../_downloads/98e08086a49350bea51e64248343d7ac/fake_provider-1_00.hires.png">
                    <code class="xref download docutils literal notranslate"><span class="pre">hires.png</span></code>
                </a>
                ,
                <a class="reference download internal" download="" href="../_downloads/684bf35d507376624fcead10d9aedaed/fake_provider-1_00.pdf">
                    <code class="xref download docutils literal notranslate"><span class="pre">pdf</span></code>
                </a>
                )
            </span>
            <a class="headerlink" href="#id1" title="Link to this image"></a>
        </p>
    </figcaption>
</figure>

We want to simplify the HTML via a new helper function in processHtml.ts. It should look like this:

<figure class="align-default" id="id1">
    <img alt="../_images/fake_provider-1_00.png" class="plot-directive" src="../_images/fake_provider-1_00.png">
</figure>

The function needs to use https://cheerio.js.org to remove the <figcaption> but if it matches this selector: figcaption span.caption-text a.download.internal.reference. We don't want to remove any generic figcaption.

We should this in processHtml.test.ts, including that we don't remove generic figcaptions.

The final step is to run npm run regen-apis.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions