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:
parent
6e2959f619
commit
771ff7615a
4 changed files with 323 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue