markup: Handle attribute lists in code fences

Fixes #8278
This commit is contained in:
Bjørn Erik Pedersen
2021-02-23 18:04:05 +01:00
parent cd0c5d7ef3
commit aed7df62a8
3 changed files with 78 additions and 6 deletions

View File

@@ -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
}