fix(slugify): GitHub compatible heading links, fixed #272
This commit is contained in:
parent
2e3fe59702
commit
9b4e6669db
1 changed files with 5 additions and 2 deletions
|
|
@ -1,13 +1,16 @@
|
||||||
let cache = {}
|
let cache = {}
|
||||||
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g
|
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g
|
||||||
|
|
||||||
|
function lower (string) {
|
||||||
|
return string.toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
export function slugify (str) {
|
export function slugify (str) {
|
||||||
if (typeof str !== 'string') return ''
|
if (typeof str !== 'string') return ''
|
||||||
|
|
||||||
str = /^[\w\s]+$/g.test(str) ? str.toLowerCase() : str
|
|
||||||
|
|
||||||
let slug = str
|
let slug = str
|
||||||
.trim()
|
.trim()
|
||||||
|
.replace(/[A-Z]+/g, lower)
|
||||||
.replace(/<[^>\d]+>/g, '')
|
.replace(/<[^>\d]+>/g, '')
|
||||||
.replace(re, '')
|
.replace(re, '')
|
||||||
.replace(/\s/g, '-')
|
.replace(/\s/g, '-')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue