| 1 | import MarkdownExit from 'markdown-exit' |
| 2 | import { expect, it } from 'vitest' |
| 3 | import MarkdownItKatex from './katex' |
| 4 | |
| 5 | it('inline math', async () => { |
| 6 | const md = MarkdownExit() |
| 7 | md.use(MarkdownItKatex, {}) |
| 8 | |
| 9 | const result = await md.renderAsync('This is $x^2$ inline') |
| 10 | expect(result).toContain('<span class="katex">') |
| 11 | }) |
| 12 | |
| 13 | it('block math', async () => { |
| 14 | const md = MarkdownExit() |
| 15 | md.use(MarkdownItKatex, {}) |
| 16 | |
| 17 | const result = await md.renderAsync('$$ {2,3|4}\nx^2\n$$') |
| 18 | |
| 19 | expect(result).toMatchInlineSnapshot(` |
| 20 | "<KaTexBlockWrapper :ranges='["2,3","4"]'><p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msup><mi>x</mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">x^2 |
| 21 | </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.8641em;"></span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8641em;"><span style="top:-3.113em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="katex-sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span></span></span></span></span></p></KaTexBlockWrapper> |
| 22 | " |
| 23 | `) |
| 24 | }) |
| 25 | |
| 26 | it('not transform in code block', async () => { |
| 27 | const md = MarkdownExit() |
| 28 | md.use(MarkdownItKatex, {}) |
| 29 | |
| 30 | const result = await md.renderAsync('```\n$$x^2$$\n```') |
| 31 | |
| 32 | expect(result).toMatchInlineSnapshot(` |
| 33 | "<pre><code>$$x^2$$ |
| 34 | </code></pre> |
| 35 | " |
| 36 | `) |
| 37 | }) |
| 38 |