fix: katex fetching from the backend

This commit is contained in:
Rotimi Best
2025-06-13 16:56:09 +01:00
parent 82be557a42
commit 179faf0d2c
3 changed files with 7 additions and 16 deletions
+7 -14
View File
@@ -5,25 +5,18 @@ import { z } from 'zod';
export const katexRouter = new Hono();
const katexSchema = z.object({
latex: z.string().min(1),
displayMode: z.boolean().optional()
});
katexRouter.post('/', async (c: Context) => {
katexRouter.get('/', async (c: Context) => {
try {
const data = await c.req.json();
const validatedData = katexSchema.parse(data);
const original = c.req.raw.url;
const html = katex.renderToString(validatedData.latex, {
displayMode: validatedData.displayMode ?? false,
const latexString = original.split('?')[1].replaceAll('+', '+').replaceAll('&space;', '');
const html = katex.renderToString(latexString, {
output: 'mathml',
throwOnError: false
});
return c.json({
success: true,
html
});
return c.html(html);
} catch (error) {
if (error instanceof z.ZodError) {
return c.json(