2024-01-31 03:37:34 -05:00
|
|
|
import * as assert from 'node:assert/strict';
|
2024-02-21 09:08:19 -05:00
|
|
|
import { describe, it } from 'node:test';
|
|
|
|
import mdx from '@astrojs/mdx';
|
2023-03-08 11:29:22 -05:00
|
|
|
import { parseHTML } from 'linkedom';
|
|
|
|
import rehypeMathjaxSvg from 'rehype-mathjax';
|
2023-11-20 23:09:19 -05:00
|
|
|
import rehypeMathjaxChtml from 'rehype-mathjax/chtml';
|
2024-02-21 09:08:19 -05:00
|
|
|
import remarkMath from 'remark-math';
|
|
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
2023-03-08 11:29:22 -05:00
|
|
|
|
|
|
|
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"]');
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.notEqual(mjxContainer, null);
|
2023-03-08 11:29:22 -05:00
|
|
|
|
|
|
|
const mjxStyle = document.querySelector('style').innerHTML;
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.equal(
|
|
|
|
mjxStyle.includes('mjx-container[jax="SVG"]'),
|
|
|
|
true,
|
|
|
|
'style should not be html-escaped'
|
|
|
|
);
|
2023-03-08 11:29:22 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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"]');
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.notEqual(mjxContainer, null);
|
2023-03-08 11:29:22 -05:00
|
|
|
|
|
|
|
const mjxStyle = document.querySelector('style').innerHTML;
|
2024-01-31 03:37:34 -05:00
|
|
|
assert.equal(
|
|
|
|
mjxStyle.includes('mjx-container[jax="CHTML"]'),
|
|
|
|
true,
|
|
|
|
'style should not be html-escaped'
|
|
|
|
);
|
2023-03-08 11:29:22 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|