diff --git a/tpl/transform/integration_test.go b/tpl/transform/integration_test.go index 9a68b7ff2c3..3ba65c71511 100644 --- a/tpl/transform/integration_test.go +++ b/tpl/transform/integration_test.go @@ -16,6 +16,7 @@ package transform_test import ( "testing" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/hugolib" ) @@ -85,3 +86,24 @@ a **b** c <p>a <strong>b</strong> c</p> `) } + +// Issue #9642 +func TestHighlightError(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +-- layouts/index.html -- +{{ highlight "a" "b" 0 }} + ` + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ) + + _, err := b.BuildE() + b.Assert(err.Error(), qt.Contains, "error calling highlight: invalid Highlight option: 0") +} diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go index 178db84e412..8078bc0ceac 100644 --- a/tpl/transform/transform.go +++ b/tpl/transform/transform.go @@ -79,7 +79,10 @@ func (ns *Namespace) Highlight(s any, lang string, opts ...any) (template.HTML, } hl := ns.deps.ContentSpec.Converters.GetHighlighter() - highlighted, _ := hl.Highlight(ss, lang, optsv) + highlighted, err := hl.Highlight(ss, lang, optsv) + if err != nil { + return "", err + } return template.HTML(highlighted), nil }