markdown.go 744 B

1234567891011121314151617181920212223242526
  1. package common
  2. import (
  3. "charm.land/glamour/v2"
  4. "github.com/charmbracelet/crush/internal/ui/styles"
  5. )
  6. // MarkdownRenderer returns a glamour [glamour.TermRenderer] configured with
  7. // the given styles and width.
  8. func MarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer {
  9. r, _ := glamour.NewTermRenderer(
  10. glamour.WithStyles(sty.Markdown),
  11. glamour.WithWordWrap(width),
  12. )
  13. return r
  14. }
  15. // PlainMarkdownRenderer returns a glamour [glamour.TermRenderer] with no colors
  16. // (plain text with structure) and the given width.
  17. func PlainMarkdownRenderer(sty *styles.Styles, width int) *glamour.TermRenderer {
  18. r, _ := glamour.NewTermRenderer(
  19. glamour.WithStyles(sty.PlainMarkdown),
  20. glamour.WithWordWrap(width),
  21. )
  22. return r
  23. }