feat(markdown): add enhanced code blocks with syntax highlighting

- Add codeblock.go for custom Goldmark renderer
- Add code block header with language icon, filename, copy button
- Use Chroma for syntax highlighting with class-based output
- Add GenerateChromaCSS for theme CSS generation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Josh 2026-01-12 02:01:09 +02:00
parent 6e2959f619
commit 771ff7615a
4 changed files with 323 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"strings"
"github.com/alecthomas/chroma/v2"
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/styles"
)
@ -150,3 +151,18 @@ func GenerateHljsCSS(themeName string) (string, error) {
func ListThemes() []string {
return styles.Names()
}
func GenerateChromaCSS(themeName string) (string, error) {
style := styles.Get(themeName)
if style == nil {
style = styles.Get("github")
}
formatter := chromahtml.New(chromahtml.WithClasses(true))
var css strings.Builder
css.WriteString("/* Chroma theme: " + themeName + " */\n")
if err := formatter.WriteCSS(&css, style); err != nil {
return "", err
}
return css.String(), nil
}