🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
feat: Export to markdown
Rene Wanga784b73685c8
diff --git a/src/features/PageEditor/Header/useMenu.tsx b/src/features/PageEditor/Header/useMenu.tsxindex 9e8d4d81f27..b6809d8da15 100644--- a/src/features/PageEditor/Header/useMenu.tsx+++ b/src/features/PageEditor/Header/useMenu.tsx@@ -1,11 +1,12 @@import { Flexbox, Icon } from '@lobehub/ui';-import { App } from 'antd';+import { App, Switch } from 'antd';import { useResponsive, useTheme } from 'antd-style';import dayjs from 'dayjs';-import { Link2, PanelLeftRightDashedIcon, SquareChartGanttIcon, Trash2 } from 'lucide-react';+import { CopyPlus, Download, Link2, Trash2 } from 'lucide-react';import { useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { useFileStore } from '@/store/file';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';@@ -20,6 +21,9 @@ export const useMenu = (): { menuItems: any[] } => {const lastUpdatedTime = usePageEditorStore((s) => s.lastUpdatedTime);const wordCount = usePageEditorStore((s) => s.wordCount);+ const currentDocId = usePageEditorStore((s) => s.currentDocId);++ const duplicateDocument = useFileStore((s) => s.duplicateDocument);const [wideScreen, toggleWideScreen] = useGlobalStore((s) => [systemStatusSelectors.wideScreen(s),@@ -29,67 +33,58 @@ export const useMenu = (): { menuItems: any[] } => {// Wide screen mode only makes sense when screen is large enoughconst showViewModeSwitch = lg;+ const handleDuplicate = async () => {+ if (!currentDocId) return;+ try {+ await duplicateDocument(currentDocId);+ message.success(t('pageEditor.duplicateSuccess'));+ } catch (error) {+ console.error('Failed to duplicate page:', error);+ message.error(t('pageEditor.duplicateError'));+ }+ };++ const handleExportMarkdown = () => {+ const state = storeApi.getState();+ const { editor, currentTitle } = state;++ if (!editor) return;++ try {+ const markdown = (editor.getDocument('markdown') as unknown as string) || '';+ const blob = new Blob([markdown], { type: 'text/markdown' });+ const url = URL.createObjectURL(blob);+ const a = document.createElement('a');+ a.href = url;+ a.download = `${currentTitle || 'Untitled'}.md`;+ document.body.appendChild(a);+ a.click();+ document.body.removeChild(a);+ URL.revokeObjectURL(url);+ message.success(t('pageEditor.exportSuccess'));+ } catch (error) {+ console.error('Failed to export markdown:', error);+ message.error(t('pageEditor.exportError'));+ }+ };+const menuItems = useMemo(() => [...(showViewModeSwitch? [{- disabled: true,- key: 'view-mode',+ key: 'full-width',label: (- <Flexbox gap={8} horizontal>- <Flexbox- align="center"- gap={4}- onClick={() => {- if (wideScreen) toggleWideScreen();- }}- style={{- backgroundColor: !wideScreen ? theme.colorFillSecondary : 'transparent',- borderRadius: theme.borderRadius,- cursor: 'pointer',- flex: 1,- padding: '8px 12px',- pointerEvents: 'auto',- transition: `background-color ${theme.motionDurationMid}`,- }}- >- <Icon icon={PanelLeftRightDashedIcon} size={20} />- <span- style={{- color: !wideScreen ? theme.colorText : theme.colorTextSecondary,- fontSize: 12,- }}- >- {t('viewMode.normal', { ns: 'chat' })}- </span>- </Flexbox>- <Flexbox- align="center"- gap={4}- onClick={() => {- if (!wideScreen) toggleWideScreen();- }}- style={{- backgroundColor: wideScreen ? theme.colorFillSecondary : 'transparent',- borderRadius: theme.borderRadius,- cursor: 'pointer',- flex: 1,- padding: '8px 12px',- pointerEvents: 'auto',- transition: `background-color ${theme.motionDurationMid}`,+ <Flexbox align="center" horizontal justify="space-between">+ <span>{t('viewMode.fullWidth', { ns: 'chat' })}</span>+ <Switch+ checked={wideScreen}+ onChange={toggleWideScreen}+ onClick={(checked, event) => {+ event.stopPropagation();}}- >- <Icon icon={SquareChartGanttIcon} size={20} />- <span- style={{- color: wideScreen ? theme.colorText : theme.colorTextSecondary,- fontSize: 12,- }}- >- {t('viewMode.wideScreen', { ns: 'chat' })}- </span>- </Flexbox>+ size="small"+ /></Flexbox>),},@@ -98,6 +93,12 @@ export const useMenu = (): { menuItems: any[] } => {},]: []),+ {+ icon: <Icon icon={CopyPlus} />,+ key: 'duplicate',+ label: t('pageList.duplicate'),+ onClick: handleDuplicate,+ },{icon: <Icon icon={Link2} />,key: 'copy-link',@@ -120,6 +121,21 @@ export const useMenu = (): { menuItems: any[] } => {{type: 'divider' as const,},+ {+ children: [+ {+ key: 'export-markdown',+ label: t('pageEditor.menu.export.markdown'),+ onClick: handleExportMarkdown,+ },+ ],+ icon: <Icon icon={Download} />,+ key: 'export',+ label: t('pageEditor.menu.export'),+ },+ {+ type: 'divider' as const,+ },{disabled: true,key: 'page-info',@@ -148,6 +164,8 @@ export const useMenu = (): { menuItems: any[] } => {wideScreen,toggleWideScreen,showViewModeSwitch,+ handleDuplicate,+ handleExportMarkdown,],);diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.tsindex 49ed888dd23..c40695a8da7 100644--- a/src/locales/default/chat.ts+++ b/src/locales/default/chat.ts@@ -393,6 +393,7 @@ export default {'upload.preview.status.processing': 'Processing file...','upload.validation.videoSizeExceeded':'Video file size must not exceed 20MB. Current file size is {{actualSize}}.',+ 'viewMode.fullWidth': 'Full Width','viewMode.normal': 'Standard','viewMode.wideScreen': 'Widescreen','you': 'You',diff --git a/src/locales/default/file.ts b/src/locales/default/file.tsindex 7f1400a3197..b12397ea46e 100644--- a/src/locales/default/file.ts+++ b/src/locales/default/file.ts@@ -80,6 +80,8 @@ export default {'pageEditor.deleteConfirm.title': 'Delete Page','pageEditor.deleteError': 'Failed to delete the page','pageEditor.deleteSuccess': 'Page deleted successfully',+ 'pageEditor.duplicateError': 'Failed to duplicate the page',+ 'pageEditor.duplicateSuccess': 'Page duplicated successfully','pageEditor.editedAt': 'Last edited on {{time}}','pageEditor.editedBy': 'Last edited by {{name}}','pageEditor.editorPlaceholder': 'Start writing your page. Press / to open the command menu',@@ -87,8 +89,12 @@ export default {'pageEditor.empty.importNotion': 'Import from Notion','pageEditor.empty.title': 'Select a page to get started','pageEditor.empty.uploadFiles': 'Upload Files',+ 'pageEditor.exportError': 'Failed to export the page',+ 'pageEditor.exportSuccess': 'Page exported successfully','pageEditor.linkCopied': 'Link copied','pageEditor.menu.copyLink': 'Copy Link',+ 'pageEditor.menu.export': 'Export',+ 'pageEditor.menu.export.markdown': 'Markdown','pageEditor.menu.exportDocument': 'Export Page','pageEditor.menu.importDocument': 'Import Page','pageEditor.menu.pin': 'Pin Page',diff --git a/src/store/global/actions/workspacePane.ts b/src/store/global/actions/workspacePane.tsindex fbad84fd227..c20bdd90f63 100644--- a/src/store/global/actions/workspacePane.ts+++ b/src/store/global/actions/workspacePane.ts@@ -103,9 +103,9 @@ export const globalWorkspaceSlice: StateCreator<get().updateSystemStatus({ showSystemRole }, n('toggleMobileTopic', newValue));},toggleWideScreen: (newValue) => {- const wideScreen = typeof newValue === 'boolean' ? newValue : !get().status.noWideScreen;+ const noWideScreen = typeof newValue === 'boolean' ? !newValue : !get().status.noWideScreen;- get().updateSystemStatus({ noWideScreen: wideScreen }, n('toggleWideScreen', newValue));+ get().updateSystemStatus({ noWideScreen }, n('toggleWideScreen', newValue));},toggleZenMode: () => {const { status } = get();