Skip to content

Commit

Permalink
fix: error converting some element types to HTML #257
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Aug 21, 2023
1 parent 9495bfe commit a805590
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/editor/dataset/constant/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'·',
'、',
Expand Down
13 changes: 12 additions & 1 deletion src/editor/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a805590

Please sign in to comment.