File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed
front_end/src/components/markdown_editor Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -73,9 +73,22 @@ const PrismCodeBlock: FC<{ code?: string; language?: string }> = ({
7373 theme === "dark" ? prismThemes . dracula : prismThemes . github ;
7474
7575 const raw = ( language as string | undefined ) ?? "ts" ;
76- const prismLang = CANONICAL_TO_PRISM [ normalizeLang ( raw ) ] ?? "tsx" ;
76+ const normalizedLang = normalizeLang ( raw ) ;
7777 const codeTrimmed = ( code ?? "" ) . replace ( / ^ \n + | \n + $ / g, "" ) ;
7878
79+ // Handle plain text without syntax highlighting
80+ if ( normalizedLang === "text" ) {
81+ return (
82+ < div className = "my-4" >
83+ < pre className = "overflow-x-auto rounded border border-gray-300 bg-gray-100 p-3 dark:border-gray-300-dark dark:bg-gray-100-dark" >
84+ { codeTrimmed }
85+ </ pre >
86+ </ div >
87+ ) ;
88+ }
89+
90+ const prismLang = CANONICAL_TO_PRISM [ normalizedLang ] ?? "tsx" ;
91+
7992 return (
8093 < div className = "my-4" >
8194 < Highlight
@@ -256,7 +269,7 @@ const InitializedMarkdownEditor: FC<
256269 }
257270 return [
258271 ...common ,
259- codeBlockPlugin ( { defaultCodeBlockLanguage : "ts " } ) ,
272+ codeBlockPlugin ( { defaultCodeBlockLanguage : "text " } ) ,
260273 codeMirrorPlugin ( {
261274 codeBlockLanguages : CANONICAL_TO_LABEL ,
262275 } ) ,
Original file line number Diff line number Diff line change 11import type { Language } from "prism-react-renderer" ;
22
33export const CANONICAL_TO_LABEL = {
4+ text : "Plain text" ,
45 ts : "TypeScript" ,
56 tsx : "TSX" ,
67 js : "JavaScript" ,
@@ -14,6 +15,10 @@ export const CANONICAL_TO_LABEL = {
1415export type CanonicalLang = keyof typeof CANONICAL_TO_LABEL ;
1516
1617const ALIAS_TO_CANONICAL : Record < string , CanonicalLang > = {
18+ text : "text" ,
19+ plaintext : "text" ,
20+ plain : "text" ,
21+
1722 typescript : "ts" ,
1823 ts : "ts" ,
1924 tsx : "tsx" ,
@@ -42,6 +47,7 @@ export function normalizeLang(
4247}
4348
4449export const CANONICAL_TO_PRISM : Record < CanonicalLang , Language > = {
50+ text : "text" as Language ,
4551 ts : "typescript" ,
4652 tsx : "tsx" ,
4753 js : "javascript" ,
You can’t perform that action at this time.
0 commit comments