diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vue index 60b755c88..34950f2ab 100644 --- a/apps/desktop/src/components/editor/AiAssistant.vue +++ b/apps/desktop/src/components/editor/AiAssistant.vue @@ -24,7 +24,7 @@ import { buildAiAgentPlan } from "@/lib/aiAgentPlan"; import { buildAiAgentStepItems, type AiAgentStepItem, type AiAgentStepTone } from "@/lib/aiAgentStepPresentation"; import { createAiShikiCodeHighlighter, type AiCodeHighlighter } from "@/lib/aiCodeHighlighter"; import { createAiMessageRenderer } from "@/lib/aiMessageRender"; -import { Marked } from "marked"; +import { formatAiInlineMarkdown, handleAiMarkdownLinkClick } from "@/lib/aiMarkdown"; import { aiCancelStream, aiListModels, saveAiConversation, loadAiConversations, deleteAiConversation, listSchemas, listTables, type AiConversation, type AiModelInfo } from "@/lib/api"; import type { AiMessage } from "@/lib/api"; import type { ConnectionConfig, QueryTab, TableInfo } from "@/types/database"; @@ -1021,32 +1021,27 @@ function triggerAction(action: AiAction, instruction?: string) { defineExpose({ triggerAction }); -const markedInstance = new Marked({ - breaks: true, - gfm: true, - renderer: { - code({ text }: { text: string }) { - return `${text}`; - }, - }, -}); - -function formatInlineText(text: string): string { - try { - return markedInstance.parse(text) as string; - } catch { - return text.replace(/&/g, "&").replace(//g, ">"); - } -} - const messageRenderer = computed(() => { const appearance = aiCodeAppearance.value; const highlightCode = shikiCodeHighlighter.value; return createAiMessageRenderer({ - markdown: formatInlineText, + markdown: formatAiInlineMarkdown, highlightCode: highlightCode ? (content, lang) => highlightCode(content, lang, appearance) : undefined, }); }); + +function onMarkdownClick(event: MouseEvent) { + handleAiMarkdownLinkClick(event, openExternalUrl); +} + +async function openExternalUrl(url: string) { + try { + const { open } = await import("@tauri-apps/plugin-shell"); + await open(url); + } catch { + window.open(url, "_blank", "noopener,noreferrer"); + } +}