import { describe, it, expect } from "vitest"; import { parseAdvancedmarkup } from "../../src/lib/utils/markup/advancedMarkupParser"; import { readFileSync } from "fs"; import { join } from "path"; describe("LaTeX and AsciiMath Rendering in Inline Code Blocks", () => { const jsonPath = join(__dirname, "../../test_data/LaTeXtestfile.json"); const raw = readFileSync(jsonPath, "utf-8"); // Extract the markdown content field from the JSON event const content = JSON.parse(raw).content; it('renders LaTeX inline and display math correctly', async () => { const html = await parseAdvancedmarkup(content); // Test basic LaTeX examples from the test document expect(html).toMatch(/\$\\sqrt\{x\}\$<\/span>/); expect(html).toMatch(/
\$\$\\sqrt\{x\}\$\$<\/div>/); expect(html).toMatch(/\$\\mathbb\{N\} = \\{ a \\in \\mathbb\{Z\} : a > 0 \\}\$<\/span>/); expect(html).toMatch(/
\$\$P \\left\( A=2 \\, \\middle\| \\, \\dfrac\{A\^2\}\{B\}>4 \\right\)\$\$<\/div>/); }); it('renders AsciiMath inline and display math correctly', async () => { const html = await parseAdvancedmarkup(content); // Test AsciiMath examples expect(html).toMatch(/\$E=mc\^2\$<\/span>/); expect(html).toMatch(/
\$\$sum_\(k=1\)\^n k = 1\+2\+ cdots \+n=\(n\(n\+1\)\)\/2\$\$<\/div>/); expect(html).toMatch(/
\$\$int_0\^1 x\^2 dx\$\$<\/div>/); }); it('renders LaTeX array and matrix environments as math', async () => { const html = await parseAdvancedmarkup(content); // Test array and matrix environments expect(html).toMatch(/
\$\$[\s\S]*\\begin\{array\}\{ccccc\}[\s\S]*\\end\{array\}[\s\S]*\$\$<\/div>/); expect(html).toMatch(/
\$\$[\s\S]*\\begin\{bmatrix\}[\s\S]*\\end\{bmatrix\}[\s\S]*\$\$<\/div>/); }); it('handles unsupported LaTeX environments gracefully', async () => { const html = await parseAdvancedmarkup(content); // Should show a message and plaintext for tabular expect(html).toMatch(/
/); expect(html).toMatch(/Unrendered, as it is LaTeX typesetting, not a formula:/); expect(html).toMatch(/\\\\begin\{tabular\}/); }); it('renders mixed LaTeX and AsciiMath correctly', async () => { const html = await parseAdvancedmarkup(content); // Test mixed content expect(html).toMatch(/\$\\frac\{1\}\{2\}\$<\/span>/); expect(html).toMatch(/\$1\/2\$<\/span>/); expect(html).toMatch(/
\$\$\\sum_\{i=1\}\^n x_i\$\$<\/div>/); expect(html).toMatch(/
\$\$sum_\(i=1\)\^n x_i\$\$<\/div>/); }); it('handles edge cases and regular code blocks', async () => { const html = await parseAdvancedmarkup(content); // Test regular code blocks (should remain as code, not math) expect(html).toMatch(/]*>\$19\.99<\/code>/); expect(html).toMatch(/]*>echo "Price: \$100"<\/code>/); expect(html).toMatch(/]*>const price = \\`\$\$\{amount\}\\`<\/code>/); expect(html).toMatch(/]*>color: \$primary-color<\/code>/); }); });