diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index fd3e112..617be2a 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -1235,7 +1235,10 @@ export function getElementListByHTML( } } else if (/H[1-6]/.test(node.nodeName)) { const hElement = node as HTMLTitleElement - const valueList = getElementListByHTML(hElement.innerHTML, options) + const valueList = getElementListByHTML( + replaceHTMLElementTag(hElement, 'div').outerHTML, + options + ) elementList.push({ value: '', type: ElementType.TITLE, @@ -1478,3 +1481,16 @@ export function getIsBlockElement(element?: IElement) { element.imgDisplay === ImageDisplay.INLINE) ) } + +export function replaceHTMLElementTag( + oldDom: HTMLElement, + tagName: keyof HTMLElementTagNameMap +): HTMLElement { + const newDom = document.createElement(tagName) + for (let i = 0; i < oldDom.attributes.length; i++) { + const attr = oldDom.attributes[i] + newDom.setAttribute(attr.name, attr.value) + } + newDom.innerHTML = oldDom.innerHTML + return newDom +} diff --git a/src/main.ts b/src/main.ts index 85f9f8d..2f1aed5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1731,7 +1731,6 @@ window.onload = function () { instance.listener.saved = function (payload) { console.log('elementList: ', payload) - console.log(instance.command.getControlList()) } // 9. 右键菜单注册