Compare commits
2 commits
f1a67636a9
...
e2f73b4e51
Author | SHA1 | Date | |
---|---|---|---|
e2f73b4e51 | |||
266cef9baf |
3 changed files with 33 additions and 152 deletions
|
@ -12,7 +12,7 @@ vencord-input: final: prev: {
|
|||
|
||||
idea-ultimate-fixed = prev.callPackage ./idea-fixed.nix {};
|
||||
|
||||
vencord = prev.vencord.overrideAttrs (old: {
|
||||
vencord = prev.vencord.overrideAttrs (old: rec {
|
||||
src =
|
||||
vencord-input
|
||||
// {
|
||||
|
@ -20,6 +20,15 @@ vencord-input: final: prev: {
|
|||
repo = "Vencord";
|
||||
};
|
||||
|
||||
patches = old.patches or [] ++ [./ventex.patch];
|
||||
ventex = prev.fetchFromGitHub {
|
||||
owner = "vgskye";
|
||||
repo = "ventex";
|
||||
rev = "158c14e7d88acb140a71766c514d8a3724d260cd";
|
||||
hash = "sha256-Svc8dI2weFcqPSk064t/pL/4Hopn6/mWP6cIrT+FIr8=";
|
||||
};
|
||||
|
||||
postConfigure = ''
|
||||
cp -r ${ventex} src/plugins/ventex
|
||||
'';
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
diff --git a/src/plugins/ventex/README.md b/src/plugins/ventex/README.md
|
||||
new file mode 100644
|
||||
index 00000000..3a0dc43d
|
||||
--- /dev/null
|
||||
+++ b/src/plugins/ventex/README.md
|
||||
@@ -0,0 +1,4 @@
|
||||
+# vencord katex thing
|
||||
+[forum guidelines told me to link this](https://docs.vencord.dev/installing/custom-plugins/)
|
||||
+
|
||||
+renders inline codeblocks starting and ending in `$` and codeblocks with the language `latex` in TeX using KaTeX
|
||||
\ No newline at end of file
|
||||
diff --git a/src/plugins/ventex/index.tsx b/src/plugins/ventex/index.tsx
|
||||
new file mode 100644
|
||||
index 00000000..11fc0d22
|
||||
--- /dev/null
|
||||
+++ b/src/plugins/ventex/index.tsx
|
||||
@@ -0,0 +1,97 @@
|
||||
+import "./katex.css";
|
||||
+
|
||||
+import { Devs } from "@utils/constants";
|
||||
+import definePlugin, { ReporterTestable } from "@utils/types";
|
||||
+import { makeLazy } from "@utils/lazy";
|
||||
+import { React, useEffect, useMemo, useState } from "@webpack/common";
|
||||
+
|
||||
+// @ts-expect-error
|
||||
+export const getKatex = /* #__PURE__*/ makeLazy(async () => (await import("https://unpkg.com/katex@0.16.9/dist/katex.mjs")).default);
|
||||
+
|
||||
+export function useKatex() {
|
||||
+ const [katex, setKatex] = useState();
|
||||
+ useEffect(() => {
|
||||
+ if (katex === undefined)
|
||||
+ getKatex().then(setKatex);
|
||||
+ });
|
||||
+ return katex;
|
||||
+}
|
||||
+
|
||||
+// @ts-expect-error
|
||||
+export const getDomPurify = /* #__PURE__*/ makeLazy(async () => (await import("https://unpkg.com/dompurify@3.1.7/dist/purify.es.mjs")).default);
|
||||
+
|
||||
+export function useDomPurify() {
|
||||
+ const [domPurify, setDomPurify] = useState();
|
||||
+ useEffect(() => {
|
||||
+ if (domPurify === undefined)
|
||||
+ getDomPurify().then(setDomPurify);
|
||||
+ });
|
||||
+ return domPurify;
|
||||
+}
|
||||
+
|
||||
+export interface HighlighterProps {
|
||||
+ lang?: string;
|
||||
+ content: string;
|
||||
+ isPreview: boolean;
|
||||
+ tempSettings?: Record<string, any>;
|
||||
+}
|
||||
+
|
||||
+export default definePlugin({
|
||||
+ name: "KaTeX",
|
||||
+ description: "TeX typesetting in discord",
|
||||
+ authors: [Devs.skyevg],
|
||||
+ reporterTestable: ReporterTestable.Patches,
|
||||
+
|
||||
+ patches: [
|
||||
+ {
|
||||
+ find: "codeBlock:{react(",
|
||||
+ replacement: {
|
||||
+ match: /codeBlock:\{react\((\i),(\i),(\i)\)\{/,
|
||||
+ replace: "$&if($1.lang == 'latex') return $self.createBlock($1,$2,$3);"
|
||||
+ }
|
||||
+ },
|
||||
+ {
|
||||
+ find: "inlineCode:{react:(",
|
||||
+ replacement: {
|
||||
+ match: /inlineCode:\{react:\((\i),(\i),(\i)\)=>/,
|
||||
+ replace: "$&($1.content.startsWith('$$') && $1.content.endsWith('$$'))?$self.createInline($1,$2,$3):"
|
||||
+ }
|
||||
+ }
|
||||
+ ],
|
||||
+ start: async () => {
|
||||
+ useKatex();
|
||||
+ useDomPurify();
|
||||
+ },
|
||||
+ stop: () => {
|
||||
+ },
|
||||
+
|
||||
+ createBlock: (props: HighlighterProps) => (
|
||||
+ <LazyLatex displayMode formula={props.content} />
|
||||
+ ),
|
||||
+ createInline: (props: HighlighterProps) => (
|
||||
+ <LazyLatex formula={props.content.substring(1, props.content.length - 1)} />
|
||||
+ ),
|
||||
+});
|
||||
+
|
||||
+function LazyLatex(props) {
|
||||
+ const { formula } = props;
|
||||
+ const katex = useKatex();
|
||||
+ const domPurify = useDomPurify();
|
||||
+ return katex && domPurify
|
||||
+ ? <Latex {...props} katex={katex} domPurify={domPurify} />
|
||||
+ : <code>{formula}</code>;
|
||||
+}
|
||||
+
|
||||
+function Latex({ katex, formula, displayMode, domPurify }) {
|
||||
+ const result = useMemo(() => {
|
||||
+ const html = katex.renderToString(formula, {
|
||||
+ displayMode,
|
||||
+ throwOnError: false
|
||||
+ });
|
||||
+ return domPurify.sanitize(html);
|
||||
+ }, [formula, displayMode]);
|
||||
+
|
||||
+ return displayMode
|
||||
+ ? <div className="tex" dangerouslySetInnerHTML={{ __html: result }} />
|
||||
+ : <span className="tex" dangerouslySetInnerHTML={{ __html: result }} />;
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/plugins/ventex/katex.css b/src/plugins/ventex/katex.css
|
||||
new file mode 100644
|
||||
index 00000000..fbc06b44
|
||||
--- /dev/null
|
||||
+++ b/src/plugins/ventex/katex.css
|
||||
@@ -0,0 +1,6 @@
|
||||
+@import url("https://unpkg.com/katex@0.16.9/dist/katex.min.css");
|
||||
+
|
||||
+.katex-display {
|
||||
+ width: min-content;
|
||||
+ margin: 1em;
|
||||
+}
|
||||
\ No newline at end of file
|
44
flake.lock
generated
44
flake.lock
generated
|
@ -75,11 +75,11 @@
|
|||
},
|
||||
"catppuccin": {
|
||||
"locked": {
|
||||
"lastModified": 1730036420,
|
||||
"narHash": "sha256-rv2bz7J6Wo7AenPiu4+ptCB1AFyaMcS77y89zbRAtI8=",
|
||||
"lastModified": 1730458408,
|
||||
"narHash": "sha256-JQ+SphQn13bdibKUrBBBznYehXX4xJrxD1ifBp6vSWw=",
|
||||
"owner": "Stonks3141",
|
||||
"repo": "ctp-nix",
|
||||
"rev": "0b7bf04628414a402d255924f65e9a0d1a53d92b",
|
||||
"rev": "191fbf2d81a63fad8f62f1233c0051f09b75d0ad",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -172,11 +172,11 @@
|
|||
"zig": "zig"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730155692,
|
||||
"narHash": "sha256-2p90mOK7JC3Rt8hH2tQDV4WxbukjWpq2+OH2WptEgag=",
|
||||
"lastModified": 1730394182,
|
||||
"narHash": "sha256-gICiMiFZcxz/oY29iEsYi9Q/gC8Fx2nW1L872J1TA74=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "c413f2445d8fc9af8919bae818ec01b5a543cec2",
|
||||
"revCount": 7836,
|
||||
"rev": "e7ccc60ed57f9897f390da42f0d7e06f094d46f3",
|
||||
"revCount": 7858,
|
||||
"type": "git",
|
||||
"url": "ssh://git@github.com/ghostty-org/ghostty"
|
||||
},
|
||||
|
@ -192,11 +192,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730016908,
|
||||
"narHash": "sha256-bFCxJco7d8IgmjfNExNz9knP8wvwbXU4s/d53KOK6U0=",
|
||||
"lastModified": 1730450782,
|
||||
"narHash": "sha256-0AfApF8aexgB6o34qqLW2cCX4LaWJajBVdU6ddiWZBM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "e83414058edd339148dc142a8437edb9450574c8",
|
||||
"rev": "8ca921e5a806b5b6171add542defe7bdac79d189",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -243,11 +243,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1729935605,
|
||||
"narHash": "sha256-CLMq9+IxT7r3Du2tNNUPoM1exJL6D6jxe9GSar51lbM=",
|
||||
"lastModified": 1730448125,
|
||||
"narHash": "sha256-egDk4Sdd2NtPhPrSKAzagW+7mG5zzVsqdrLNjIk20xg=",
|
||||
"owner": "soopyc",
|
||||
"repo": "mystia",
|
||||
"rev": "3b6f001db02f5135386dbf0b3628e9679c2cdb63",
|
||||
"rev": "663145aa050103c278863d55e136ce30e341497e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -287,11 +287,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730120924,
|
||||
"narHash": "sha256-I6hwd+YlgefioLfmsM04MxzbEAES1N328/T+VqhcWnQ=",
|
||||
"lastModified": 1730453870,
|
||||
"narHash": "sha256-d+kIgz4BvTXb7emjSFV3zjNydGmLUmuluQjdBb51R9o=",
|
||||
"owner": "nix-community",
|
||||
"repo": "NixOS-WSL",
|
||||
"rev": "b124084667fb4c912fda68fdd9d05f59e18b6ef7",
|
||||
"rev": "adb6bc4b661a43328752b4575be4968a4990c033",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -302,11 +302,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1729880355,
|
||||
"narHash": "sha256-RP+OQ6koQQLX5nw0NmcDrzvGL8HDLnyXt/jHhL1jwjM=",
|
||||
"lastModified": 1730200266,
|
||||
"narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "18536bf04cd71abd345f9579158841376fdd0c5a",
|
||||
"rev": "807e9154dcb16384b1b765ebe9cd2bba2ac287fd",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -438,11 +438,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1730166645,
|
||||
"narHash": "sha256-r+cFrkHjf93QHzAid/IAIoTjY8icOFu5iCCQ5e/Sd98=",
|
||||
"lastModified": 1730426202,
|
||||
"narHash": "sha256-swwKpE3lrdvcSh6Hjyf/eSe/zPnsZgeVlSl+B4yBpeo=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nix-vscode-extensions",
|
||||
"rev": "be01145d66a5cdaf0a620b8b277a8e05f1fba84b",
|
||||
"rev": "96dcbddd24edc60ad47f41bb2a73e06099eba4af",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue