mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Attributes for code fences should be placed after the lang indicator only
Fixes #8313
This commit is contained in:
@@ -242,9 +242,19 @@ func TestConvertAttributes(t *testing.T) {
|
||||
withBlockAttributes(conf)
|
||||
conf.Highlight.CodeFences = true
|
||||
},
|
||||
"```bash\necho 'foo';\n````\n{.myclass id=\"myid\"}",
|
||||
"```bash {.myclass id=\"myid\"}\necho 'foo';\n````\n",
|
||||
"<div class=\"highlight myclass\" id=\"myid\"><pre style",
|
||||
},
|
||||
{
|
||||
"Code block, CodeFences=true,linenos=table",
|
||||
func(conf *markup_config.Config) {
|
||||
withBlockAttributes(conf)
|
||||
conf.Highlight.CodeFences = true
|
||||
},
|
||||
"```bash {linenos=table .myclass id=\"myid\"}\necho 'foo';\n````\n{ .adfadf }",
|
||||
[]string{"div class=\"highlight myclass\" id=\"myid\"><div s",
|
||||
"table style"},
|
||||
},
|
||||
{
|
||||
"Paragraph",
|
||||
withBlockAttributes,
|
||||
|
@@ -97,10 +97,16 @@ type transformer struct{}
|
||||
func (a *transformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context) {
|
||||
var attributes = make([]ast.Node, 0, 500)
|
||||
ast.Walk(node, func(node ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||
if entering && node.Kind() == kindAttributesBlock && !node.HasBlankPreviousLines() {
|
||||
attributes = append(attributes, node)
|
||||
return ast.WalkSkipChildren, nil
|
||||
if entering && node.Kind() == kindAttributesBlock {
|
||||
// Attributes for fenced code blocks are handled in their own extension,
|
||||
// but note that we currently only support code block attributes when
|
||||
// CodeFences=true.
|
||||
if node.PreviousSibling().Kind() != ast.KindFencedCodeBlock && !node.HasBlankPreviousLines() {
|
||||
attributes = append(attributes, node)
|
||||
return ast.WalkSkipChildren, nil
|
||||
}
|
||||
}
|
||||
|
||||
return ast.WalkContinue, nil
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user