fix(editor): skip user avatars when importing Notion HTML (#15899)

Notion exports person values as `<img class="icon user-icon">`. 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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: DarkSky <darksky2048@gmail.com>
This commit is contained in:
CommaBotandDarkSky authored and GitHub committed 2026-11-23 23:04:48 +08:00
1 parent 872451073b
commit 7ee31d9173
2 files changed
+40 -4

No files matched your search

@@ -1263,6 +1263,37 @@ describe('notion html to snapshot', () => {
});
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
});
const userAvatar = `<span class="user"><img src="${originalUrl}" class="icon user-icon" />Alice</span>`;
test.each([
{
location: 'a database person cell',
body: `<table class="collection-content">
<thead><tr><th>Name</th><th>Person</th></tr></thead>
<tbody><tr><td class="cell-title"><a>Row</a></td><td>${userAvatar}</td></tr></tbody>
</table>`,
},
{
location: 'a paragraph',
body: `<p>${userAvatar}</p>`,
},
])(
'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: `<div class="page-body">${body}</div>`,
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 () => {
@@ -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,