diff --git a/apps/web/src/components/affine/operation-menu-items/Export.tsx b/apps/web/src/components/affine/operation-menu-items/Export.tsx index 45d0ced54c..ecfd17ed90 100644 --- a/apps/web/src/components/affine/operation-menu-items/Export.tsx +++ b/apps/web/src/components/affine/operation-menu-items/Export.tsx @@ -1,11 +1,13 @@ import { Menu, MenuItem } from '@affine/component'; import { useTranslation } from '@affine/i18n'; +import { ContentParser } from '@blocksuite/blocks/content-parser'; import { ArrowRightSmallIcon, ExportIcon, ExportToHtmlIcon, ExportToMarkdownIcon, } from '@blocksuite/icons'; +import { useRef } from 'react'; import type { CommonMenuItemProps } from './types'; @@ -14,7 +16,7 @@ export const Export = ({ onItemClick, }: CommonMenuItemProps<{ type: 'markdown' | 'html' }>) => { const { t } = useTranslation(); - + const contentParserRef = useRef(); return ( { - // @ts-expect-error - globalThis.currentEditor.contentParser.onExportHtml(); + if (!contentParserRef.current) { + contentParserRef.current = new ContentParser( + globalThis.currentEditor!.page + ); + } + contentParserRef.current.onExportHtml(); onSelect?.({ type: 'html' }); }} icon={} @@ -33,9 +40,14 @@ export const Export = ({ {t('Export to HTML')} { - // @ts-expect-error - globalThis.currentEditor.contentParser.onExportMarkdown(); + if (!contentParserRef.current) { + contentParserRef.current = new ContentParser( + globalThis.currentEditor!.page + ); + } + contentParserRef.current.onExportMarkdown(); onSelect?.({ type: 'markdown' }); }} icon={} @@ -46,6 +58,7 @@ export const Export = ({ } > } endIcon={} onClick={e => { diff --git a/tests/parallels/local-first-favorite-page.spec.ts b/tests/parallels/local-first-favorite-page.spec.ts index 785a9152bc..e03be1fb3e 100644 --- a/tests/parallels/local-first-favorite-page.spec.ts +++ b/tests/parallels/local-first-favorite-page.spec.ts @@ -29,6 +29,27 @@ test.describe('Local first favorite and cancel favorite page', () => { await favoriteBtn.click(); await assertCurrentWorkspaceFlavour('local', page); }); + + test('Export to html and markdown', async ({ page }) => { + await openHomePage(page); + await waitMarkdownImported(page); + { + await clickPageMoreActions(page); + await page.getByTestId('export-menu').click(); + const downloadPromise = page.waitForEvent('download'); + await page.getByTestId('export-to-markdown').click(); + await downloadPromise; + } + await page.waitForTimeout(50); + { + await clickPageMoreActions(page); + await page.getByTestId('export-menu').click(); + const downloadPromise = page.waitForEvent('download'); + await page.getByTestId('export-to-html').click(); + await downloadPromise; + } + }); + test('Cancel favorite', async ({ page }) => { await openHomePage(page); await waitMarkdownImported(page);