优化预览header生成

This commit is contained in:
xiaoqi.cxq 2023-10-18 09:40:43 +08:00
parent 96ea8cd0db
commit b4c9407b06

View File

@ -233,9 +233,18 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
const clonedElt = headingElt.cloneNode(true); const clonedElt = headingElt.cloneNode(true);
clonedElt.removeAttribute('id'); clonedElt.removeAttribute('id');
sectionTocElt.appendChild(clonedElt); sectionTocElt.appendChild(clonedElt);
// 创建一个新的 <span> 元素
const contentElt = document.createElement('span');
contentElt.className = 'content';
// 将原始内容移动到新的 <span> 元素中
while (headingElt.firstChild) {
contentElt.appendChild(headingElt.firstChild);
}
const prefixElt = document.createElement('span'); const prefixElt = document.createElement('span');
prefixElt.className = 'prefix'; prefixElt.className = 'prefix';
headingElt.insertBefore(prefixElt, headingElt.firstChild); headingElt.insertBefore(prefixElt, headingElt.firstChild);
// 将新的 <span> 元素替换原始元素
headingElt.appendChild(contentElt);
const suffixElt = document.createElement('span'); const suffixElt = document.createElement('span');
suffixElt.className = 'suffix'; suffixElt.className = 'suffix';
headingElt.appendChild(suffixElt); headingElt.appendChild(suffixElt);