From 0327da050f809ff6502ef611a0f77a962dbc8a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Mar 2022 10:44:29 +0100 Subject: [PATCH] tpl/transform: Fix it when template.HTML is passes as option to Hightlight Fixes #9591 --- markup/highlight/config.go | 9 ++++++--- tpl/transform/transform_test.go | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/markup/highlight/config.go b/markup/highlight/config.go index 3204ce195..1142c5e11 100644 --- a/markup/highlight/config.go +++ b/markup/highlight/config.go @@ -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 { diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go index 289674bf1..e52e0046d 100644 --- a/tpl/transform/transform_test.go +++ b/tpl/transform/transform_test.go @@ -15,6 +15,7 @@ package transform_test import ( "html/template" + "strings" "testing" "github.com/gohugoio/hugo/common/loggers" @@ -81,6 +82,8 @@ func TestHighlight(t *testing.T) { // Issue #4179 {``, "xml", "", `<`}, {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)