mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
e1e1baa1bd
* 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
18 lines
467 B
JavaScript
18 lines
467 B
JavaScript
import { readInput, writeOutput } from './common';
|
|
import katex from 'katex';
|
|
|
|
const render = function (input) {
|
|
const data = input.data;
|
|
const expression = data.expression;
|
|
const options = data.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);
|