Skip to content

Commit

Permalink
fix(slugify): GitHub compatible heading links, fixed #272
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Oct 7, 2017
1 parent 2e3fe59 commit 9b4e666
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/render/slugify.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
let cache = {}
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,.\/:;<=>?@\[\]^`{|}~]/g

function lower (string) {
return string.toLowerCase()
}

export function slugify (str) {
if (typeof str !== 'string') return ''

str = /^[\w\s]+$/g.test(str) ? str.toLowerCase() : str

let slug = str
.trim()
.replace(/[A-Z]+/g, lower)
.replace(/<[^>\d]+>/g, '')
.replace(re, '')
.replace(/\s/g, '-')
Expand Down

0 comments on commit 9b4e666

Please sign in to comment.