aboutsummaryrefslogtreecommitdiffhomepage
path: root/markup/goldmark/codeblocks/render.go
diff options
context:
space:
mode:
Diffstat (limited to 'markup/goldmark/codeblocks/render.go')
-rw-r--r--markup/goldmark/codeblocks/render.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/markup/goldmark/codeblocks/render.go b/markup/goldmark/codeblocks/render.go
index e245688e7..3daad0af6 100644
--- a/markup/goldmark/codeblocks/render.go
+++ b/markup/goldmark/codeblocks/render.go
@@ -16,6 +16,7 @@ package codeblocks
import (
"bytes"
"fmt"
+ "strings"
"sync"
"github.com/alecthomas/chroma/v2/lexers"
@@ -69,7 +70,7 @@ func (r *htmlRenderer) renderCodeBlock(w util.BufWriter, src []byte, node ast.No
}
n := node.(*codeBlock)
- lang := string(n.b.Language(src))
+ lang := getLang(n.b, src)
renderer := ctx.RenderContext().GetRenderer(hooks.CodeBlockRendererType, lang)
if renderer == nil {
return ast.WalkStop, fmt.Errorf("no code renderer found for %q", lang)
@@ -174,6 +175,12 @@ func (c *codeBlockContext) Position() htext.Position {
return c.pos
}
+func getLang(node *ast.FencedCodeBlock, src []byte) string {
+ langWithAttributes := string(node.Language(src))
+ lang, _, _ := strings.Cut(langWithAttributes, "{")
+ return lang
+}
+
func getAttributes(node *ast.FencedCodeBlock, infostr []byte) []ast.Attribute {
if node.Attributes() != nil {
return node.Attributes()
@@ -188,7 +195,7 @@ func getAttributes(node *ast.FencedCodeBlock, infostr []byte) []ast.Attribute {
}
}
- if attrStartIdx > 0 {
+ if attrStartIdx != -1 {
n := ast.NewTextBlock() // dummy node for storing attributes
attrStr := infostr[attrStartIdx:]
if attrs, hasAttr := parser.ParseAttributes(text.NewReader(attrStr)); hasAttr {