glamour icon indicating copy to clipboard operation
glamour copied to clipboard

Styling Code vs CodeBlock

Open pnelson opened this issue 4 years ago • 0 comments

I noticed a difference in output when setting colors for Code vs CodeBlock. I was expecting them to be the same colors with my configuration and it seems they are for red and green but others aren't. I'm not sure if I'm using this wrong or if this is a bug. I'm using latest master.

require github.com/charmbracelet/glamour v0.1.1-0.20200527150921-a605339c8b91

Usable repo here but I thought I'd copy below in case I ever delete it.

Source

package main

import (
	"flag"
	"log"
	"os"

	"github.com/charmbracelet/glamour"
	"github.com/charmbracelet/glamour/ansi"
)

var color = flag.String("c", "#546e7a", "color")

func main() {
	flag.Parse()
	err := render(*color)
	if err != nil {
		log.Fatal(err)
	}
}

func render(color string) error {
	styles := glamour.WithStyles(ansi.StyleConfig{
		Code: ansi.StyleBlock{
			StylePrimitive: ansi.StylePrimitive{
				Color: stringPtr(color),
			},
		},
		CodeBlock: ansi.StyleCodeBlock{
			Chroma: &ansi.Chroma{
				Text: ansi.StylePrimitive{
					Color: stringPtr(color),
				},
			},
		},
	})
	renderer, err := glamour.NewTermRenderer(styles)
	if err != nil {
		return err
	}
	b, err := renderer.RenderBytes([]byte("plain text\n\n`code`\n\n```\ncode block\n```\n"))
	if err != nil {
		return err
	}
	_, err = os.Stdout.Write(b)
	return err
}

func stringPtr(s string) *string { return &s }

Output

Apologies for the blurry screenshot.

output

pnelson avatar Jun 25 '20 03:06 pnelson