summaryrefslogtreecommitdiffstats
path: root/markup/goldmark/convert.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-02-23 18:04:05 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-02-24 11:16:06 +0100
commitaed7df62a811b07b73ec5cbbf03e69e4bbf00919 (patch)
tree6099181308f9f6fe5126a3eac85a73ff601df52e /markup/goldmark/convert.go
parentcd0c5d7ef32cbd570af00c50ce760452381df64e (diff)
markup: Handle attribute lists in code fences
Fixes #8278
Diffstat (limited to 'markup/goldmark/convert.go')
-rw-r--r--markup/goldmark/convert.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go
index 629e2b15a..639fddace 100644
--- a/markup/goldmark/convert.go
+++ b/markup/goldmark/convert.go
@@ -22,6 +22,7 @@ import (
"runtime/debug"
"github.com/gohugoio/hugo/markup/goldmark/internal/extensions/attributes"
+ "github.com/yuin/goldmark/ast"
"github.com/gohugoio/hugo/identity"
@@ -321,7 +322,28 @@ func newHighlighting(cfg highlight.Config) goldmark.Extender {
highlight.WriteCodeTag(w, language)
return
}
- w.WriteString(`<div class="highlight">`)
+
+ w.WriteString(`<div class="highlight`)
+
+ var attributes []ast.Attribute
+ if ctx.Attributes() != nil {
+ attributes = ctx.Attributes().All()
+ }
+
+ if attributes != nil {
+ class, found := ctx.Attributes().GetString("class")
+ if found {
+ w.WriteString(" ")
+ w.Write(util.EscapeHTML(class.([]byte)))
+
+ }
+ _, _ = w.WriteString("\"")
+ renderAttributes(w, true, attributes...)
+ } else {
+ _, _ = w.WriteString("\"")
+ }
+
+ w.WriteString(">")
return
}