修复h标签渲染包含图片锚点错误并图片渲染不了的问题

This commit is contained in:
xiaoqi.cxq 2023-06-30 09:40:52 +08:00
parent 1727be1eaf
commit 282b546edc
2 changed files with 7 additions and 1 deletions

View File

@ -56,6 +56,7 @@ export default (md) => {
// According to http://pandoc.org/README.html#extension-auto_identifiers
let slug = headingContent
.replace(/<img[^>]*>/g, '') // Replace image to empty
.replace(/\s/g, '-') // Replace all spaces and newlines with hyphens
.replace(/[\0-,/:-@[-^`{-~]/g, '') // Remove all punctuation, except underscores, hyphens, and periods
.toLowerCase(); // Convert all alphabetic characters to lowercase

View File

@ -233,7 +233,12 @@ const editorSvc = Object.assign(new Vue(), editorSvcDiscussions, editorSvcUtils,
const clonedElt = headingElt.cloneNode(true);
clonedElt.removeAttribute('id');
sectionTocElt.appendChild(clonedElt);
headingElt.innerHTML = `<span class="prefix"></span><span class="content">${headingElt.innerHTML}</span><span class="suffix"></span>`;
const prefixElt = document.createElement('span');
prefixElt.className = 'prefix';
headingElt.insertBefore(prefixElt, headingElt.firstChild);
const suffixElt = document.createElement('span');
suffixElt.className = 'suffix';
headingElt.appendChild(suffixElt);
}
if (insertBeforeTocElt) {
this.tocElt.insertBefore(sectionTocElt, insertBeforeTocElt);