From 7ade99b9b8b66db71192b51af9c2140daf510eba Mon Sep 17 00:00:00 2001 From: YangFong Date: Sun, 12 May 2024 18:38:15 +0800 Subject: [PATCH] fix: list rendering error (#297) --- .../CodemirrorEditor/EditorHeader/index.vue | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/CodemirrorEditor/EditorHeader/index.vue b/src/components/CodemirrorEditor/EditorHeader/index.vue index 9335696..0183e0f 100644 --- a/src/components/CodemirrorEditor/EditorHeader/index.vue +++ b/src/components/CodemirrorEditor/EditorHeader/index.vue @@ -365,10 +365,29 @@ export default { copy() { this.$emit(`startCopy`) setTimeout(() => { + function modifyHtmlStructure(htmlString) { + // 创建一个 div 元素来暂存原始 HTML 字符串 + const tempDiv = document.createElement(`div`) + tempDiv.innerHTML = htmlString + + const originalItems = tempDiv.querySelectorAll(`li > ul, li > ol`) + + originalItems.forEach((originalItem) => { + originalItem.parentElement.insertAdjacentElement( + `afterend`, + originalItem + ) + }) + + // 返回修改后的 HTML 字符串 + return tempDiv.innerHTML + } + solveWeChatImage() const clipboardDiv = document.getElementById(`output`) clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML) + clipboardDiv.innerHTML = modifyHtmlStructure(clipboardDiv.innerHTML) // 调整 katex 公式元素为行内标签,目的是兼容微信公众号渲染 clipboardDiv.innerHTML = clipboardDiv.innerHTML