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

remove matplotlib figure captions #848

Merged
merged 10 commits into from
Feb 20, 2024
93 changes: 93 additions & 0 deletions scripts/lib/api/processHtml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
removeDownloadSourceCode,
removePermalinks,
removeColonSpans,
removeMatplotlibFigCaptions,
replaceViewcodeLinksWithGitHub,
convertRubricsToHeaders,
prepareGitHubLink,
Expand Down Expand Up @@ -191,6 +192,98 @@ test("removeColonSpans()", () => {
doc.expectHtml(`<dt class="field-odd">Parameters</dt>`);
});

test("removeMatplotlibFigCaptions()", () => {
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
const doc = Doc.load(`
<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>
`);
removeMatplotlibFigCaptions(doc.$main);
doc.expectHtml(`
<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>
`);
});

test("removeMatplotlibFigCaptionsOnlyInMatches()", () => {
const doc = Doc.load(`
<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" 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" 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" 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>
`);
removeMatplotlibFigCaptions(doc.$main);
doc.expectHtml(`
<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" 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" 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" 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>
`);
});

test("addLanguageClassToCodeBlocks()", () => {
const doc1 = Doc.load(`<p><strong>Circuit symbol:</strong></p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span> ┌──────────┐
Expand Down
7 changes: 7 additions & 0 deletions scripts/lib/api/processHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ export function removePermalinks($main: Cheerio<any>): void {
}
}

export function removeMatplotlibFigCaptions($main: Cheerio<any>): void {
kevinsung marked this conversation as resolved.
Show resolved Hide resolved
$main
.find("figcaption")
.has("span.caption-text a.download.internal.reference")
.remove();
}

export function removeDownloadSourceCode($main: Cheerio<any>): void {
$main.find("p > a.reference.download.internal").closest("p").remove();
}
Expand Down
Loading