diff --git a/packages/html-parser/src/html-parser.test.ts b/packages/html-parser/src/html-parser.test.ts index 85c8735b..9e40f636 100644 --- a/packages/html-parser/src/html-parser.test.ts +++ b/packages/html-parser/src/html-parser.test.ts @@ -361,6 +361,14 @@ describe('HtmlMessageEntityParser', () => { test(htm`hewwo ${htm`
`} world`, [], 'hewwo \nworld') }) + it('should keep whitespaces in raw strings', () => { + const dot = ' ∙ ' + const lf = '\n' + test(htm`this is${dot}some text${lf}xd`, [], 'this is ∙ some text\nxd') + + test(htm`hewwo ${htm`
`} world`, [], 'hewwo \nworld') + }) + it('should not ignore newlines and indentation in pre', () => { test( htm`
this is some text\n\nwith newlines
`, diff --git a/packages/html-parser/src/index.ts b/packages/html-parser/src/index.ts index d5d16861..bdb6e584 100644 --- a/packages/html-parser/src/index.ts +++ b/packages/html-parser/src/index.ts @@ -262,9 +262,11 @@ function parse( return } - if (typeof it === 'string' || typeof it === 'number') { + if (typeof it === 'string') { + processPendingText() pendingText += it - } else if (Long.isLong(it)) { + processPendingText(false, true) + } else if (Long.isLong(it) || typeof it === 'number') { pendingText += it.toString(10) } else { // TextWithEntities or MessageEntity