fix: error converting some element types to HTML #257

This commit is contained in:
Hufe921
2023-08-21 21:42:07 +08:00
parent 9495bfef39
commit a805590696
2 changed files with 13 additions and 1 deletions
+1
View File
@@ -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 = [
'·',
'、',
+12 -1
View File
@@ -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
}