Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
"thumbhash": "^0.1.1",
"use-fit-text": "^2.4.0",
"zod": "^3.22.4",
"zustand": "^4.4.6"
"zustand": "^4.4.6",
"katex": "^0.16.8",
"react-katex": "^3.0.1"
},
"devDependencies": {
"@chakra-ui/cli": "^2.4.1",
Expand All @@ -112,6 +114,7 @@
"@types/lodash.throttle": "^4.1.9",
"@types/node": "^20.10.4",
"@types/qrcode": "^1.5.5",
"@types/katex": "^0.16.7",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"autoprefixer": "^10.4.16",
Expand Down
3 changes: 3 additions & 0 deletions apps/next/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
@tailwind components;
@tailwind utilities;

/* KaTeX CSS for LaTeX rendering */
@import "katex/dist/katex.min.css";

.betteruptime-announcement {
position: relative !important;
font-family: "Open Sans" !important;
Expand Down
7 changes: 5 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"next-seo": "^6.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"xss": "^1.0.14"
"xss": "^1.0.14",
"katex": "^0.16.8",
"react-katex": "^3.0.1"
},
"scripts": {
"lint": "eslint . --ext .ts,.tsx",
Expand All @@ -26,6 +28,7 @@
"devDependencies": {
"@types/lodash.merge": "^4.6.9",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17"
"@types/react-dom": "^18.2.17",
"@types/katex": "^0.16.7"
}
}
12 changes: 12 additions & 0 deletions packages/components/script-formatter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import React, { useMemo } from "react";

import { formatScripts } from "@quenti/lib/scripts";
import { LatexFormatter } from "./latex-formatter";

export const ScriptFormatter = ({ children }: { children: string }) => {
const formatted = useMemo(() => formatScripts(children), [children]);

// Check if the text contains LaTeX expressions
const hasLatex = useMemo(() => {
return /(\$\$[\s\S]*?\$\$|\$[^$\n]*?\$)/.test(children);
}, [children]);

// If LaTeX is detected, use LatexFormatter which will handle both LaTeX and regular text
if (hasLatex) {
return <LatexFormatter>{children}</LatexFormatter>;
}

// Otherwise, use the original script formatting
return (
<>
{formatted.map((item, index) => (
Expand Down