aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-math.test.js
blob: 5352eca68c8ba9107d310fb450104305f5d916fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import mdx from '@astrojs/mdx';
import { parseHTML } from 'linkedom';
import rehypeMathjaxSvg from 'rehype-mathjax';
import rehypeMathjaxChtml from 'rehype-mathjax/chtml';
import remarkMath from 'remark-math';
import { loadFixture } from '../../../astro/test/test-utils.js';

const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url);

describe('MDX math', () => {
	describe('mathjax', () => {
		it('works with svg', async () => {
			const fixture = await loadFixture({
				root: FIXTURE_ROOT,
				markdown: {
					remarkPlugins: [remarkMath],
					rehypePlugins: [rehypeMathjaxSvg],
				},
				integrations: [mdx()],
			});
			await fixture.build();

			const html = await fixture.readFile('/mathjax/index.html');
			const { document } = parseHTML(html);

			const mjxContainer = document.querySelector('mjx-container[jax="SVG"]');
			assert.notEqual(mjxContainer, null);

			const mjxStyle = document.querySelector('style').innerHTML;
			assert.equal(
				mjxStyle.includes('mjx-container[jax="SVG"]'),
				true,
				'style should not be html-escaped',
			);
		});

		it('works with chtml', async () => {
			const fixture = await loadFixture({
				root: FIXTURE_ROOT,
				markdown: {
					remarkPlugins: [remarkMath],
					rehypePlugins: [
						[
							rehypeMathjaxChtml,
							{
								chtml: {
									fontURL: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/output/chtml/fonts/woff-v2',
								},
							},
						],
					],
				},
				integrations: [mdx()],
			});
			await fixture.build();

			const html = await fixture.readFile('/mathjax/index.html');
			const { document } = parseHTML(html);

			const mjxContainer = document.querySelector('mjx-container[jax="CHTML"]');
			assert.notEqual(mjxContainer, null);

			const mjxStyle = document.querySelector('style').innerHTML;
			assert.equal(
				mjxStyle.includes('mjx-container[jax="CHTML"]'),
				true,
				'style should not be html-escaped',
			);
		});
	});
});