feat(html-parser): allow passing Longs to interpolate
This commit is contained in:
parent
7a6d984977
commit
9ff8f9d33f
2 changed files with 14 additions and 3 deletions
|
@ -501,6 +501,14 @@ describe('HtmlMessageEntityParser', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('should handle numbers and Longs', () => {
|
||||
test(
|
||||
htm`a number ${123123} and a long ${Long.fromNumber(456456)}`,
|
||||
[],
|
||||
'a number 123123 and a long 456456',
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle interpolation into attrs', () => {
|
||||
test(
|
||||
htm`<a href="${'https'}://example.com/"${'foo'}/bar/${'baz'}?foo=bar&baz=${'egg'}">link</a>`,
|
||||
|
@ -526,7 +534,7 @@ describe('HtmlMessageEntityParser', () => {
|
|||
'user',
|
||||
)
|
||||
test(
|
||||
htm`<tg-emoji id="${'123123123123'}">🚀</tg-emoji>`,
|
||||
htm`<tg-emoji id="${Long.fromString('123123123123')}">🚀</tg-emoji>`,
|
||||
[
|
||||
createEntity('messageEntityCustomEmoji', 0, 2, {
|
||||
documentId: Long.fromString('123123123123'),
|
||||
|
|
|
@ -20,7 +20,7 @@ function escape(str: string, quote = false): string {
|
|||
|
||||
function parse(
|
||||
strings: TemplateStringsArray | string,
|
||||
...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]
|
||||
...sub: (InputText | MessageEntity | Long | boolean | number | undefined | null)[]
|
||||
): TextWithEntities {
|
||||
const stacks: Record<string, tl.Mutable<tl.TypeMessageEntity>[]> = {}
|
||||
const entities: tl.TypeMessageEntity[] = []
|
||||
|
@ -250,6 +250,7 @@ function parse(
|
|||
|
||||
if (typeof it === 'string') text = it
|
||||
else if (typeof it === 'number') text = it.toString()
|
||||
else if (Long.isLong(it)) text = it.toString(10)
|
||||
else {
|
||||
// obviously we can't have entities inside attributes, so just use the text
|
||||
text = it.text
|
||||
|
@ -261,6 +262,8 @@ function parse(
|
|||
|
||||
if (typeof it === 'string' || typeof it === 'number') {
|
||||
pendingText += it
|
||||
} else if (Long.isLong(it)) {
|
||||
pendingText += it.toString(10)
|
||||
} else {
|
||||
// TextWithEntities or MessageEntity
|
||||
const text = it.text
|
||||
|
@ -451,7 +454,7 @@ export const html: {
|
|||
*/
|
||||
(
|
||||
strings: TemplateStringsArray,
|
||||
...sub: (InputText | MessageEntity | boolean | number | undefined | null)[]
|
||||
...sub: (InputText | MessageEntity | boolean | Long | number | undefined | null)[]
|
||||
): TextWithEntities
|
||||
/**
|
||||
* A variant taking a plain JS string as input
|
||||
|
|
Loading…
Reference in a new issue