优化导出中的header生成
This commit is contained in:
parent
b4c9407b06
commit
97b8d3c288
@ -116,9 +116,18 @@ export default {
|
|||||||
// Make TOC
|
// Make TOC
|
||||||
const allHeaders = containerElt.querySelectorAll('h1,h2,h3,h4,h5,h6');
|
const allHeaders = containerElt.querySelectorAll('h1,h2,h3,h4,h5,h6');
|
||||||
Array.prototype.slice.call(allHeaders).forEach((headingElt) => {
|
Array.prototype.slice.call(allHeaders).forEach((headingElt) => {
|
||||||
|
// 创建一个新的 <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);
|
||||||
|
Loading…
Reference in New Issue
Block a user