\\[\\begin{split}CCX q_0, q_1, q_2 =
- I \\otimes I \\otimes |0 \\rangle \\langle 0| + CX \\otimes |1 \\rangle \\langle 1| =
+ I \\otimes I \\otimes \vert 0 \\rangle \\langle 0\vert + CX \\otimes \vert 1 \\rangle \\langle 1\vert =
\\begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\\
@@ -1061,7 +1061,7 @@ bits.
).toMatchInlineSnapshot(`
"$$
\\begin{split}CCX q_0, q_1, q_2 =
- I \\otimes I \\otimes |0 \\rangle \\langle 0| + CX \\otimes |1 \\rangle \\langle 1| =
+ I \\otimes I \\otimes \vert 0 \\rangle \\langle 0\vert + CX \\otimes \vert 1 \\rangle \\langle 1\vert =
\\begin{pmatrix}
1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\\\
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\\\
@@ -1427,6 +1427,47 @@ test("test dt tag without id", async () => {
`);
});
+test("test replacement of the pipe character for `\vert` on math expressions", async () => {
+ expect(
+ await toMd(`
+
+
+ `),
+ ).toMatchInlineSnapshot(`
+ "## Methods
+
+ | | |
+ | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
+ | [](#text-with-pipe "text with pipe") | This is an example of using the \\| character outside of a math expression |
+ | [](#span-tag-math-expressions-with-pipe "(span tag) math expressions with pipe") | Example single pipe: $\\mathcal{Q}^k \\mathcal{A} \\vert 0\\rangle$. |
+ | [](#span-tag-math-expressions-with-double-pipe "(span tag) math expressions with double pipe") | Example double pipe: The length of the vector x is $\\|x\\|_2$. |
+
+ This is a math expression outside the table:
+
+ $$
+ \\mathcal{Q}^k \\mathcal{A} \\vert 0\\rangle
+ $$
+ "
+ `);
+});
+
async function toMd(html: string) {
return (
await sphinxHtmlToMarkdown({
diff --git a/scripts/lib/api/htmlToMd.ts b/scripts/lib/api/htmlToMd.ts
index 927c780645c..bdafac327c4 100644
--- a/scripts/lib/api/htmlToMd.ts
+++ b/scripts/lib/api/htmlToMd.ts
@@ -71,6 +71,9 @@ async function generateMarkdownFile(
const sufix = "\\)";
if (value.startsWith(prefix) && value.endsWith(sufix)) {
value = value.substring(prefix.length, value.length - sufix.length);
+ // We need to replace the single `|` characters for `\vert ` to avoid page crashes when
+ // they are used inside a table. For more information: https://github.com/Qiskit/documentation/issues/488
+ value = value.replace(/(?Methods
+This is a math expression outside the table:
\\[\\mathcal{Q}^k \\mathcal{A} |0\\rangle\\]
+