From a805590696bed12c0b4ececdc7de222f629a8cc9 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 21 Aug 2023 21:42:07 +0800 Subject: [PATCH] fix: error converting some element types to HTML #257 --- src/editor/dataset/constant/Common.ts | 1 + src/editor/utils/element.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/editor/dataset/constant/Common.ts b/src/editor/dataset/constant/Common.ts index 91ab2439e..27e6d16ad 100644 --- a/src/editor/dataset/constant/Common.ts +++ b/src/editor/dataset/constant/Common.ts @@ -4,6 +4,7 @@ export const ZERO = '\u200B' export const WRAP = '\n' export const HORIZON_TAB = '\t' export const NBSP = '\u0020' +export const NON_BREAKING_SPACE = ' ' export const PUNCTUATION_LIST = [ '·', '、', diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index 135eaf737..345988b25 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -9,7 +9,7 @@ import { } from '..' import { LaTexParticle } from '../core/draw/particle/latex/LaTexParticle' import { defaultCheckboxOption } from '../dataset/constant/Checkbox' -import { ZERO } from '../dataset/constant/Common' +import { NON_BREAKING_SPACE, ZERO } from '../dataset/constant/Common' import { defaultControlOption } from '../dataset/constant/Control' import { EDITOR_ELEMENT_CONTEXT_ATTR, @@ -697,6 +697,9 @@ export function convertElementToDom( if (element.highlight) { dom.style.backgroundColor = element.highlight } + if (element.underline) { + dom.style.textDecoration = 'underline' + } dom.innerText = element.value.replace(new RegExp(`${ZERO}`, 'g'), '\n') return dom } @@ -811,6 +814,10 @@ export function createDomFromElementList( checkbox.setAttribute('checked', 'true') } clipboardDom.append(checkbox) + } else if (element.type === ElementType.TAB) { + const tab = document.createElement('span') + tab.innerHTML = `${NON_BREAKING_SPACE}${NON_BREAKING_SPACE}` + clipboardDom.append(tab) } else if ( !element.type || element.type === ElementType.LATEX || @@ -873,6 +880,10 @@ export function convertTextNodeToElement( if (style.backgroundColor !== 'rgba(0, 0, 0, 0)') { element.highlight = style.backgroundColor } + // 下划线 + if (style.textDecorationLine === 'underline') { + element.underline = true + } return element }