Skip to content

Commit

Permalink
Split sphinxHtmlToMarkdown into helper functions (#596)
Browse files Browse the repository at this point in the history
Part of #223. There are
still improvements we can make like better testing.

This PR tries to avoid making code changes and only moves the code to
helper functions.
  • Loading branch information
Eric-Arellano authored Jan 9, 2024
1 parent 68af1c9 commit b9b2e00
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 175 deletions.
18 changes: 13 additions & 5 deletions scripts/lib/sphinx/sphinxHtmlToMarkdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import { describe, test, expect } from "@jest/globals";
import { sphinxHtmlToMarkdown } from "./sphinxHtmlToMarkdown";

const DEFAULT_ARGS = {
imageDestination: "/images/qiskit",
baseSourceUrl: "https://github.com/Qiskit/qiskit-ibm-runtime/tree/0.9.2/",
releaseNotesTitle: "My Quantum release notes",
};

describe("sphinxHtmlToMarkdown", () => {
test("remove .html extension from relative links", async () => {
expect(
Expand Down Expand Up @@ -114,7 +120,7 @@ describe("sphinxHtmlToMarkdown", () => {
</div>
`,
url: "http://qiskit.org/docs/quantum-circuit.html",
imageDestination: "/images/qiskit",
...DEFAULT_ARGS,
}),
).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -506,7 +512,7 @@ Can be either (1) a dictionary mapping XX angle values to fidelity at that angle
</div>
`,
url: "https://qiskit.org/documentation/partners/qiskit_ibm_runtime/stubs/qiskit_ibm_runtime.Sampler.html",
baseSourceUrl: `https://github.com/Qiskit/qiskit-ibm-runtime/tree/0.9.2/`,
...DEFAULT_ARGS,
})
).markdown,
).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -1418,7 +1424,7 @@ compilation flow follows the structure given below:</p>
Most circuits must undergo a series of transformations that make them compatible with a given target device, and optimize them to reduce the effects of noise on the resulting outcomes. Rewriting quantum circuits to match hardware constraints and optimizing for performance can be far from trivial. The flow of logic in the rewriting tool chain need not be linear, and can often have iterative sub-loops, conditional branches, and other complex behaviors. That being said, the standard compilation flow follows the structure given below:
![../\\_images/transpiling\\_core\\_steps.png](/images/api//transpiling_core_steps.png)
![../\\_images/transpiling\\_core\\_steps.png](/images/qiskit/transpiling_core_steps.png)
Qiskit has four pre-built transpilation pipelines available here:
"
Expand All @@ -1443,13 +1449,13 @@ test("identify release notes", async () => {
</ul>
`,
url: "http://qiskit.org/docs/release_notes.html",
imageDestination: "/images/qiskit",
...DEFAULT_ARGS,
}),
).toMatchInlineSnapshot(`
{
"images": [],
"isReleaseNotes": true,
"markdown": "# Release Notes
"markdown": "# My Quantum release notes
<span id="release-notes-0-14-0" />
Expand Down Expand Up @@ -1528,6 +1534,7 @@ async function toMd(html: string) {
await sphinxHtmlToMarkdown({
url: "https://qiskit.org/documentation/partners/qiskit_ibm_runtime/stubs/qiskit_ibm_runtime.Sampler.html",
html,
...DEFAULT_ARGS,
})
).markdown;
}
Expand All @@ -1536,5 +1543,6 @@ async function toMdWithMeta(html: string) {
return await sphinxHtmlToMarkdown({
url: "https://qiskit.org/documentation/partners/qiskit_ibm_runtime/stubs/qiskit_ibm_runtime.Sampler.html",
html,
...DEFAULT_ARGS,
});
}
Loading

0 comments on commit b9b2e00

Please sign in to comment.