9 changed files with 4619 additions and 614 deletions
File diff suppressed because one or more lines are too long
@ -1,151 +0,0 @@ |
|||||||
# This is a testfile for writing mathematic formulas in NostrMarkup |
|
||||||
|
|
||||||
This document covers the rendering of formulas in TeX/LaTeX and AsciiMath |
|
||||||
notation, or some combination of those within the same page. It is meant to be |
|
||||||
rendered by clients utilizing MathJax. |
|
||||||
|
|
||||||
If you want the entire document to be rendered as mathematics, place the entire |
|
||||||
thing in a backtick-codeblock, but know that this makes the document slower to |
|
||||||
load, it is harder to format the prose, and the result is less legible. It also |
|
||||||
doesn't increase portability, as it's easy to export markup as LaTeX files, or |
|
||||||
as PDFs, with the formulas rendered. |
|
||||||
|
|
||||||
The general idea, is that anything placed within `single backticks` is inline |
|
||||||
code, and inline-code will all be scanned for typical mathematics statements and |
|
||||||
rendered with best-effort. (For more precise rendering, use Asciidoc.) We will |
|
||||||
not render text that is not marked as inline code, as mathematical formulas, as |
|
||||||
that is prose. |
|
||||||
|
|
||||||
If you want the TeX to be blended into the surrounding text, wrap the text |
|
||||||
within single `$`. Otherwise, use double `$$` symbols, for display math, and it |
|
||||||
will appear on its own line. |
|
||||||
|
|
||||||
## TeX Examples |
|
||||||
|
|
||||||
Inline equation: `$\sqrt{x}$` |
|
||||||
|
|
||||||
Same equation, in the display mode: `$$\sqrt{x}$$` |
|
||||||
|
|
||||||
Something more complex, inline: `$\mathbb{N} = \{ a \in \mathbb{Z} : a > 0 \}$` |
|
||||||
|
|
||||||
Something complex, in display mode: |
|
||||||
`$$P \left( A=2 \, \middle| \, \dfrac{A^2}{B}>4 \right)$$` |
|
||||||
|
|
||||||
Another example of `$$\prod_{i=1}^{n} x_i - 1$$` inline formulas. |
|
||||||
|
|
||||||
Function example: `$$ f(x)= \begin{cases} 1/d_{ij} & \quad \text{when |
|
||||||
$d_{ij} \leq 160$}\\ 0 & \quad \text{otherwise} \end{cases} |
|
||||||
|
|
||||||
$$ ` |
|
||||||
|
|
||||||
And a matrix: ` $$ |
|
||||||
|
|
||||||
M = \begin{bmatrix} \frac{5}{6} & \frac{1}{6} & 0 \\[0.3em] \frac{5}{6} & 0 & |
|
||||||
\frac{1}{6} \\[0.3em] 0 & \frac{5}{6} & \frac{1}{6} \end{bmatrix} |
|
||||||
|
|
||||||
$$ ` |
|
||||||
|
|
||||||
LaTeX ypesetting won't be rendered. Use NostrMarkup delimeter tables for this |
|
||||||
sort of thing. |
|
||||||
|
|
||||||
`\\begin{tabular}{|c|c|c|l|r|} |
|
||||||
\\hline |
|
||||||
\\multicolumn{3}{|l|}{test} & A & B \\\\ |
|
||||||
\\hline |
|
||||||
1 & 2 & 3 & 4 & 5 \\\\ |
|
||||||
\\hline |
|
||||||
\\end{tabular}` |
|
||||||
|
|
||||||
We also recognize common LaTeX statements: |
|
||||||
|
|
||||||
`\[ |
|
||||||
\begin{array}{ccccc} |
|
||||||
1 & 2 & 3 & 4 & 5 \\ |
|
||||||
\end{array} |
|
||||||
\]` |
|
||||||
|
|
||||||
`\[ x^n + y^n = z^n \]` |
|
||||||
|
|
||||||
`\sqrt{x^2+1}` |
|
||||||
|
|
||||||
Greek letters are a snap: `$\Psi$`, `$\psi$`, `$\Phi$`, `$\phi$`. |
|
||||||
|
|
||||||
Equations within text are easy--- A well known Maxwell thermodynamic relation is |
|
||||||
`$\left.{\partial T \over \partial P}\right|_{s} = \left.{\partial v \over \partial s}\right|_{P}$`. |
|
||||||
|
|
||||||
You can also set aside equations like so: |
|
||||||
`\begin{eqnarray} du &=& T\ ds -P\ dv, \qquad \mbox{first law.}\label{fl}\\ ds &\ge& {\delta q \over T}.\qquad \qquad \mbox{second law.} \label{sl} \end {eqnarray}` |
|
||||||
|
|
||||||
## And some good ole Asciimath |
|
||||||
|
|
||||||
Asciimath doesn't use `$` or `$$` delimiters, but we are using it to make mathy |
|
||||||
stuff easier to find. If you want it inline, include it inline. If you want it |
|
||||||
on a separate line, put a hard-return before and after. |
|
||||||
|
|
||||||
Inline text example here `$E=mc^2$` and another `$1/(x+1)$`; very simple. |
|
||||||
|
|
||||||
Displaying on a separate line: |
|
||||||
|
|
||||||
`$$sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2$$` |
|
||||||
|
|
||||||
`$$int_0^1 x^2 dx$$` |
|
||||||
|
|
||||||
`$$x = (-6 +- sqrt((-6)^2 - 4 (1)(4)))/(2 xx 1)$$` |
|
||||||
|
|
||||||
`$$|x|= {(x , if x ge 0 text(,)),(-x , if x <0.):}$$` |
|
||||||
|
|
||||||
Displaying with wider spacing: |
|
||||||
|
|
||||||
`$a=3, \ \ \ b=-3,\ \ $` and `$ \ \ c=2$`. |
|
||||||
|
|
||||||
Thus `$(a+b)(c+b)=0$`. |
|
||||||
|
|
||||||
Displaying with indentations: |
|
||||||
|
|
||||||
Using the quadratic formula, the roots of `$x^2-6x+4=0$` are |
|
||||||
|
|
||||||
`$$x = (-6 +- sqrt((-6)^2 - 4 (1)(4)))/(2 xx 1)$$` |
|
||||||
|
|
||||||
`$$ \ \ = (-6 +- sqrt(36 - 16))/2$$` |
|
||||||
|
|
||||||
`$$ \ \ =(-6 +- sqrt(20))/2$$` |
|
||||||
|
|
||||||
`$$ \ \ = -0.8 or 2.2 \ \ \ $$` to 1 decimal place. |
|
||||||
|
|
||||||
Advanced alignment and matrices looks like this: |
|
||||||
|
|
||||||
A `$3xx3$` matrix, `$$((1,2,3),(4,5,6),(7,8,9))$$` and a `$2xx1$` matrix, or |
|
||||||
vector, `$$((1),(0))$$`. |
|
||||||
|
|
||||||
The outer brackets determine the delimiters e.g. `$|(a,b),(c,d)|=ad-bc$`. |
|
||||||
|
|
||||||
A general `$m xx n$` matrix |
|
||||||
`$$((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))$$` |
|
||||||
|
|
||||||
## Mixed Examples |
|
||||||
|
|
||||||
Here are some examples mixing LaTeX and AsciiMath: |
|
||||||
|
|
||||||
- LaTeX inline: `$\frac{1}{2}$` vs AsciiMath inline: `$1/2$` |
|
||||||
- LaTeX display: `$$\sum_{i=1}^n x_i$$` vs AsciiMath display: |
|
||||||
`$$sum_(i=1)^n x_i$$` |
|
||||||
- LaTeX matrix: `$$\begin{pmatrix} a & b \\ c & d \end{pmatrix}$$` vs AsciiMath |
|
||||||
matrix: `$$((a,b),(c,d))$$` |
|
||||||
|
|
||||||
## Edge Cases |
|
||||||
|
|
||||||
- Empty math: `$$` |
|
||||||
- Just delimiters: `$ $` |
|
||||||
- Dollar signs in text: The price is $10.50 |
|
||||||
- Currency: `$19.99` |
|
||||||
- Shell command: `echo "Price: $100"` |
|
||||||
- JavaScript template: `const price = \`$${amount}\`` |
|
||||||
- CSS with dollar signs: `color: $primary-color` |
|
||||||
|
|
||||||
This document should demonstrate that: |
|
||||||
|
|
||||||
1. LaTeX is processed within inline code blocks with proper delimiters |
|
||||||
2. AsciiMath is processed within inline code blocks with proper delimiters |
|
||||||
3. Regular code blocks remain unchanged |
|
||||||
4. Mixed content is handled correctly |
|
||||||
5. Edge cases are handled gracefully $$ |
|
||||||
@ -1,83 +0,0 @@ |
|||||||
import { describe, expect, it } 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(/<span class="math-inline">\$\\sqrt\{x\}\$<\/span>/); |
|
||||||
expect(html).toMatch(/<div class="math-block">\$\$\\sqrt\{x\}\$\$<\/div>/); |
|
||||||
expect(html).toMatch( |
|
||||||
/<span class="math-inline">\$\\mathbb\{N\} = \\{ a \\in \\mathbb\{Z\} : a > 0 \\}\$<\/span>/, |
|
||||||
); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$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(/<span class="math-inline">\$E=mc\^2\$<\/span>/); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$sum_\(k=1\)\^n k = 1\+2\+ cdots \+n=\(n\(n\+1\)\)\/2\$\$<\/div>/, |
|
||||||
); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$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( |
|
||||||
/<div class="math-block">\$\$[\s\S]*\\begin\{array\}\{ccccc\}[\s\S]*\\end\{array\}[\s\S]*\$\$<\/div>/, |
|
||||||
); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$[\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(/<div class="unrendered-latex">/); |
|
||||||
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( |
|
||||||
/<span class="math-inline">\$\\frac\{1\}\{2\}\$<\/span>/, |
|
||||||
); |
|
||||||
expect(html).toMatch(/<span class="math-inline">\$1\/2\$<\/span>/); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$\\sum_\{i=1\}\^n x_i\$\$<\/div>/, |
|
||||||
); |
|
||||||
expect(html).toMatch( |
|
||||||
/<div class="math-block">\$\$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(/<code[^>]*>\$19\.99<\/code>/); |
|
||||||
expect(html).toMatch(/<code[^>]*>echo "Price: \$100"<\/code>/); |
|
||||||
expect(html).toMatch( |
|
||||||
/<code[^>]*>const price = \\`\$\$\{amount\}\\`<\/code>/, |
|
||||||
); |
|
||||||
expect(html).toMatch(/<code[^>]*>color: \$primary-color<\/code>/); |
|
||||||
}); |
|
||||||
}); |
|
||||||
@ -0,0 +1,186 @@ |
|||||||
|
import { describe, expect, it } from "vitest"; |
||||||
|
import { parseAdvancedmarkup } from "../../src/lib/utils/markup/advancedMarkupParser.ts"; |
||||||
|
|
||||||
|
describe("Math Processing in Advanced Markup Parser", () => { |
||||||
|
it("should process inline math inside code blocks", async () => { |
||||||
|
const input = "Here is some inline math: `$x^2 + y^2 = z^2$` in a sentence."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">\\(x^2 + y^2 = z^2\\)</span>'); |
||||||
|
expect(result).toContain("Here is some inline math:"); |
||||||
|
expect(result).toContain("in a sentence."); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should process display math inside code blocks", async () => { |
||||||
|
const input = "Here is a display equation:\n\n`$$\n\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}\n$$`\n\nThis is after the equation."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">\\[\n\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}\n\\]</span>'); |
||||||
|
expect(result).toContain('<p class="my-4">Here is a display equation:</p>'); |
||||||
|
expect(result).toContain('<p class="my-4">This is after the equation.</p>'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should process both inline and display math in the same code block", async () => { |
||||||
|
const input = "Mixed math: `$\\alpha$ and $$\\beta = \\frac{1}{2}$$` in one block."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">\\(\\alpha\\)</span>'); |
||||||
|
expect(result).toContain('<span class="math-display">\\[\\beta = \\frac{1}{2}\\]</span>'); |
||||||
|
expect(result).toContain("Mixed math:"); |
||||||
|
expect(result).toContain("in one block."); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should NOT process math outside of code blocks", async () => { |
||||||
|
const input = "This math $x^2 + y^2 = z^2$ should not be processed."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain("$x^2 + y^2 = z^2$"); |
||||||
|
expect(result).not.toContain('<span class="math-inline">'); |
||||||
|
expect(result).not.toContain('<span class="math-display">'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should NOT process display math outside of code blocks", async () => { |
||||||
|
const input = "This display math $$\n\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}\n$$ should not be processed."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain("$$\n\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}\n$$"); |
||||||
|
expect(result).not.toContain('<span class="math-inline">'); |
||||||
|
expect(result).not.toContain('<span class="math-display">'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle code blocks without math normally", async () => { |
||||||
|
const input = "Here is some code: `console.log('hello world')` that should not be processed."; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain("`console.log('hello world')`"); |
||||||
|
expect(result).not.toContain('<span class="math-inline">'); |
||||||
|
expect(result).not.toContain('<span class="math-display">'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle complex math expressions with nested structures", async () => { |
||||||
|
const input = "Complex math: `$$\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix} \\cdot \\begin{pmatrix} x \\\\ y \\end{pmatrix} = \\begin{pmatrix} ax + by \\\\ cx + dy \\end{pmatrix}$$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\begin{pmatrix}"); |
||||||
|
expect(result).toContain("\\end{pmatrix}"); |
||||||
|
expect(result).toContain("\\cdot"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle inline math with special characters", async () => { |
||||||
|
const input = "Special chars: `$\\alpha, \\beta, \\gamma, \\delta$` and `$\\sum_{i=1}^{n} x_i$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">\\(\\alpha, \\beta, \\gamma, \\delta\\)</span>'); |
||||||
|
expect(result).toContain('<span class="math-inline">\\(\\sum_{i=1}^{n} x_i\\)</span>'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle multiple math expressions in separate code blocks", async () => { |
||||||
|
const input = "First: `$E = mc^2$` and second: `$$F = G\\frac{m_1 m_2}{r^2}$$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">\\(E = mc^2\\)</span>'); |
||||||
|
expect(result).toContain('<span class="math-display">\\[F = G\\frac{m_1 m_2}{r^2}\\]</span>'); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle math expressions with line breaks in display mode", async () => { |
||||||
|
const input = "Multi-line: `$$\n\\begin{align}\nx &= a + b \\\\\ny &= c + d\n\\end{align}\n$$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\begin{align}"); |
||||||
|
expect(result).toContain("\\end{align}"); |
||||||
|
expect(result).toContain("x &= a + b"); |
||||||
|
expect(result).toContain("y &= c + d"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle edge case with empty math expressions", async () => { |
||||||
|
const input = "Empty math: `$$` and `$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
// Should not crash and should preserve the original content
|
||||||
|
expect(result).toContain("`$$`"); |
||||||
|
expect(result).toContain("`$`"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle mixed content with regular text, code, and math", async () => { |
||||||
|
const input = `This is a paragraph with regular text.
|
||||||
|
|
||||||
|
Here is some code: \`console.log('hello')\` |
||||||
|
|
||||||
|
And here is math: \`$\\pi \\approx 3.14159$\` |
||||||
|
|
||||||
|
And display math: \`$$\n\\int_0^1 x^2 dx = \\frac{1}{3}\n$$\` |
||||||
|
|
||||||
|
And more regular text.`;
|
||||||
|
|
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
// Should preserve regular text
|
||||||
|
expect(result).toContain("This is a paragraph with regular text."); |
||||||
|
expect(result).toContain("And more regular text."); |
||||||
|
|
||||||
|
// Should preserve regular code blocks
|
||||||
|
expect(result).toContain("`console.log('hello')`"); |
||||||
|
|
||||||
|
// Should process math
|
||||||
|
expect(result).toContain('<span class="math-inline">\\(\\pi \\approx 3.14159\\)</span>'); |
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\int_0^1 x^2 dx = \\frac{1}{3}"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle math expressions with dollar signs in the content", async () => { |
||||||
|
const input = "Price math: `$\\text{Price} = \\$19.99$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">'); |
||||||
|
expect(result).toContain("\\text{Price} = \\$19.99"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle display math with dollar signs in the content", async () => { |
||||||
|
const input = "Price display: `$$\n\\text{Total} = \\$19.99 + \\$5.99 = \\$25.98\n$$`"; |
||||||
|
const result = await parseAdvancedmarkup(input); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\text{Total} = \\$19.99 + \\$5.99 = \\$25.98"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle JSON content with escaped backslashes", async () => { |
||||||
|
// Simulate content from JSON where backslashes are escaped
|
||||||
|
const jsonContent = "Math from JSON: `$\\\\alpha + \\\\beta = \\\\gamma$`"; |
||||||
|
const result = await parseAdvancedmarkup(jsonContent); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">'); |
||||||
|
expect(result).toContain("\\\\alpha + \\\\beta = \\\\gamma"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle JSON content with escaped display math", async () => { |
||||||
|
// Simulate content from JSON where backslashes are escaped
|
||||||
|
const jsonContent = "Display math from JSON: `$$\\\\int_0^1 x^2 dx = \\\\frac{1}{3}$$`"; |
||||||
|
const result = await parseAdvancedmarkup(jsonContent); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\\\int_0^1 x^2 dx = \\\\frac{1}{3}"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle JSON content with escaped dollar signs", async () => { |
||||||
|
// Simulate content from JSON where dollar signs are escaped
|
||||||
|
const jsonContent = "Price math from JSON: `$\\\\text{Price} = \\\\\\$19.99$`"; |
||||||
|
const result = await parseAdvancedmarkup(jsonContent); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-inline">'); |
||||||
|
expect(result).toContain("\\\\text{Price} = \\\\\\$19.99"); |
||||||
|
}); |
||||||
|
|
||||||
|
it("should handle complex JSON content with multiple escaped characters", async () => { |
||||||
|
// Simulate complex content from JSON
|
||||||
|
const jsonContent = "Complex JSON math: `$$\\\\begin{pmatrix} a & b \\\\\\\\ c & d \\\\end{pmatrix} \\\\cdot \\\\begin{pmatrix} x \\\\\\\\ y \\\\end{pmatrix}$$`"; |
||||||
|
const result = await parseAdvancedmarkup(jsonContent); |
||||||
|
|
||||||
|
expect(result).toContain('<span class="math-display">'); |
||||||
|
expect(result).toContain("\\\\begin{pmatrix}"); |
||||||
|
expect(result).toContain("\\\\end{pmatrix}"); |
||||||
|
expect(result).toContain("\\\\cdot"); |
||||||
|
expect(result).toContain("\\\\\\\\"); |
||||||
|
}); |
||||||
|
}); |
||||||
Loading…
Reference in new issue