返回 slidev
scoped.test.ts
根目录 / packages / slidev / node / syntax / scoped.test.ts
1 import MarkdownExit from 'markdown-exit'
2 import { expect, it } from 'vitest'
3 import MarkdownItStyleScoped from './scoped'
4
5 it('add scoped to style', async () => {
6 const md = MarkdownExit({ html: true })
7 md.use(MarkdownItStyleScoped)
8
9 const result = await md.renderAsync('<style>\n.red { color: red; }\n</style>')
10
11 expect(result).toMatchInlineSnapshot(`
12 "<style scoped>
13 .red { color: red; }
14 </style>"
15 `)
16 })
17
18 it('preserve existing scoped', async () => {
19 const md = MarkdownExit({ html: true })
20 md.use(MarkdownItStyleScoped)
21
22 const result = await md.renderAsync('<style scoped>\n.red { color: red; }\n</style>')
23
24 expect(result).toMatchInlineSnapshot(`
25 "<style scoped>
26 .red { color: red; }
27 </style>"
28 `)
29 })
30
31 it('not transform in code block', async () => {
32 const md = MarkdownExit({ html: true })
33 md.use(MarkdownItStyleScoped)
34
35 const result = await md.renderAsync('```html\n<style>\n.red { color: red; }\n</style>\n```')
36
37 expect(result).toMatchInlineSnapshot(`
38 "<pre><code class="language-html">&lt;style&gt;
39 .red { color: red; }
40 &lt;/style&gt;
41 </code></pre>
42 "
43 `)
44 })
45
45 lines TYPESCRIPT