mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-26 05:35:51 +10:00
33 lines
680 B
JavaScript
33 lines
680 B
JavaScript
import { Md } from './util'
|
|
import anchor from 'markdown-it-anchor'
|
|
import slugify from '../../shared-utils/lib/slugify.js'
|
|
|
|
const mdS = Md().use(anchor, {
|
|
slugify,
|
|
permalink: true,
|
|
permalinkBefore: true,
|
|
permalinkSymbol: '#'
|
|
})
|
|
|
|
const asserts = {
|
|
/* header: slug */
|
|
'# a b': 'a-b',
|
|
'# a-b': 'a-b',
|
|
'# `<a>`': 'a',
|
|
'# `<a>`b': 'a-b',
|
|
'# `<a>` b': 'a-b'
|
|
}
|
|
|
|
describe('slugify', () => {
|
|
test('should convert headers to slug correctly', () => {
|
|
for (const input in asserts) {
|
|
const output = mdS.render(input)
|
|
expect(getSlug(output)).toBe(asserts[input])
|
|
}
|
|
})
|
|
})
|
|
|
|
function getSlug (output) {
|
|
return output.match(/id=\\?"([^"]*)\\?"/)[1]
|
|
}
|