tpl/transform: Display Chroma highlighting errors

Closes #9642
This commit is contained in:
Joe Mooring 2023-12-03 14:38:49 -08:00 committed by Bjørn Erik Pedersen
parent 507f4e356b
commit 4583b41305
2 changed files with 26 additions and 1 deletions

View file

@ -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
<description>&lt;p&gt;a &lt;strong&gt;b&lt;/strong&gt; c&lt;/p&gt;</description>
`)
}
// 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")
}

View file

@ -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
}