mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-12 17:26:17 +00:00
Fixes that TOC hasn't id attribute when the title is all 2-byte characters (#2994)
* Fix: 2-byte character support of slug * Fix: Decodes slug to display slug * Fix: Removed a logic of replaceDiacritics * Fix: Fixed slugify to pass tests * Fix: Fixed not to remove underscore * Adds the test for slugify.js * Fix: Fix to jump to heading * Added a comment * Fix: Created click event only linking to heading * Fix: Fix to use handleLinkClick(e) * Fix: Changed the regex rule * Fix: Changed the regex rule of extractId
This commit is contained in:
@@ -21,7 +21,7 @@ function uniqueSlug (slug, slugs, opts) {
|
||||
}
|
||||
|
||||
function linkify (token) {
|
||||
token.content = mdlink(token.content, '#' + token.slug)
|
||||
token.content = mdlink(token.content, `#${decodeURI(token.slug)}`)
|
||||
return token
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
import diacritics from 'diacritics-map'
|
||||
|
||||
function replaceDiacritics (str) {
|
||||
return str.replace(/[À-ž]/g, function (ch) {
|
||||
return diacritics[ch] || ch
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function slugify (title) {
|
||||
let slug = title.trim()
|
||||
const slug = encodeURI(
|
||||
title.trim()
|
||||
.replace(/^\s+/, '')
|
||||
.replace(/\s+$/, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[\]\[\!\'\#\$\%\&\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\{\|\}\~\`]/g, '')
|
||||
)
|
||||
|
||||
slug = replaceDiacritics(slug)
|
||||
|
||||
slug = slug.replace(/[^\w\s-]/g, '').replace(/\s+/g, '-')
|
||||
|
||||
return encodeURI(slug).replace(/\-+$/, '')
|
||||
return slug
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user