Skip to content

Commit 21d63da

Browse files
SylvainChevaliergithub-actions[bot]hlbmtc
authored
Add plain text option to markdown editor code blocks (#3918)
* Add plain text option to markdown editor code blocks - Added "Plain text" option to code block language selector - Added aliases (text, plaintext, plain) for plain text - Modified PrismCodeBlock to render plain text without syntax highlighting - Plain text code blocks don't add anything after backticks Fixes #3917 Co-authored-by: Sylvain <[email protected]> * Set plaintext as default language for new code blocks Co-authored-by: Sylvain <[email protected]> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Sylvain <[email protected]> Co-authored-by: Hlib <[email protected]>
1 parent 6f75161 commit 21d63da

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

front_end/src/components/markdown_editor/initialized_editor.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}),

front_end/src/components/markdown_editor/plugins/code/languages.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Language } from "prism-react-renderer";
22

33
export 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 = {
1415
export type CanonicalLang = keyof typeof CANONICAL_TO_LABEL;
1516

1617
const 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

4449
export const CANONICAL_TO_PRISM: Record<CanonicalLang, Language> = {
50+
text: "text" as Language,
4551
ts: "typescript",
4652
tsx: "tsx",
4753
js: "javascript",

0 commit comments

Comments
 (0)