Skip to content
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
34 changes: 34 additions & 0 deletions packages/frontend/core/src/blocksuite/utils/markdown-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'fake-indexeddb/auto';

import { getStoreManager } from '@affine/core/blocksuite/manager/store';
import { Text } from '@blocksuite/affine/store';
import { TestWorkspace } from '@blocksuite/affine/store/test';
import { describe, expect, test } from 'vitest';

import { insertFromMarkdown } from './markdown-utils';

const extensions = getStoreManager().config.init().value.get('store');

describe('markdown-utils', () => {
test('insertFromMarkdown does not create docs in the target workspace', async () => {
const collection = new TestWorkspace({ id: 'test' });
collection.meta.initialize();

const store = collection.createDoc('page0').getStore({ extensions });
store.load();
const rootId = store.addBlock('affine:page', {
title: new Text(''),
});
const noteId = store.addBlock('affine:note', {}, rootId);

await insertFromMarkdown(
undefined,
['- Summary item', '## Decisions', '- Ship it'].join('\n'),
store,
noteId,
0
);

expect(collection.meta.docMetas.map(meta => meta.id)).toEqual(['page0']);
});
});
25 changes: 2 additions & 23 deletions packages/frontend/core/src/blocksuite/utils/markdown-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,10 @@ export const markdownToSnapshot = async (
pageId: store.id,
};

const page = await markdownAdapter.toDoc(payload);

if (page) {
const pageSnapshot = transformer.docToSnapshot(page);
if (pageSnapshot) {
const snapshot: SliceSnapshot = {
type: 'slice',
content: [
pageSnapshot.blocks.children.find(
b => b.flavour === 'affine:note'
) as BlockSnapshot,
],
workspaceId: payload.workspaceId,
pageId: payload.pageId,
};

return {
snapshot,
transformer,
};
}
}
const snapshot = await markdownAdapter.toSliceSnapshot(payload);

return {
snapshot: null,
snapshot,
transformer,
};
};
Expand Down
Loading