aboutsummaryrefslogtreecommitdiff
path: root/packages/markdown/remark/test/highlight.test.js
blob: bcd2086b5c9c44d399f89b7420b623953d09a0d3 (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
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { createMarkdownProcessor } from '../dist/index.js';

describe('highlight', () => {
	it('highlights using shiki by default', async () => {
		const processor = await createMarkdownProcessor();
		const { code } = await processor.render('```js\nconsole.log("Hello, world!");\n```');
		assert.match(code, /background-color:/);
	});

	it('does not highlight math code blocks by default', async () => {
		const processor = await createMarkdownProcessor();
		const { code } = await processor.render('```math\n\\frac{1}{2}\n```');

		assert.ok(!code.includes('background-color:'));
	});

	it('highlights using prism', async () => {
		const processor = await createMarkdownProcessor({
			syntaxHighlight: {
				type: 'prism',
			},
		});
		const { code } = await processor.render('```js\nconsole.log("Hello, world!");\n```');
		assert.ok(code.includes('token'));
	});

	it('supports excludeLangs', async () => {
		const processor = await createMarkdownProcessor({
			syntaxHighlight: {
				type: 'shiki',
				excludeLangs: ['mermaid'],
			},
		});
		const { code } = await processor.render('```mermaid\ngraph TD\nA --> B\n```');

		assert.ok(!code.includes('background-color:'));
	});

	it('supports excludeLangs with prism', async () => {
		const processor = await createMarkdownProcessor({
			syntaxHighlight: {
				type: 'prism',
				excludeLangs: ['mermaid'],
			},
		});
		const { code } = await processor.render('```mermaid\ngraph TD\nA --> B\n```');

		assert.ok(!code.includes('token'));
	});
});