mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +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:
@@ -29,7 +29,8 @@ const (
|
||||
|
||||
// indirect returns the value, after dereferencing as many times
|
||||
// as necessary to reach the base type (or nil).
|
||||
func indirect(a any) any {
|
||||
// Signature modified by Hugo. TODO(bep) script this.
|
||||
func doIndirect(a any) any {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"github.com/gohugoio/hugo/common/types"
|
||||
template "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
|
||||
)
|
||||
|
||||
@@ -39,3 +40,14 @@ func (t *Template) Prepare() (*template.Template, error) {
|
||||
func StripTags(html string) string {
|
||||
return stripTags(html)
|
||||
}
|
||||
|
||||
func indirect(a any) any {
|
||||
in := doIndirect(a)
|
||||
|
||||
// We have a special Result type that we want to unwrap when printed.
|
||||
if pp, ok := in.(types.PrintableValueProvider); ok {
|
||||
return pp.PrintableValue()
|
||||
}
|
||||
|
||||
return in
|
||||
}
|
||||
|
Reference in New Issue
Block a user