⚡️ better detection of terminal code blocks
This commit is contained in:
parent
2656f9d30c
commit
b72b504181
1 changed files with 25 additions and 1 deletions
|
|
@ -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) {
|
|||
<>
|
||||
<HeaderButtonWithText
|
||||
text={
|
||||
terminalLanguages.includes(props.language)
|
||||
isTerminalCodeBlock(props.language, props.text)
|
||||
? "Run in terminal"
|
||||
: applying
|
||||
? "Applying..."
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue