From b72b5041814c1a22ed75880a28acf3a2fa3db059 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 12 Apr 2024 19:51:42 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20better=20detection=20of=20?= =?UTF-8?q?terminal=20code=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/markdown/CodeBlockToolbar.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gui/src/components/markdown/CodeBlockToolbar.tsx b/gui/src/components/markdown/CodeBlockToolbar.tsx index a7a1e53e1..f0512163d 100644 --- a/gui/src/components/markdown/CodeBlockToolbar.tsx +++ b/gui/src/components/markdown/CodeBlockToolbar.tsx @@ -40,6 +40,30 @@ interface CodeBlockToolBarProps { } const terminalLanguages = ["bash", "sh"]; +const commonTerminalCommands = [ + "npm", + "pnpm", + "yarn", + "bun", + "deno", + "npx", + "cd", + "ls", + "pwd", + "pip", + "python", + "node", + "git", + "curl", + "wget", +]; +function isTerminalCodeBlock(language: string | undefined, text: string) { + return ( + terminalLanguages.includes(language) || + (text.trim().split("\n").length === 1 && + commonTerminalCommands.some((c) => text.trim().startsWith(c))) + ); +} function CodeBlockToolBar(props: CodeBlockToolBarProps) { const [copied, setCopied] = useState(false); @@ -52,7 +76,7 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) { <>