diff --git a/format/command.go b/format/command.go index 59ce23d..82ebf0c 100644 --- a/format/command.go +++ b/format/command.go @@ -29,7 +29,7 @@ func (o Options) Run() error { switch o.Type { case "code": - output, err = code(input) + output, err = code(input, o.Language) case "emoji": output, err = emoji(input) case "template": diff --git a/format/formats.go b/format/formats.go index a043535..d123135 100644 --- a/format/formats.go +++ b/format/formats.go @@ -9,7 +9,7 @@ import ( "github.com/muesli/termenv" ) -func code(input string) (string, error) { +func code(input, language string) (string, error) { renderer, err := glamour.NewTermRenderer( glamour.WithAutoStyle(), glamour.WithWordWrap(0), @@ -17,7 +17,7 @@ func code(input string) (string, error) { if err != nil { return "", fmt.Errorf("unable to create renderer: %w", err) } - output, err := renderer.Render(fmt.Sprintf("```\n%s\n```", input)) + output, err := renderer.Render(fmt.Sprintf("```%s\n%s\n```", language, input)) if err != nil { return "", fmt.Errorf("unable to render: %w", err) } diff --git a/format/options.go b/format/options.go index 210860b..a24429c 100644 --- a/format/options.go +++ b/format/options.go @@ -4,6 +4,7 @@ package format type Options struct { Template []string `arg:"" optional:"" help:"Template string to format (can also be provided via stdin)"` Theme string `help:"Glamour theme to use for markdown formatting" default:"pink"` + Language string `help:"Programming language to parse code" short:"l" default:""` Type string `help:"Format to use (markdown,template,code,emoji)" enum:"markdown,template,code,emoji" short:"t" default:"markdown"` }