Files
classroomio/apps/backend/src/routes/katex.js
T

32 lines
654 B
JavaScript
Raw Normal View History

const express = require('express');
// https://ben.page/node-latex-to-html
const katex = require('katex');
const router = express.Router();
// localhost:3002/katex
router.get('/', async (req, res) => {
2024-04-09 21:34:01 +01:00
try {
const original = req._parsedUrl.search;
2024-04-09 21:34:01 +01:00
const latexString = original
.replace('?', '')
.replaceAll('+', '+')
.replaceAll('&space;', '');
console.log({ latexString });
2024-04-09 21:34:01 +01:00
const html = katex.renderToString(latexString, {
throwOnError: false,
output: 'mathml'
});
2024-04-09 21:34:01 +01:00
console.log({ html });
2024-04-09 21:34:01 +01:00
res.send(html);
} catch (error) {
res.send('failed');
}
});
module.exports = router;