This is a sample HTML content
+diff --git a/blocksuite/affine/all/src/__tests__/adapters/markdown.unit.spec.ts b/blocksuite/affine/all/src/__tests__/adapters/markdown.unit.spec.ts index b6a4a36fe..1b4a6b373 100644 --- a/blocksuite/affine/all/src/__tests__/adapters/markdown.unit.spec.ts +++ b/blocksuite/affine/all/src/__tests__/adapters/markdown.unit.spec.ts @@ -2448,203 +2448,262 @@ World! }); describe('markdown to snapshot', () => { - test('code', async () => { - const markdown = '```python\nimport this\n```\n'; + describe('code', () => { + test('markdown code block', async () => { + const markdown = '```python\nimport this\n```\n'; - const blockSnapshot: BlockSnapshot = { - type: 'block', - id: 'matchesReplaceMap[0]', - flavour: 'affine:note', - props: { - xywh: '[0,0,800,95]', - background: DefaultTheme.noteBackgrounColor, - index: 'a0', - hidden: false, - displayMode: NoteDisplayMode.DocAndEdgeless, - }, - children: [ - { - type: 'block', - id: 'matchesReplaceMap[1]', - flavour: 'affine:code', - props: { - language: 'python', - wrap: false, - text: { - '$blocksuite:internal:text$': true, - delta: [ - { - insert: 'import this', - }, - ], - }, - }, - children: [], + const blockSnapshot: BlockSnapshot = { + type: 'block', + id: 'matchesReplaceMap[0]', + flavour: 'affine:note', + props: { + xywh: '[0,0,800,95]', + background: DefaultTheme.noteBackgrounColor, + index: 'a0', + hidden: false, + displayMode: NoteDisplayMode.DocAndEdgeless, }, - ], - }; - - const mdAdapter = new MarkdownAdapter(createJob(), provider); - const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({ - file: markdown, - }); - expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot); - }); - - test('code with indentation 1 - slice', async () => { - const markdown = '```python\n import this\n```'; - - const sliceSnapshot: SliceSnapshot = { - type: 'slice', - content: [ - { - type: 'block', - id: 'matchesReplaceMap[0]', - flavour: 'affine:note', - props: { - xywh: '[0,0,800,95]', - background: DefaultTheme.noteBackgrounColor, - index: 'a0', - hidden: false, - displayMode: 'both', - }, - children: [ - { - type: 'block', - id: 'matchesReplaceMap[1]', - flavour: 'affine:code', - props: { - language: 'python', - wrap: false, - text: { - '$blocksuite:internal:text$': true, - delta: [ - { - insert: ' import this', - }, - ], - }, + children: [ + { + type: 'block', + id: 'matchesReplaceMap[1]', + flavour: 'affine:code', + props: { + language: 'python', + wrap: false, + text: { + '$blocksuite:internal:text$': true, + delta: [ + { + insert: 'import this', + }, + ], }, - children: [], }, - ], - }, - ], - workspaceId: '', - pageId: '', - }; - - const mdAdapter = new MarkdownAdapter(createJob(), provider); - const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ - file: markdown, - workspaceId: '', - pageId: '', - }); - expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot); - }); - - test('code with indentation 2 - slice', async () => { - const markdown = '````python\n```python\n import this\n```\n````'; - - const sliceSnapshot: SliceSnapshot = { - type: 'slice', - content: [ - { - type: 'block', - id: 'matchesReplaceMap[0]', - flavour: 'affine:note', - props: { - xywh: '[0,0,800,95]', - background: DefaultTheme.noteBackgrounColor, - index: 'a0', - hidden: false, - displayMode: 'both', + children: [], }, - children: [ - { - type: 'block', - id: 'matchesReplaceMap[1]', - flavour: 'affine:code', - props: { - language: 'python', - wrap: false, - text: { - '$blocksuite:internal:text$': true, - delta: [ - { - insert: '```python\n import this\n```', - }, - ], - }, - }, - children: [], - }, - ], - }, - ], - workspaceId: '', - pageId: '', - }; + ], + }; - const mdAdapter = new MarkdownAdapter(createJob(), provider); - const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ - file: markdown, - workspaceId: '', - pageId: '', + const mdAdapter = new MarkdownAdapter(createJob(), provider); + const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({ + file: markdown, + }); + expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot); }); - expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot); - }); - test('code with indentation 3 - slice', async () => { - const markdown = '~~~~python\n````python\n import this\n````\n~~~~'; + test('code with indentation 1 - slice', async () => { + const markdown = '```python\n import this\n```'; - const sliceSnapshot: SliceSnapshot = { - type: 'slice', - content: [ - { - type: 'block', - id: 'matchesReplaceMap[0]', - flavour: 'affine:note', - props: { - xywh: '[0,0,800,95]', - background: DefaultTheme.noteBackgrounColor, - index: 'a0', - hidden: false, - displayMode: 'both', + const sliceSnapshot: SliceSnapshot = { + type: 'slice', + content: [ + { + type: 'block', + id: 'matchesReplaceMap[0]', + flavour: 'affine:note', + props: { + xywh: '[0,0,800,95]', + background: DefaultTheme.noteBackgrounColor, + index: 'a0', + hidden: false, + displayMode: 'both', + }, + children: [ + { + type: 'block', + id: 'matchesReplaceMap[1]', + flavour: 'affine:code', + props: { + language: 'python', + wrap: false, + text: { + '$blocksuite:internal:text$': true, + delta: [ + { + insert: ' import this', + }, + ], + }, + }, + children: [], + }, + ], }, - children: [ - { - type: 'block', - id: 'matchesReplaceMap[1]', - flavour: 'affine:code', - props: { - language: 'python', - wrap: false, - text: { - '$blocksuite:internal:text$': true, - delta: [ - { - insert: '````python\n import this\n````', - }, - ], - }, - }, - children: [], - }, - ], - }, - ], - workspaceId: '', - pageId: '', - }; + ], + workspaceId: '', + pageId: '', + }; - const mdAdapter = new MarkdownAdapter(createJob(), provider); - const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ - file: markdown, - workspaceId: '', - pageId: '', + const mdAdapter = new MarkdownAdapter(createJob(), provider); + const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ + file: markdown, + workspaceId: '', + pageId: '', + }); + expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot); + }); + + test('code with indentation 2 - slice', async () => { + const markdown = '````python\n```python\n import this\n```\n````'; + + const sliceSnapshot: SliceSnapshot = { + type: 'slice', + content: [ + { + type: 'block', + id: 'matchesReplaceMap[0]', + flavour: 'affine:note', + props: { + xywh: '[0,0,800,95]', + background: DefaultTheme.noteBackgrounColor, + index: 'a0', + hidden: false, + displayMode: 'both', + }, + children: [ + { + type: 'block', + id: 'matchesReplaceMap[1]', + flavour: 'affine:code', + props: { + language: 'python', + wrap: false, + text: { + '$blocksuite:internal:text$': true, + delta: [ + { + insert: '```python\n import this\n```', + }, + ], + }, + }, + children: [], + }, + ], + }, + ], + workspaceId: '', + pageId: '', + }; + + const mdAdapter = new MarkdownAdapter(createJob(), provider); + const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ + file: markdown, + workspaceId: '', + pageId: '', + }); + expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot); + }); + + test('code with indentation 3 - slice', async () => { + const markdown = '~~~~python\n````python\n import this\n````\n~~~~'; + + const sliceSnapshot: SliceSnapshot = { + type: 'slice', + content: [ + { + type: 'block', + id: 'matchesReplaceMap[0]', + flavour: 'affine:note', + props: { + xywh: '[0,0,800,95]', + background: DefaultTheme.noteBackgrounColor, + index: 'a0', + hidden: false, + displayMode: 'both', + }, + children: [ + { + type: 'block', + id: 'matchesReplaceMap[1]', + flavour: 'affine:code', + props: { + language: 'python', + wrap: false, + text: { + '$blocksuite:internal:text$': true, + delta: [ + { + insert: '````python\n import this\n````', + }, + ], + }, + }, + children: [], + }, + ], + }, + ], + workspaceId: '', + pageId: '', + }; + + const mdAdapter = new MarkdownAdapter(createJob(), provider); + const rawSliceSnapshot = await mdAdapter.toSliceSnapshot({ + file: markdown, + workspaceId: '', + pageId: '', + }); + expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot); + }); + + test('html block import as code block', async () => { + const markdown = `
This is a sample HTML content
+This is a sample HTML content
\n