mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 13:40:38 +03:00
Add some more KaTeX options
And fix the options handling. Closes #12745 Fixes #12746
This commit is contained in:
parent
946e6af0bb
commit
891aa00fe1
3 changed files with 48 additions and 6 deletions
|
@ -211,13 +211,14 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er
|
|||
katexInput := warpc.KatexInput{
|
||||
Expression: expression,
|
||||
Options: warpc.KatexOptions{
|
||||
Output: "mathml",
|
||||
ThrowOnError: false,
|
||||
Output: "mathml",
|
||||
MinRuleThickness: 0.04,
|
||||
ErrorColor: "#cc0000",
|
||||
},
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
if err := mapstructure.WeakDecode(args[1], &katexInput); err != nil {
|
||||
if err := mapstructure.WeakDecode(args[1], &katexInput.Options); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,3 +149,24 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
|||
<span class="katex"><math
|
||||
`)
|
||||
}
|
||||
|
||||
func TestToMathMacros(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- layouts/index.html --
|
||||
{{ $macros := dict
|
||||
"\\addBar" "\\bar{#1}"
|
||||
"\\bold" "\\mathbf{#1}"
|
||||
}}
|
||||
{{ $opts := dict "macros" $macros }}
|
||||
{{ transform.ToMath "\\addBar{y} + \\bold{H}" $opts }}
|
||||
`
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
<mi>y</mi>
|
||||
`)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue