Skip to content

Commit

Permalink
tpl/transform: Display Chroma highlighting errors
Browse files Browse the repository at this point in the history
Closes #9642
  • Loading branch information
jmooring authored and bep committed Dec 4, 2023
1 parent 507f4e3 commit 4583b41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tpl/transform/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package transform_test
import (
"testing"

qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/hugolib"
)

Expand Down Expand Up @@ -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")
}
5 changes: 4 additions & 1 deletion tpl/transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4583b41

Please sign in to comment.