fix(html): keep whitespaces in raw text
This commit is contained in:
parent
d3ceed84d5
commit
869d5987c7
2 changed files with 12 additions and 2 deletions
|
@ -341,6 +341,14 @@ describe('HtmlMessageEntityParser', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should keep whitespaces in raw text', () => {
|
||||||
|
const dot = { text: ' ∙ ' }
|
||||||
|
const lf = { text: '\n' }
|
||||||
|
test(htm`this is${dot}some text${lf}xd`, [], 'this is ∙ some text\nxd')
|
||||||
|
|
||||||
|
test(htm`hewwo ${htm`<br>`} world`, [], 'hewwo \nworld')
|
||||||
|
})
|
||||||
|
|
||||||
it('should not ignore newlines and indentation in pre', () => {
|
it('should not ignore newlines and indentation in pre', () => {
|
||||||
test(
|
test(
|
||||||
htm`<pre>this is some text\n\nwith newlines</pre>`,
|
htm`<pre>this is some text\n\nwith newlines</pre>`,
|
||||||
|
|
|
@ -27,10 +27,10 @@ function parse(
|
||||||
let plainText = ''
|
let plainText = ''
|
||||||
let pendingText = ''
|
let pendingText = ''
|
||||||
|
|
||||||
function processPendingText(tagEnd = false) {
|
function processPendingText(tagEnd = false, keepWhitespace = false) {
|
||||||
if (!pendingText.length) return
|
if (!pendingText.length) return
|
||||||
|
|
||||||
if (!stacks.pre?.length) {
|
if (!stacks.pre?.length && !keepWhitespace) {
|
||||||
pendingText = pendingText.replace(/[^\S\u00A0]+/gs, ' ')
|
pendingText = pendingText.replace(/[^\S\u00A0]+/gs, ' ')
|
||||||
|
|
||||||
if (tagEnd) pendingText = pendingText.trimEnd()
|
if (tagEnd) pendingText = pendingText.trimEnd()
|
||||||
|
@ -237,6 +237,8 @@ function parse(
|
||||||
entities.push({ ...ent, offset: ent.offset + baseOffset })
|
entities.push({ ...ent, offset: ent.offset + baseOffset })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processPendingText(false, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue