Skip to content

Commit

Permalink
tpl/transform: Fix it when template.HTML is passes as option to Hight…
Browse files Browse the repository at this point in the history
…light

Fixes #9591
  • Loading branch information
bep committed Mar 2, 2022
1 parent 9b8b6d3 commit 0327da0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions markup/highlight/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ func applyOptions(opts interface{}, cfg *Config) error {
switch vv := opts.(type) {
case map[string]interface{}:
return applyOptionsFromMap(vv, cfg)
case string:
return applyOptionsFromString(vv, cfg)
default:
s, err := cast.ToStringE(opts)
if err != nil {
return err
}
return applyOptionsFromString(s, cfg)
}
return nil
}

func applyOptionsFromString(opts string, cfg *Config) error {
Expand Down
3 changes: 3 additions & 0 deletions tpl/transform/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package transform_test

import (
"html/template"
"strings"
"testing"

"github.com/gohugoio/hugo/common/loggers"
Expand Down Expand Up @@ -81,6 +82,8 @@ func TestHighlight(t *testing.T) {
// Issue #4179
{`<Foo attr=" &lt; "></Foo>`, "xml", "", `&amp;lt;`},
{tstNoStringer{}, "go", "", false},
// Issue #9591
{strings.Repeat("AAA \n", 10), "bash", template.HTML("linenos=true,noClasses=false"), "line"},
} {

result, err := ns.Highlight(test.s, test.lang, test.opts)
Expand Down

0 comments on commit 0327da0

Please sign in to comment.