refactor(editor): extract markdown adapter (#9443)

This commit is contained in:
Saul-Mirone
2024-12-31 04:13:02 +00:00
parent adf14d11d5
commit 09427e846e
25 changed files with 333 additions and 181 deletions
@@ -5,7 +5,13 @@ import type {
EmbedBlockModel,
ImageBlockModel,
} from '@blocksuite/affine/blocks';
import { MarkdownAdapter } from '@blocksuite/affine/blocks';
import {
defaultBlockMarkdownAdapterMatchers,
inlineDeltaToMarkdownAdapterMatchers,
MarkdownAdapter,
markdownInlineToDeltaMatchers,
} from '@blocksuite/affine/blocks';
import { Container } from '@blocksuite/affine/global/di';
import {
createYProxy,
DocCollection,
@@ -174,11 +180,22 @@ function generateMarkdownPreviewBuilder(
adapterConfigs.set('docLinkBaseUrl', baseUrl);
};
const container = new Container();
[
...markdownInlineToDeltaMatchers,
...defaultBlockMarkdownAdapterMatchers,
...inlineDeltaToMarkdownAdapterMatchers,
].forEach(ext => {
ext.setup(container);
});
const provider = container.provider();
const markdownAdapter = new MarkdownAdapter(
new Job({
collection: markdownPreviewDocCollection,
middlewares: [docLinkBaseURLMiddleware, titleMiddleware],
})
}),
provider
);
const markdownPreviewCache = new WeakMap<BlockDocumentInfo, string | null>();