mirror of https://github.com/vuejs/vitepress
refactor: improve relative image path normalization (#5314)
parent
9ee401d7ad
commit
262b78f1ca
@ -0,0 +1,33 @@
|
||||
import { MarkdownItAsync } from 'markdown-it-async'
|
||||
import { imagePlugin } from 'node/markdown/plugins/image'
|
||||
|
||||
describe('node/markdown/plugins/image', () => {
|
||||
const md = new MarkdownItAsync()
|
||||
imagePlugin(md as any)
|
||||
|
||||
test('default image output', async () => {
|
||||
const html = await md.renderAsync('')
|
||||
expect(html.trim()).toMatchInlineSnapshot(
|
||||
`"<p><img src="./foo.png" alt="logo"></p>"`
|
||||
)
|
||||
})
|
||||
|
||||
test.for([
|
||||
['foo.png', './foo.png'],
|
||||
['./foo.png', './foo.png'],
|
||||
['../foo.png', '../foo.png'],
|
||||
['../../foo.png', '../../foo.png'],
|
||||
['/foo.png', '/foo.png'],
|
||||
['https://example.com/foo.png', 'https://example.com/foo.png']
|
||||
])('normalizes image src: %s → %s', async ([src, expected]) => {
|
||||
const html = await md.renderAsync(``)
|
||||
expect(html).toContain(`src="${expected}"`)
|
||||
})
|
||||
|
||||
test('adds loading="lazy" attribute when lazyLoading is enabled', async () => {
|
||||
const mdLazy = new MarkdownItAsync()
|
||||
imagePlugin(mdLazy as any, { lazyLoading: true })
|
||||
const html = await mdLazy.renderAsync('')
|
||||
expect(html).toContain('loading="lazy"')
|
||||
})
|
||||
})
|
||||
Loading…
Reference in new issue