diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-03-20 16:36:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-03-20 19:15:11 +0100 |
commit | b725253f9e3033e18bd45096c0622e6fb7b1ff79 (patch) | |
tree | a88ffca6a7cddf39df8921a862331a4a917fd8f1 /markup/goldmark | |
parent | 35dedf15c04a605df4d4a09263b0b299e5161f86 (diff) |
Attributes for code fences should be placed after the lang indicator only
Fixes #8313
Diffstat (limited to 'markup/goldmark')
-rw-r--r-- | markup/goldmark/convert_test.go | 12 | ||||
-rw-r--r-- | markup/goldmark/internal/extensions/attributes/attributes.go | 12 |
2 files changed, 20 insertions, 4 deletions
diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index c7367dd01..2b66a1910 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -242,10 +242,20 @@ 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, "\nHi there.\n{.myclass }", diff --git a/markup/goldmark/internal/extensions/attributes/attributes.go b/markup/goldmark/internal/extensions/attributes/attributes.go index ce745295c..e10e7ba79 100644 --- a/markup/goldmark/internal/extensions/attributes/attributes.go +++ b/markup/goldmark/internal/extensions/attributes/attributes.go @@ -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 }) |