hugo/internal/warpc/js/renderkatex.js
Bjørn Erik Pedersen 6334948515
Handle KaTeX warnings (#13760)
Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>

Fixes #13735
2025-05-30 20:57:54 +02:00

25 lines
823 B
JavaScript

import { readInput, writeOutput } from './common';
import katex from 'katex';
import 'katex/contrib/mhchem/mhchem.js';
const render = function (input) {
const data = input.data;
const expression = data.expression;
const options = data.options;
const header = input.header;
header.warnings = [];
if (options.strict == 'warn') {
// By default, KaTeX will write to console.warn, that's a little hard to handle.
options.strict = (errorCode, errorMsg) => {
header.warnings.push(
`katex: LaTeX-incompatible input and strict mode is set to 'warn': ${errorMsg} [${errorCode}]`,
);
};
}
// Any error thrown here will be caught by the common.js readInput function.
const output = katex.renderToString(expression, options);
writeOutput({ header: header, data: { output: output } });
};
readInput(render);