11import Markdown , { Components } from "react-markdown" ;
22import remarkGfm from "remark-gfm" ;
33import SyntaxHighlighter from "react-syntax-highlighter" ;
4- import { PythonEmbeddedTerminal } from "../terminal/python/embedded" ;
54import { type AceLang , EditorComponent } from "../terminal/editor" ;
6- import { ExecFile , ExecLang } from "../terminal/exec" ;
5+ import { ExecFile } from "../terminal/exec" ;
76import { useChangeTheme } from "./themeToggle" ;
87import {
98 tomorrow ,
109 atomOneDark ,
1110} from "react-syntax-highlighter/dist/esm/styles/hljs" ;
1211import { ReactNode } from "react" ;
12+ import { RuntimeLang } from "@/terminal/runtime" ;
13+ import { ReplTerminal } from "@/terminal/repl" ;
1314
1415export function StyledMarkdown ( { content } : { content : string } ) {
1516 return (
@@ -94,6 +95,19 @@ function CodeComponent({
9495 className || ""
9596 ) ;
9697 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+ }
97111 if ( match [ 2 ] === "-exec" && match [ 3 ] ) {
98112 /*
99113 ```python-exec:main.py
@@ -105,24 +119,11 @@ function CodeComponent({
105119 hello, world!
106120 ---------------------------
107121 */
108- let execLang : ExecLang | undefined = undefined ;
109- switch ( match [ 1 ] ) {
110- case "python" :
111- execLang = "python" ;
112- break ;
113- case "cpp" :
114- case "c++" :
115- execLang = "cpp" ;
116- break ;
117- default :
118- console . warn ( `Unsupported language for exec: ${ match [ 1 ] } ` ) ;
119- break ;
120- }
121- if ( execLang ) {
122+ if ( runtimeLang ) {
122123 return (
123124 < div className = "border border-primary border-2 shadow-md m-2 rounded-lg" >
124125 < ExecFile
125- language = { execLang }
126+ language = { runtimeLang }
126127 filenames = { match [ 3 ] . split ( "," ) }
127128 content = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
128129 />
@@ -131,25 +132,21 @@ function CodeComponent({
131132 }
132133 } else if ( match [ 2 ] === "-repl" ) {
133134 // repl付きの言語指定
134- // 現状はPythonのみ対応
135135 if ( ! match [ 3 ] ) {
136136 console . warn (
137137 `${ match [ 1 ] } -repl without terminal id! content: ${ String ( props . children ) . slice ( 0 , 20 ) } ...`
138138 ) ;
139139 }
140- switch ( match [ 1 ] ) {
141- case "python" :
142- return (
143- < div className = "bg-base-300 border border-primary border-2 shadow-md m-2 p-4 pr-1 rounded-lg" >
144- < PythonEmbeddedTerminal
145- terminalId = { match [ 3 ] }
146- content = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
147- />
148- </ div >
149- ) ;
150- default :
151- console . warn ( `Unsupported language for repl: ${ match [ 1 ] } ` ) ;
152- break ;
140+ if ( runtimeLang ) {
141+ return (
142+ < div className = "bg-base-300 border border-primary border-2 shadow-md m-2 p-4 pr-1 rounded-lg" >
143+ < ReplTerminal
144+ terminalId = { match [ 3 ] }
145+ language = { runtimeLang }
146+ initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
147+ />
148+ </ div >
149+ ) ;
153150 }
154151 } else if ( match [ 3 ] ) {
155152 // ファイル名指定がある場合、ファイルエディター
@@ -180,7 +177,6 @@ function CodeComponent({
180177 < div className = "border border-primary border-2 shadow-md m-2 rounded-lg" >
181178 < EditorComponent
182179 language = { aceLang }
183- tabSize = { 4 }
184180 filename = { match [ 3 ] }
185181 readonly = { match [ 2 ] === "-readonly" }
186182 initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
0 commit comments