mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
committed by
Bjørn Erik Pedersen
parent
e25db38467
commit
013c8cfb25
@@ -19,6 +19,7 @@ import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"io"
|
||||
@@ -234,6 +235,7 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er
|
||||
MinRuleThickness: 0.04,
|
||||
ErrorColor: "#cc0000",
|
||||
ThrowOnError: true,
|
||||
Strict: "error",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -243,6 +245,13 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er
|
||||
}
|
||||
}
|
||||
|
||||
switch katexInput.Options.Strict {
|
||||
case "error", "ignore", "warn":
|
||||
// Valid strict mode, continue
|
||||
default:
|
||||
return "", fmt.Errorf("invalid strict mode; expected one of error, ignore, or warn; received %s", katexInput.Options.Strict)
|
||||
}
|
||||
|
||||
s := hashing.HashString(args...)
|
||||
key := "tomath/" + s[:2] + "/" + s[2:]
|
||||
fileCache := ns.deps.ResourceSpec.FileCaches.MiscCache()
|
||||
|
@@ -495,3 +495,44 @@ DATA
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 13729
|
||||
func TestToMathStrictMode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- layouts/all.html --
|
||||
{{ transform.ToMath "a %" dict }}
|
||||
-- foo --
|
||||
`
|
||||
|
||||
// strict mode: default
|
||||
f := strings.ReplaceAll(files, "dict", "")
|
||||
b, err := hugolib.TestE(t, f)
|
||||
b.Assert(err.Error(), qt.Contains, "[commentAtEnd]")
|
||||
|
||||
// strict mode: error
|
||||
f = strings.ReplaceAll(files, "dict", `(dict "strict" "error")`)
|
||||
b, err = hugolib.TestE(t, f)
|
||||
b.Assert(err.Error(), qt.Contains, "[commentAtEnd]")
|
||||
|
||||
// strict mode: ignore
|
||||
f = strings.ReplaceAll(files, "dict", `(dict "strict" "ignore")`)
|
||||
b = hugolib.Test(t, f, hugolib.TestOptWarn())
|
||||
b.AssertLogMatches("")
|
||||
b.AssertFileContent("public/index.html", `<annotation encoding="application/x-tex">a %</annotation>`)
|
||||
|
||||
// strict: warn
|
||||
// TODO: see https://github.com/gohugoio/hugo/issues/13735
|
||||
// f = strings.ReplaceAll(files, "dict", `(dict "strict" "warn")`)
|
||||
// b = hugolib.Test(t, f, hugolib.TestOptWarn())
|
||||
// b.AssertLogMatches("[commentAtEnd]")
|
||||
// b.AssertFileContent("public/index.html", `<annotation encoding="application/x-tex">a %</annotation>`)
|
||||
|
||||
// strict mode: invalid value
|
||||
f = strings.ReplaceAll(files, "dict", `(dict "strict" "foo")`)
|
||||
b, err = hugolib.TestE(t, f)
|
||||
b.Assert(err.Error(), qt.Contains, "invalid strict mode")
|
||||
}
|
||||
|
Reference in New Issue
Block a user