mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.4 KiB
106 lines
3.4 KiB
import {
|
|
createMarkdownRenderer,
|
|
disposeMdItInstance,
|
|
type MarkdownOptions
|
|
} from 'node/markdown/markdown'
|
|
|
|
async function render(src: string, options: MarkdownOptions = {}) {
|
|
disposeMdItInstance()
|
|
const md = await createMarkdownRenderer('.', {
|
|
highlight: (code) => code,
|
|
...options
|
|
})
|
|
return md.renderAsync(src)
|
|
}
|
|
|
|
describe('node/markdown/markdown', () => {
|
|
describe('disabling built-in plugins', () => {
|
|
test('anchor', async () => {
|
|
const enabled = await render('# Hello World')
|
|
expect(enabled).toContain('id="hello-world"')
|
|
expect(enabled).toContain('header-anchor')
|
|
|
|
const disabled = await render('# Hello World', { anchor: false })
|
|
expect(disabled).not.toContain('id=')
|
|
expect(disabled).not.toContain('header-anchor')
|
|
})
|
|
|
|
test('attrs', async () => {
|
|
const enabled = await render('## Title {#custom-id}')
|
|
expect(enabled).toContain('id="custom-id"')
|
|
|
|
const disabled = await render('## Title {#custom-id}', { attrs: false })
|
|
expect(disabled).not.toContain('id="custom-id"')
|
|
expect(disabled).toContain('{#custom-id}')
|
|
})
|
|
|
|
test('emoji', async () => {
|
|
expect(await render(':tada:')).toContain('🎉')
|
|
expect(await render(':tada:', { emoji: false })).toContain(':tada:')
|
|
})
|
|
|
|
test('toc', async () => {
|
|
const src = '# Title\n\n[[toc]]'
|
|
expect(await render(src)).toContain('table-of-contents')
|
|
|
|
const disabled = await render(src, { toc: false })
|
|
expect(disabled).not.toContain('table-of-contents')
|
|
expect(disabled).toContain('[[toc]]')
|
|
})
|
|
|
|
test('preWrapper', async () => {
|
|
const src = '```js\nconst a = 1\n```'
|
|
const enabled = await render(src)
|
|
expect(enabled).toContain('<div class="language-js">')
|
|
expect(enabled).toContain('class="copy"')
|
|
|
|
const disabled = await render(src, { preWrapper: false })
|
|
expect(disabled).not.toContain('<div class="language-js">')
|
|
expect(disabled).not.toContain('class="copy"')
|
|
})
|
|
|
|
test('preWrapper disables line numbers with it', async () => {
|
|
const src = '```js\nconst a = 1\n```'
|
|
const enabled = await render(src, { lineNumbers: true })
|
|
expect(enabled).toContain('line-numbers-wrapper')
|
|
|
|
const disabled = await render(src, {
|
|
preWrapper: false,
|
|
lineNumbers: true
|
|
})
|
|
expect(disabled).not.toContain('line-numbers-wrapper')
|
|
})
|
|
|
|
test('snippet', async () => {
|
|
const disabled = await render('<<< ./foo.js', { snippet: false })
|
|
expect(disabled).toContain('<<< ./foo.js')
|
|
})
|
|
|
|
test('image', async () => {
|
|
const src = ''
|
|
const enabled = await render(src, { image: { lazyLoad: true } })
|
|
expect(enabled).toContain('loading="lazy"')
|
|
|
|
const disabled = await render(src, { image: false })
|
|
expect(disabled).not.toContain('loading="lazy"')
|
|
})
|
|
|
|
test('component', async () => {
|
|
const src = 'text\n<MyComponent/>\nmore'
|
|
const enabled = await render(src)
|
|
expect(enabled).toContain('</p>\n<MyComponent/><p>')
|
|
|
|
const disabled = await render(src, { component: false })
|
|
expect(disabled).toContain('<p>text\n<MyComponent/>\nmore</p>')
|
|
})
|
|
|
|
test('tableTabIndex', async () => {
|
|
const src = '| a |\n| --- |\n| b |'
|
|
expect(await render(src)).toContain('tabindex="0"')
|
|
expect(await render(src, { tableTabIndex: false })).not.toContain(
|
|
'tabindex'
|
|
)
|
|
})
|
|
})
|
|
})
|