import { unified } from 'unified'; import { describe, test, expect } from 'vitest'; import remarkParse from 'remark-parse'; import remarkRehype from 'remark-rehype'; import rehypeStringify from 'rehype-stringify'; import { rehypePluginPreWrapper } from '../plugin-markdown/rehypePlugins/preWrapper'; import { rehypePluginShiki } from '../plugin-markdown/rehypePlugins/shiki'; import shiki from 'shiki'; import remarkMdx from 'remark-mdx'; import { remarkPluginToc } from '../plugin-markdown/remarkPlugins/toc'; import remarkStringify from 'remark-stringify'; describe('Markdown compile cases', async () => { const processor = unified() .use(remarkParse) .use(remarkRehype) .use(rehypePluginPreWrapper) .use(rehypePluginShiki, { highlighter: await shiki.getHighlighter({ theme: 'nord' }) }) .use(rehypeStringify); test('Compile title', async () => { const mdContent = '# 123'; const result = processor.processSync(mdContent); expect(result.value).toMatchInlineSnapshot('"

123

"'); }); test('Compile code', async () => { const mdContent = 'I am using `Beaver.js`'; const result = processor.processSync(mdContent); expect(result.value).toMatchInlineSnapshot('"

I am using Beaver.js

"'); }); test('Compile TOC', async () => { const mdContent = `# h1 ## h2 \`code\` ### h3 [link](https://beaver.dev) #### h4 ##### h5 `; const remarkProcessor = unified() .use(remarkParse) .use(remarkMdx) .use(remarkPluginToc) .use(remarkStringify); const result = remarkProcessor.processSync(mdContent); expect(result.value.toString().replace(mdContent, '')).toMatchInlineSnapshot(` " export const toc = [ { \\"id\\": \\"h2-code\\", \\"text\\": \\"h2 code\\", \\"depth\\": 2 }, { \\"id\\": \\"h3-link\\", \\"text\\": \\"h3 link\\", \\"depth\\": 3 }, { \\"id\\": \\"h4\\", \\"text\\": \\"h4\\", \\"depth\\": 4 } ]; export const title = 'h1'; " `); }); });