]> git.maquefel.me Git - brevno-suite/hugo/commit
Improve Katex error handling and fix handling of large expressions
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 11 Aug 2024 18:31:17 +0000 (20:31 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Aug 2024 11:50:18 +0000 (13:50 +0200)
commite1e1baa1bd33181b32c58524bc21ef21da4880db
tree6840eb247068ee425e8e6955677b90c70b22e3d2
parente42263529c35d966b752690ad1bcb461b90b470d
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
14 files changed:
common/types/types.go
internal/warpc/js/common.js
internal/warpc/js/greet.bundle.js
internal/warpc/js/renderkatex.bundle.js
internal/warpc/js/renderkatex.js
internal/warpc/katex.go
internal/warpc/warpc.go
internal/warpc/wasm/greet.wasm
internal/warpc/wasm/renderkatex.wasm
tpl/internal/go_templates/htmltemplate/content.go
tpl/internal/go_templates/htmltemplate/hugo_template.go
tpl/transform/testdata/large-katex.md [new file with mode: 0644]
tpl/transform/transform.go
tpl/transform/transform_integration_test.go