feat: set title style through executeSetHtml api #626

pr675
Hufe921 2 years ago
parent aca9d34a46
commit ac795b0bc4

@ -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
}

@ -1731,7 +1731,6 @@ window.onload = function () {
instance.listener.saved = function (payload) {
console.log('elementList: ', payload)
console.log(instance.command.getControlList())
}
// 9. 右键菜单注册

Loading…
Cancel
Save