1- import Markdown , { Components } from "react-markdown" ;
1+ import Markdown , { Components , ExtraProps } from "react-markdown" ;
22import remarkGfm from "remark-gfm" ;
33import { EditorComponent , getAceLang } from "../terminal/editor" ;
44import { ExecFile } from "../terminal/exec" ;
5- import { useChangeTheme } from "./themeToggle" ;
6- import {
7- tomorrow ,
8- atomOneDark ,
9- } from "react-syntax-highlighter/dist/esm/styles/hljs" ;
10- import { ReactNode } from "react" ;
5+ import { JSX , ReactNode } from "react" ;
116import { getRuntimeLang } from "@/terminal/runtime" ;
127import { ReplTerminal } from "@/terminal/repl" ;
13- import dynamic from "next/dynamic" ;
14- // SyntaxHighlighterはファイルサイズがでかいので & HydrationErrorを起こすので、SSRを無効化する
15- const SyntaxHighlighter = dynamic ( ( ) => import ( "react-syntax-highlighter" ) , { ssr : false } ) ;
8+ import {
9+ getSyntaxHighlighterLang ,
10+ MarkdownLang ,
11+ StyledSyntaxHighlighter ,
12+ } from "./styledSyntaxHighlighter" ;
1613
1714export function StyledMarkdown ( { content } : { content : string } ) {
1815 return (
@@ -40,14 +37,14 @@ const components: Components = {
4037 li : ( { node, ...props } ) => < li className = "my-1" { ...props } /> ,
4138 a : ( { node, ...props } ) => < a className = "link link-info" { ...props } /> ,
4239 strong : ( { node, ...props } ) => (
43- < strong className = "text-primary dark:text-secondary " { ...props } />
40+ < strong className = "text-primary" { ...props } />
4441 ) ,
4542 table : ( { node, ...props } ) => (
46- < div className = "w-max max-w-full overflow-x-auto mx-auto my-2 rounded-lg border border-base-content/5 shadow-sm" >
43+ < div className = "w-max max-w-full overflow-x-auto mx-auto my-2 rounded-box border border-current/20 shadow-sm" >
4744 < table className = "table w-max" { ...props } />
4845 </ div >
4946 ) ,
50- hr : ( { node, ...props } ) => < hr className = "border-primary my-4" { ...props } /> ,
47+ hr : ( { node, ...props } ) => < hr className = "border-accent my-4" { ...props } /> ,
5148 pre : ( { node, ...props } ) => props . children ,
5249 code : ( { node, className, ref, style, ...props } ) => (
5350 < CodeComponent { ...{ node, className, ref, style, ...props } } />
@@ -84,20 +81,12 @@ function CodeComponent({
8481 ref,
8582 style,
8683 ...props
87- } : {
88- node : unknown ;
89- className ?: string ;
90- ref ?: unknown ;
91- style ?: unknown ;
92- [ key : string ] : unknown ;
93- } ) {
94- const theme = useChangeTheme ( ) ;
95- const codetheme = theme === "tomorrow" ? tomorrow : atomOneDark ;
84+ } : JSX . IntrinsicElements [ "code" ] & ExtraProps ) {
9685 const match = / ^ l a n g u a g e - ( \w + ) ( - r e p l | - e x e c | - r e a d o n l y ) ? \: ? ( .+ ) ? $ / . exec (
9786 className || ""
9887 ) ;
9988 if ( match ) {
100- const runtimeLang = getRuntimeLang ( match [ 1 ] ) ;
89+ const runtimeLang = getRuntimeLang ( match [ 1 ] as MarkdownLang | undefined ) ;
10190 if ( match [ 2 ] === "-exec" && match [ 3 ] ) {
10291 /*
10392 ```python-exec:main.py
@@ -111,13 +100,11 @@ function CodeComponent({
111100 */
112101 if ( runtimeLang ) {
113102 return (
114- < div className = "border border-primary border-2 shadow-md m-2 rounded-lg" >
115- < ExecFile
116- language = { runtimeLang }
117- filenames = { match [ 3 ] . split ( "," ) }
118- content = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
119- />
120- </ div >
103+ < ExecFile
104+ language = { runtimeLang }
105+ filenames = { match [ 3 ] . split ( "," ) }
106+ content = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
107+ />
121108 ) ;
122109 }
123110 } else if ( match [ 2 ] === "-repl" ) {
@@ -129,57 +116,45 @@ function CodeComponent({
129116 }
130117 if ( runtimeLang ) {
131118 return (
132- < div className = "bg-base-300 border border-primary border-2 shadow-md m-2 p-4 pr-1 rounded-lg" >
133- < ReplTerminal
134- terminalId = { match [ 3 ] }
135- language = { runtimeLang }
136- initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
137- />
138- </ div >
119+ < ReplTerminal
120+ terminalId = { match [ 3 ] }
121+ language = { runtimeLang }
122+ initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
123+ />
139124 ) ;
140125 }
141126 } else if ( match [ 3 ] ) {
142127 // ファイル名指定がある場合、ファイルエディター
143- const aceLang = getAceLang ( match [ 1 ] ) ;
128+ const aceLang = getAceLang ( match [ 1 ] as MarkdownLang | undefined ) ;
144129 return (
145- < div className = "border border-primary border-2 shadow-md m-2 rounded-lg" >
146- < EditorComponent
147- language = { aceLang }
148- filename = { match [ 3 ] }
149- readonly = { match [ 2 ] === "-readonly" }
150- initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
151- />
152- </ div >
130+ < EditorComponent
131+ language = { aceLang }
132+ filename = { match [ 3 ] }
133+ readonly = { match [ 2 ] === "-readonly" }
134+ initContent = { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
135+ />
153136 ) ;
154137 }
138+ const syntaxHighlighterLang = getSyntaxHighlighterLang (
139+ match [ 1 ] as MarkdownLang | undefined
140+ ) ;
155141 return (
156- < SyntaxHighlighter
157- language = { match [ 1 ] }
158- PreTag = "div"
159- className = "border border-base-content/50 mx-2 my-2 rounded-lg text-sm p-4!"
160- style = { codetheme }
161- { ...props }
162- >
142+ < StyledSyntaxHighlighter language = { syntaxHighlighterLang } >
163143 { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
164- </ SyntaxHighlighter >
144+ </ StyledSyntaxHighlighter >
165145 ) ;
166146 } else if ( String ( props . children ) . includes ( "\n" ) ) {
167147 // 言語指定なしコードブロック
168148 return (
169- < SyntaxHighlighter
170- PreTag = "div"
171- className = "border border-base-content/50 mx-2 my-2 rounded-lg text-sm p-4!"
172- style = { codetheme }
173- { ...props }
174- >
149+ < StyledSyntaxHighlighter language = { undefined } >
175150 { String ( props . children || "" ) . replace ( / \n $ / , "" ) }
176- </ SyntaxHighlighter >
151+ </ StyledSyntaxHighlighter >
177152 ) ;
178153 } else {
179154 // inline
180155 return (
181156 < code
182- className = "bg-base-200/60 border border-base-300 px-1 py-0.5 rounded text-sm "
157+ className = "bg-current/10 border border-current/20 px-1 py-0.5 mx-0.5 rounded-md "
183158 { ...props }
184159 />
185160 ) ;
0 commit comments