diff --git a/exprs/overlay.nix b/exprs/overlay.nix index e6671f7..64acc39 100644 --- a/exprs/overlay.nix +++ b/exprs/overlay.nix @@ -12,7 +12,7 @@ vencord-input: final: prev: { idea-ultimate-fixed = prev.callPackage ./idea-fixed.nix {}; - vencord = prev.vencord.overrideAttrs (old: rec { + vencord = prev.vencord.overrideAttrs (old: { src = vencord-input // { @@ -20,15 +20,6 @@ vencord-input: final: prev: { repo = "Vencord"; }; - ventex = prev.fetchFromGitHub { - owner = "vgskye"; - repo = "ventex"; - rev = "158c14e7d88acb140a71766c514d8a3724d260cd"; - hash = "sha256-Svc8dI2weFcqPSk064t/pL/4Hopn6/mWP6cIrT+FIr8="; - }; - - postConfigure = '' - cp -r ${ventex} src/plugins/ventex - ''; + patches = old.patches or [] ++ [./ventex.patch]; }); } diff --git a/exprs/ventex.patch b/exprs/ventex.patch new file mode 100644 index 0000000..61e1c8f --- /dev/null +++ b/exprs/ventex.patch @@ -0,0 +1,128 @@ +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; ++} ++ ++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) => ( ++ ++ ), ++ createInline: (props: HighlighterProps) => ( ++ ++ ), ++}); ++ ++function LazyLatex(props) { ++ const { formula } = props; ++ const katex = useKatex(); ++ const domPurify = useDomPurify(); ++ return katex && domPurify ++ ? ++ : {formula}; ++} ++ ++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 ++ ?
++ : ; ++} +\ 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 diff --git a/flake.lock b/flake.lock index c56a7f4..2e67ec7 100644 --- a/flake.lock +++ b/flake.lock @@ -75,11 +75,11 @@ }, "catppuccin": { "locked": { - "lastModified": 1730458408, - "narHash": "sha256-JQ+SphQn13bdibKUrBBBznYehXX4xJrxD1ifBp6vSWw=", + "lastModified": 1730036420, + "narHash": "sha256-rv2bz7J6Wo7AenPiu4+ptCB1AFyaMcS77y89zbRAtI8=", "owner": "Stonks3141", "repo": "ctp-nix", - "rev": "191fbf2d81a63fad8f62f1233c0051f09b75d0ad", + "rev": "0b7bf04628414a402d255924f65e9a0d1a53d92b", "type": "github" }, "original": { @@ -172,11 +172,11 @@ "zig": "zig" }, "locked": { - "lastModified": 1730394182, - "narHash": "sha256-gICiMiFZcxz/oY29iEsYi9Q/gC8Fx2nW1L872J1TA74=", + "lastModified": 1730155692, + "narHash": "sha256-2p90mOK7JC3Rt8hH2tQDV4WxbukjWpq2+OH2WptEgag=", "ref": "refs/heads/main", - "rev": "e7ccc60ed57f9897f390da42f0d7e06f094d46f3", - "revCount": 7858, + "rev": "c413f2445d8fc9af8919bae818ec01b5a543cec2", + "revCount": 7836, "type": "git", "url": "ssh://git@github.com/ghostty-org/ghostty" }, @@ -192,11 +192,11 @@ ] }, "locked": { - "lastModified": 1730450782, - "narHash": "sha256-0AfApF8aexgB6o34qqLW2cCX4LaWJajBVdU6ddiWZBM=", + "lastModified": 1730016908, + "narHash": "sha256-bFCxJco7d8IgmjfNExNz9knP8wvwbXU4s/d53KOK6U0=", "owner": "nix-community", "repo": "home-manager", - "rev": "8ca921e5a806b5b6171add542defe7bdac79d189", + "rev": "e83414058edd339148dc142a8437edb9450574c8", "type": "github" }, "original": { @@ -243,11 +243,11 @@ ] }, "locked": { - "lastModified": 1730448125, - "narHash": "sha256-egDk4Sdd2NtPhPrSKAzagW+7mG5zzVsqdrLNjIk20xg=", + "lastModified": 1729935605, + "narHash": "sha256-CLMq9+IxT7r3Du2tNNUPoM1exJL6D6jxe9GSar51lbM=", "owner": "soopyc", "repo": "mystia", - "rev": "663145aa050103c278863d55e136ce30e341497e", + "rev": "3b6f001db02f5135386dbf0b3628e9679c2cdb63", "type": "github" }, "original": { @@ -287,11 +287,11 @@ ] }, "locked": { - "lastModified": 1730453870, - "narHash": "sha256-d+kIgz4BvTXb7emjSFV3zjNydGmLUmuluQjdBb51R9o=", + "lastModified": 1730120924, + "narHash": "sha256-I6hwd+YlgefioLfmsM04MxzbEAES1N328/T+VqhcWnQ=", "owner": "nix-community", "repo": "NixOS-WSL", - "rev": "adb6bc4b661a43328752b4575be4968a4990c033", + "rev": "b124084667fb4c912fda68fdd9d05f59e18b6ef7", "type": "github" }, "original": { @@ -302,11 +302,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1730200266, - "narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=", + "lastModified": 1729880355, + "narHash": "sha256-RP+OQ6koQQLX5nw0NmcDrzvGL8HDLnyXt/jHhL1jwjM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "807e9154dcb16384b1b765ebe9cd2bba2ac287fd", + "rev": "18536bf04cd71abd345f9579158841376fdd0c5a", "type": "github" }, "original": { @@ -438,11 +438,11 @@ ] }, "locked": { - "lastModified": 1730426202, - "narHash": "sha256-swwKpE3lrdvcSh6Hjyf/eSe/zPnsZgeVlSl+B4yBpeo=", + "lastModified": 1730166645, + "narHash": "sha256-r+cFrkHjf93QHzAid/IAIoTjY8icOFu5iCCQ5e/Sd98=", "owner": "nix-community", "repo": "nix-vscode-extensions", - "rev": "96dcbddd24edc60ad47f41bb2a73e06099eba4af", + "rev": "be01145d66a5cdaf0a620b8b277a8e05f1fba84b", "type": "github" }, "original": {