Adds new HTMLBlock component (#36262)

This commit is contained in:
Echo 2025-09-26 11:50:59 +02:00 committed by GitHub
commit e07b9dfdc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 260 additions and 79 deletions

View file

@ -48,7 +48,7 @@ describe('html', () => {
const input = '<p>lorem ipsum</p>';
const onText = vi.fn((text: string) => text);
html.htmlStringToComponents(input, { onText });
expect(onText).toHaveBeenCalledExactlyOnceWith('lorem ipsum');
expect(onText).toHaveBeenCalledExactlyOnceWith('lorem ipsum', {});
});
it('calls onElement callback', () => {
@ -61,6 +61,7 @@ describe('html', () => {
expect(onElement).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ tagName: 'P' }),
expect.arrayContaining(['lorem ipsum']),
{},
);
});
@ -71,6 +72,7 @@ describe('html', () => {
expect(onElement).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ tagName: 'P' }),
expect.arrayContaining(['lorem ipsum']),
{},
);
expect(output).toMatchSnapshot();
});
@ -88,15 +90,16 @@ describe('html', () => {
'href',
'https://example.com',
'a',
{},
);
expect(onAttribute).toHaveBeenCalledWith('target', '_blank', 'a');
expect(onAttribute).toHaveBeenCalledWith('rel', 'nofollow', 'a');
expect(onAttribute).toHaveBeenCalledWith('target', '_blank', 'a', {});
expect(onAttribute).toHaveBeenCalledWith('rel', 'nofollow', 'a', {});
});
it('respects allowedTags option', () => {
const input = '<p>lorem <strong>ipsum</strong> <em>dolor</em></p>';
const output = html.htmlStringToComponents(input, {
allowedTags: new Set(['p', 'em']),
allowedTags: { p: {}, em: {} },
});
expect(output).toMatchSnapshot();
});