Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2021-12-07 01:53:09 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-12-07 13:26:56 +0300
commit5538507e9053a00faa358b92ad0bb004e8d28daf (patch)
treeb8436333c4467d474261e2256cb8af4b3b18c513 /tpl/transform
parentb4f27ef8e75a0a6f6ce693270f7ff3114ef4f59a (diff)
tpl/transform: Optional options for highlight func
Closes #9249 Fixes gohugoio/hugoDocs#63
Diffstat (limited to 'tpl/transform')
-rw-r--r--tpl/transform/transform.go12
-rw-r--r--tpl/transform/transform_test.go4
2 files changed, 12 insertions, 4 deletions
diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go
index 82756ed97..8ea91f234 100644
--- a/tpl/transform/transform.go
+++ b/tpl/transform/transform.go
@@ -59,13 +59,21 @@ func (ns *Namespace) Emojify(s interface{}) (template.HTML, error) {
// Highlight returns a copy of s as an HTML string with syntax
// highlighting applied.
-func (ns *Namespace) Highlight(s interface{}, lang, opts string) (template.HTML, error) {
+func (ns *Namespace) Highlight(s interface{}, lang string, opts ...interface{}) (template.HTML, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return "", err
}
- highlighted, _ := ns.deps.ContentSpec.Converters.Highlight(ss, lang, opts)
+ sopts := ""
+ if len(opts) > 0 {
+ sopts, err = cast.ToStringE(opts[0])
+ if err != nil {
+ return "", err
+ }
+ }
+
+ highlighted, _ := ns.deps.ContentSpec.Converters.Highlight(ss, lang, sopts)
return template.HTML(highlighted), nil
}
diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go
index 1dbf97f98..2b0c69d09 100644
--- a/tpl/transform/transform_test.go
+++ b/tpl/transform/transform_test.go
@@ -26,7 +26,6 @@ import (
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/langs"
-
)
type tstNoStringer struct{}
@@ -71,10 +70,11 @@ func TestHighlight(t *testing.T) {
for _, test := range []struct {
s interface{}
lang string
- opts string
+ opts interface{}
expect interface{}
}{
{"func boo() {}", "go", "", "boo"},
+ {"func boo() {}", "go", nil, "boo"},
// Issue #4179
{`<Foo attr=" &lt; "></Foo>`, "xml", "", `&amp;lt;`},
{tstNoStringer{}, "go", "", false},