Attributes for code fences should be placed after the lang indicator only

Fixes #8313
This commit is contained in:
Bjørn Erik Pedersen
2021-03-20 16:36:30 +01:00
parent 35dedf15c0
commit b725253f9e
3 changed files with 28 additions and 4 deletions

View File

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