mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Improve Katex error handling and fix handling of large expressions
* Make throwOnError=true the new default * Handle JS errors as part of the RPC request/response flow * Return a new Result type with .Err on it This enables constructs on the form: ```handlebars {{ with transform.ToMath "c = \\foo{a^2 + b^2}" }} {{ with .Err }} {{ warnf "error: %s" . }} {{ else }} {{ . }} {{ end }} {{ end }} ``` Note that the new `Result` type behaves like `template.HTML` (or a string if needed) when printed, but it will panic if in a error state. Closes #12748
This commit is contained in:
@@ -5,7 +5,14 @@ const render = function (input) {
|
||||
const data = input.data;
|
||||
const expression = data.expression;
|
||||
const options = data.options;
|
||||
writeOutput({ header: input.header, data: { output: katex.renderToString(expression, options) } });
|
||||
const header = input.header;
|
||||
try {
|
||||
const output = katex.renderToString(expression, options);
|
||||
writeOutput({ header: header, data: { output: output } });
|
||||
} catch (e) {
|
||||
header.err = e.message;
|
||||
writeOutput({ header: header });
|
||||
}
|
||||
};
|
||||
|
||||
readInput(render);
|
||||
|
Reference in New Issue
Block a user