Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(editor): extract notion html adapter to shared #9341

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blocksuite/affine/shared/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export {
BlockNotionHtmlAdapterMatcherIdentifier,
type InlineDeltaToNotionHtmlAdapterMatcher,
type NotionHtml,
NotionHtmlAdapter,
NotionHtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryIdentifier,
NotionHtmlASTToDeltaExtension,
type NotionHtmlASTToDeltaMatcher,
NotionHtmlASTToDeltaMatcherIdentifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './block-adapter.js';
export * from './delta-converter.js';
export * from './type.js';
export * from './notion-html.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import {
DEFAULT_NOTE_BACKGROUND_COLOR,
NoteDisplayMode,
} from '@blocksuite/affine-model';
import {
type AdapterContext,
AdapterFactoryIdentifier,
type BlockNotionHtmlAdapterMatcher,
BlockNotionHtmlAdapterMatcherIdentifier,
HastUtils,
type HtmlAST,
type NotionHtml,
NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter,
} from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std';
import type { ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
Expand All @@ -35,6 +24,23 @@ import {
import rehypeParse from 'rehype-parse';
import { unified } from 'unified';

import {
type AdapterContext,
AdapterFactoryIdentifier,
} from '../types/adapter';
import type { HtmlAST } from '../types/hast';
import { HastUtils } from '../utils/hast';
import {
type BlockNotionHtmlAdapterMatcher,
BlockNotionHtmlAdapterMatcherIdentifier,
} from './block-adapter';
import {
NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter,
} from './delta-converter';

export type NotionHtml = string;

type NotionHtmlToSliceSnapshotPayload = {
file: NotionHtml;
assets?: AssetsManager;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
DEFAULT_NOTE_BACKGROUND_COLOR,
NoteDisplayMode,
} from '@blocksuite/affine-model';
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import {
AssetsManager,
Expand All @@ -12,7 +13,6 @@ import { describe, expect, test } from 'vitest';

import { defaultBlockNotionHtmlAdapterMatchers } from '../../_common/adapters/notion-html/block-matcher.js';
import { notionHtmlInlineToDeltaMatchers } from '../../_common/adapters/notion-html/delta-converter/html-inline.js';
import { NotionHtmlAdapter } from '../../_common/adapters/notion-html/notion-html.js';
import { nanoidReplacement } from '../../_common/test-utils/test-utils.js';
import { createJob } from '../utils/create-job.js';

Expand Down
2 changes: 1 addition & 1 deletion blocksuite/blocks/src/_common/adapters/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
HtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryExtension,
PlainTextAdapterFactoryExtension,
} from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std';
Expand All @@ -11,7 +12,6 @@ import { ImageAdapterFactoryExtension } from './image.js';
import { MarkdownAdapterFactoryExtension } from './markdown/markdown.js';
import { MixTextAdapterFactoryExtension } from './mix-text.js';
import { notionHtmlInlineToDeltaMatchers } from './notion-html/delta-converter/html-inline.js';
import { NotionHtmlAdapterFactoryExtension } from './notion-html/notion-html.js';
import { NotionTextAdapterFactoryExtension } from './notion-text.js';
import { inlineDeltaToPlainTextAdapterMatchers } from './plain-text/delta-converter/inline-delta.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export { defaultBlockNotionHtmlAdapterMatchers } from './block-matcher.js';
export {
NotionHtmlAdapter,
NotionHtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryIdentifier,
} from './notion-html.js';
export { notionHtmlInlineToDeltaMatchers } from './delta-converter/html-inline.js';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import { sha } from '@blocksuite/global/utils';
import { type DocCollection, extMimeMap, Job } from '@blocksuite/store';

import { defaultBlockNotionHtmlAdapterMatchers } from '../adapters/notion-html/block-matcher.js';
import { notionHtmlInlineToDeltaMatchers } from '../adapters/notion-html/delta-converter/html-inline.js';
import { NotionHtmlAdapter } from '../adapters/notion-html/notion-html.js';
import { defaultImageProxyMiddleware } from './middlewares.js';
import { Unzip } from './utils.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '@shoelace-style/shoelace/dist/themes/dark.css';
import './left-side-panel.js';
import './side-panel.js';

import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
import { ShadowlessElement } from '@blocksuite/block-std';
import {
Expand All @@ -35,7 +36,6 @@ import {
HtmlTransformer,
MarkdownAdapterFactoryIdentifier,
MarkdownTransformer,
NotionHtmlAdapter,
NotionHtmlTransformer,
openFileOrFiles,
PlainTextAdapterFactoryIdentifier,
Expand Down Expand Up @@ -435,7 +435,7 @@ export class StarterDebugMenu extends ShadowlessElement {
collection: this.collection,
middlewares: [defaultImageProxyMiddleware],
});
const htmlAdapter = new NotionHtmlAdapter(job);
const htmlAdapter = new NotionHtmlAdapter(job, this.editor.std.provider);
await htmlAdapter.toDoc({
file: await file.text(),
pageId: this.collection.idGenerator(),
Expand Down
Loading