Fix chinese auchor link
This commit is contained in:
parent
9d30ac7435
commit
9a1db6ed43
3 changed files with 9 additions and 3 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 1.1.4
|
||||||
|
### Bug fixes
|
||||||
|
- Fixed chinese auchor link
|
||||||
|
|
||||||
## 1.1.3
|
## 1.1.3
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
- Optimize progress bar again
|
- Optimize progress bar again
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export function scrollActiveSidebar () {
|
||||||
export function scrollIntoView () {
|
export function scrollIntoView () {
|
||||||
const id = window.location.hash.match(/#[^#\/]+$/g)
|
const id = window.location.hash.match(/#[^#\/]+$/g)
|
||||||
if (!id || !id.length) return
|
if (!id || !id.length) return
|
||||||
const section = document.querySelector(id[0])
|
const section = document.querySelector(decodeURIComponent(id[0]))
|
||||||
|
|
||||||
if (section) section.scrollIntoView()
|
if (section) section.scrollIntoView()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,16 @@ const renderer = new marked.Renderer()
|
||||||
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
* @link https://github.com/chjj/marked#overriding-renderer-methods
|
||||||
*/
|
*/
|
||||||
renderer.heading = function (text, level) {
|
renderer.heading = function (text, level) {
|
||||||
const slug = text.toLowerCase().replace(/<(?:.|\n)*?>/gm, '').replace(/[^\w|\u4e00-\u9fa5]+/g, '-')
|
const slug = text.toLowerCase()
|
||||||
|
.replace(/<(?:.|\n)*?>/gm, '')
|
||||||
|
.replace(/[^\w|\u4e00-\u9fa5]+/g, '-')
|
||||||
let route = ''
|
let route = ''
|
||||||
|
|
||||||
if (OPTIONS.router) {
|
if (OPTIONS.router) {
|
||||||
route = `#/${getRoute()}`
|
route = `#/${getRoute()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
toc.push({ level, slug: `${route}#${slug}`, title: text })
|
toc.push({ level, slug: `${route}#${encodeURIComponent(slug)}`, title: text })
|
||||||
|
|
||||||
return `<h${level} id="${slug}"><a href="${route}#${slug}" class="anchor"></a>${text}</h${level}>`
|
return `<h${level} id="${slug}"><a href="${route}#${slug}" class="anchor"></a>${text}</h${level}>`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue