浏览代码

fix: issue with Custom Header IDs (#4527)

Fix the issue described in discussion #3502 regarding header links and TOC failing to properly generate when header ID is custom defined.
broxen 3 年之前
父节点
当前提交
db73b650c9
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      server/modules/rendering/html-core/renderer.js

+ 3 - 2
server/modules/rendering/html-core/renderer.js

@@ -201,10 +201,11 @@ module.exports = {
 
 
     let headers = []
     let headers = []
     $('h1,h2,h3,h4,h5,h6').each((i, elm) => {
     $('h1,h2,h3,h4,h5,h6').each((i, elm) => {
+      let headerSlug = uslug($(elm).text())
+      // -> If custom ID is defined, try to use that instead
       if ($(elm).attr('id')) {
       if ($(elm).attr('id')) {
-        return
+        headerSlug = $(elm).attr('id')
       }
       }
-      let headerSlug = uslug($(elm).text())
 
 
       // -> Cannot start with a number (CSS selector limitation)
       // -> Cannot start with a number (CSS selector limitation)
       if (headerSlug.match(/^\d/)) {
       if (headerSlug.match(/^\d/)) {