Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c36608c

Browse files
jmooringbep
authored andcommitted
markup/goldmark/codeblocks: Always split Chroma options into .Options
Closes #14909
1 parent 1e4037c commit c36608c

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

markup/goldmark/codeblocks/codeblocks_integration_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Attributes: {{ .Attributes }}|Type: {{ .Type }}|
276276
}
277277

278278
// Issue 9571
279+
// Issue 14909
279280
func TestAttributesChroma(t *testing.T) {
280281
t.Parallel()
281282

@@ -288,7 +289,7 @@ title: "p1"
288289
289290
## Code
290291
291-
§§§LANGUAGE {style=monokai}
292+
§§§LANGUAGE {style=monokai class=my-class tabWidth=8}
292293
echo "p1";
293294
§§§
294295
-- layouts/single.html --
@@ -304,8 +305,9 @@ Attributes: {{ .Attributes }}|Options: {{ .Options }}|
304305
b.AssertFileContent("public/p1/index.html", expect)
305306
}
306307

307-
testLanguage("bash", "Attributes: map[]|Options: map[style:monokai]|")
308-
testLanguage("hugo", "Attributes: map[style:monokai]|Options: map[]|")
308+
testLanguage("bash", "Attributes: map[class:my-class]|Options: map[style:monokai tabWidth:8]|")
309+
testLanguage("hugo", "Attributes: map[class:my-class]|Options: map[style:monokai tabWidth:8]|")
310+
testLanguage("", "Attributes: map[class:my-class]|Options: map[style:monokai tabWidth:8]|")
309311
}
310312

311313
func TestPanics(t *testing.T) {

markup/goldmark/codeblocks/render.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
htext "github.com/gohugoio/hugo/common/text"
2424
"github.com/gohugoio/hugo/markup/converter/hooks"
2525
"github.com/gohugoio/hugo/markup/goldmark/internal/render"
26-
"github.com/gohugoio/hugo/markup/highlight/chromalexers"
2726
"github.com/gohugoio/hugo/markup/internal/attributes"
2827
"github.com/yuin/goldmark"
2928
"github.com/yuin/goldmark/ast"
@@ -89,13 +88,6 @@ func (r *htmlRenderer) renderCodeBlock(w util.BufWriter, src []byte, node ast.No
8988
info = n.Info.Segment.Value(src)
9089
}
9190

92-
attrtp := attributes.AttributesOwnerCodeBlockCustom
93-
if isd, ok := renderer.(hooks.IsDefaultCodeBlockRendererProvider); (ok && isd.IsDefaultCodeBlockRenderer()) || chromalexers.Get(lang) != nil {
94-
// We say that this is a Chroma code block if it's the default code block renderer
95-
// or if the language is supported by Chroma.
96-
attrtp = attributes.AttributesOwnerCodeBlockChroma
97-
}
98-
9991
attrs, attrStr, err := getAttributes(n, info)
10092
if err != nil {
10193
return ast.WalkStop, &herrors.TextSegmentError{Err: err, Segment: attrStr}
@@ -105,7 +97,7 @@ func (r *htmlRenderer) renderCodeBlock(w util.BufWriter, src []byte, node ast.No
10597
BaseContext: render.NewBaseContext(ctx, renderer, node, src, ordinal),
10698
lang: lang,
10799
code: s,
108-
AttributesHolder: attributes.New(attrs, attrtp),
100+
AttributesHolder: attributes.New(attrs, attributes.AttributesOwnerCodeBlockChroma),
109101
}
110102

111103
cr := renderer.(hooks.CodeBlockRenderer)

0 commit comments

Comments
 (0)