From 7ee31d9173fb9516cda2fd7b89f8b24a6f738c19 Mon Sep 17 00:00:00 2001 From: CommaBot Date: Mon, 23 Nov 2026 23:04:48 +0800 Subject: [PATCH] fix(editor): skip user avatars when importing Notion HTML (#15899) Notion exports person values as ``. The image matcher accepted every `img`, so each avatar was imported as a full-size image block above the database or paragraph. The matcher now skips images with the `user-icon` class. The person's name is still imported. fix #13703 ## Summary by CodeRabbit * **Bug Fixes** * Notion user avatars in database person cells and paragraphs are no longer imported as image blocks. Regular images and figures containing images continue to be recognized during import. Co-authored-by: DarkSky --- .../adapters/notion-html.unit.spec.ts | 31 +++++++++++++++++++ .../blocks/image/src/adapters/notion-html.ts | 13 +++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/blocksuite/affine/all/src/__tests__/adapters/notion-html.unit.spec.ts b/blocksuite/affine/all/src/__tests__/adapters/notion-html.unit.spec.ts index 8dbd196aa2..16a6015ff1 100644 --- a/blocksuite/affine/all/src/__tests__/adapters/notion-html.unit.spec.ts +++ b/blocksuite/affine/all/src/__tests__/adapters/notion-html.unit.spec.ts @@ -1263,6 +1263,37 @@ describe('notion html to snapshot', () => { }); expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot); }); + + const userAvatar = `Alice`; + + test.each([ + { + location: 'a database person cell', + body: ` + + +
NamePerson
Row${userAvatar}
`, + }, + { + location: 'a paragraph', + body: `

${userAvatar}

`, + }, + ])( + 'does not import a user avatar in $location as an image', + async ({ body }) => { + const adapter = new NotionHtmlAdapter(createJob(), provider); + const snapshot = await adapter.toBlockSnapshot({ + file: `
${body}
`, + assets: new AssetsManager({ blob: new MemoryBlobCRUD() }), + }); + + const flavours = (block: BlockSnapshot): string[] => [ + block.flavour, + ...block.children.flatMap(flavours), + ]; + expect(flavours(snapshot)).not.toContain('affine:image'); + } + ); }); test('bookmark', async () => { diff --git a/blocksuite/affine/blocks/image/src/adapters/notion-html.ts b/blocksuite/affine/blocks/image/src/adapters/notion-html.ts index 9af231ca1a..8a4343ac05 100644 --- a/blocksuite/affine/blocks/image/src/adapters/notion-html.ts +++ b/blocksuite/affine/blocks/image/src/adapters/notion-html.ts @@ -11,11 +11,16 @@ export const imageBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher = { flavour: ImageBlockSchema.model.flavour, toMatch: o => { + if (!HastUtils.isElement(o.node)) { + return false; + } + if (o.node.tagName === 'img') { + const className = o.node.properties.className; + return !(Array.isArray(className) && className.includes('user-icon')); + } return ( - HastUtils.isElement(o.node) && - (o.node.tagName === 'img' || - (o.node.tagName === 'figure' && - !!HastUtils.querySelector(o.node, '.image'))) + o.node.tagName === 'figure' && + !!HastUtils.querySelector(o.node, '.image') ); }, fromMatch: () => false,