diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/CodeBlock.tsx | 21 | ||||
-rw-r--r-- | src/components/VencordSettings/PatchHelperTab.tsx | 3 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/components/CodeBlock.tsx b/src/components/CodeBlock.tsx new file mode 100644 index 0000000..41c5ef0 --- /dev/null +++ b/src/components/CodeBlock.tsx @@ -0,0 +1,21 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { findByPropsLazy } from "@webpack"; +import { Parser } from "@webpack/common"; + +const CodeContainerClasses = findByPropsLazy("markup", "codeContainer"); + +/** + * Renders code in a Discord codeblock + */ +export function CodeBlock(props: { content?: string, lang: string; }) { + return ( + <div className={CodeContainerClasses.markup}> + {Parser.defaultRules.codeBlock.react(props, null, {})} + </div> + ); +} diff --git a/src/components/VencordSettings/PatchHelperTab.tsx b/src/components/VencordSettings/PatchHelperTab.tsx index d5bd94c..0b869a5 100644 --- a/src/components/VencordSettings/PatchHelperTab.tsx +++ b/src/components/VencordSettings/PatchHelperTab.tsx @@ -17,6 +17,7 @@ */ import { CheckedTextInput } from "@components/CheckedTextInput"; +import { CodeBlock } from "@components/CodeBlock"; import { debounce } from "@utils/debounce"; import { Margins } from "@utils/margins"; import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches"; @@ -299,7 +300,7 @@ function PatchHelper() { {!!(find && match && replacement) && ( <> <Forms.FormTitle className={Margins.top20}>Code</Forms.FormTitle> - <div style={{ userSelect: "text" }}>{Parser.parse(makeCodeblock(code, "ts"))}</div> + <CodeBlock lang="js" content={code} /> <Button onClick={() => Clipboard.copy(code)}>Copy to Clipboard</Button> </> )} |