mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-21 03:51:45 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { BookmarkBlockSchema } from '@blocksuite/affine-model';
|
|
import {
|
|
BlockNotionHtmlAdapterExtension,
|
|
type BlockNotionHtmlAdapterMatcher,
|
|
HastUtils,
|
|
} from '@blocksuite/affine-shared/adapters';
|
|
import { nanoid } from '@blocksuite/store';
|
|
|
|
export const bookmarkBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher =
|
|
{
|
|
flavour: BookmarkBlockSchema.model.flavour,
|
|
toMatch: o => {
|
|
return (
|
|
HastUtils.isElement(o.node) &&
|
|
o.node.tagName === 'figure' &&
|
|
!!HastUtils.querySelector(o.node, '.bookmark')
|
|
);
|
|
},
|
|
fromMatch: () => false,
|
|
toBlockSnapshot: {
|
|
enter: (o, context) => {
|
|
if (!HastUtils.isElement(o.node)) {
|
|
return;
|
|
}
|
|
const bookmark = HastUtils.querySelector(o.node, '.bookmark');
|
|
if (!bookmark) {
|
|
return;
|
|
}
|
|
|
|
const { walkerContext } = context;
|
|
const bookmarkURL = bookmark.properties?.href;
|
|
const bookmarkTitle = HastUtils.getTextContent(
|
|
HastUtils.querySelector(bookmark, '.bookmark-title')
|
|
);
|
|
const bookmarkDescription = HastUtils.getTextContent(
|
|
HastUtils.querySelector(bookmark, '.bookmark-description')
|
|
);
|
|
const bookmarkIcon = HastUtils.querySelector(
|
|
bookmark,
|
|
'.bookmark-icon'
|
|
);
|
|
const bookmarkIconURL =
|
|
typeof bookmarkIcon?.properties?.src === 'string'
|
|
? bookmarkIcon.properties.src
|
|
: '';
|
|
walkerContext
|
|
.openNode(
|
|
{
|
|
type: 'block',
|
|
id: nanoid(),
|
|
flavour: BookmarkBlockSchema.model.flavour,
|
|
props: {
|
|
type: 'card',
|
|
url: bookmarkURL ?? '',
|
|
title: bookmarkTitle,
|
|
description: bookmarkDescription,
|
|
icon: bookmarkIconURL,
|
|
},
|
|
children: [],
|
|
},
|
|
'children'
|
|
)
|
|
.closeNode();
|
|
walkerContext.skipAllChildren();
|
|
},
|
|
},
|
|
fromBlockSnapshot: {},
|
|
};
|
|
|
|
export const BookmarkBlockNotionHtmlAdapterExtension =
|
|
BlockNotionHtmlAdapterExtension(bookmarkBlockNotionHtmlAdapterMatcher);
|