|
1 | 1 | import Markdown, { Components } from "react-markdown"; |
2 | 2 | import remarkGfm from "remark-gfm"; |
3 | 3 | import SyntaxHighlighter from "react-syntax-highlighter"; |
4 | | -import { type AceLang, EditorComponent } from "../terminal/editor"; |
| 4 | +import { type AceLang, EditorComponent, getAceLang } from "../terminal/editor"; |
5 | 5 | import { ExecFile } from "../terminal/exec"; |
6 | 6 | import { useChangeTheme } from "./themeToggle"; |
7 | 7 | import { |
8 | 8 | tomorrow, |
9 | 9 | atomOneDark, |
10 | 10 | } from "react-syntax-highlighter/dist/esm/styles/hljs"; |
11 | 11 | import { ReactNode } from "react"; |
12 | | -import { RuntimeLang } from "@/terminal/runtime"; |
| 12 | +import { getRuntimeLang, RuntimeLang } from "@/terminal/runtime"; |
13 | 13 | import { ReplTerminal } from "@/terminal/repl"; |
14 | 14 |
|
15 | 15 | export function StyledMarkdown({ content }: { content: string }) { |
@@ -95,19 +95,7 @@ function CodeComponent({ |
95 | 95 | className || "" |
96 | 96 | ); |
97 | 97 | if (match) { |
98 | | - let runtimeLang: RuntimeLang | undefined = undefined; |
99 | | - switch (match[1]) { |
100 | | - case "python": |
101 | | - runtimeLang = "python"; |
102 | | - break; |
103 | | - case "cpp": |
104 | | - case "c++": |
105 | | - runtimeLang = "cpp"; |
106 | | - break; |
107 | | - default: |
108 | | - console.warn(`Unsupported language for runtime: ${match[1]}`); |
109 | | - break; |
110 | | - } |
| 98 | + const runtimeLang = getRuntimeLang(match[1]); |
111 | 99 | if (match[2] === "-exec" && match[3]) { |
112 | 100 | /* |
113 | 101 | ```python-exec:main.py |
@@ -150,29 +138,7 @@ function CodeComponent({ |
150 | 138 | } |
151 | 139 | } else if (match[3]) { |
152 | 140 | // ファイル名指定がある場合、ファイルエディター |
153 | | - let aceLang: AceLang | undefined = undefined; |
154 | | - switch (match[1]) { |
155 | | - case "python": |
156 | | - aceLang = "python"; |
157 | | - break; |
158 | | - case "cpp": |
159 | | - case "c++": |
160 | | - aceLang = "c_cpp"; |
161 | | - break; |
162 | | - case "json": |
163 | | - aceLang = "json"; |
164 | | - break; |
165 | | - case "csv": |
166 | | - aceLang = "csv"; |
167 | | - break; |
168 | | - case "text": |
169 | | - case "txt": |
170 | | - aceLang = "text"; |
171 | | - break; |
172 | | - default: |
173 | | - console.warn(`Unsupported language for editor: ${match[1]}`); |
174 | | - break; |
175 | | - } |
| 141 | + const aceLang = getAceLang(match[1]); |
176 | 142 | return ( |
177 | 143 | <div className="border border-primary border-2 shadow-md m-2 rounded-lg"> |
178 | 144 | <EditorComponent |
|
0 commit comments