Skip to content

feat: add WithLongRenderer option - #100

Open
bdsoha wants to merge 1 commit into
charmbracelet:mainfrom
bdsoha:long-renderer
Open

feat: add WithLongRenderer option#100
bdsoha wants to merge 1 commit into
charmbracelet:mainfrom
bdsoha:long-renderer

Conversation

@bdsoha

@bdsoha bdsoha commented Jul 1, 2026

Copy link
Copy Markdown

Fang renders a command's Long/Short as plain styled text, and there's no hook to transform it first. So if you want Markdown in your long descriptions, there's nowhere to render it — the raw **bold** and - bullets just print as-is.

This adds a small WithLongRenderer(func(string) string) option. The renderer receives the raw long text and returns what should be displayed; a nil renderer (the default) leaves everything exactly as it is, so it's non-breaking. It's threaded through helpFnwriteLongShort and applied right before the existing styles.Text styling.

Typical use is rendering Markdown through glamour:

r, _ := glamour.NewTermRenderer(glamour.WithAutoStyle())

fang.Execute(ctx, root, fang.WithLongRenderer(func(s string) string {
    out, err := r.Render(s)
    if err != nil {
        return s
    }
    return out
}))

I kept it as a generic callback rather than a glamour-specific option, to avoid pulling glamour into fang's dependency tree — but if you'd rather bake it in (say a WithMarkdown() that wires glamour directly), I'm happy to switch to that instead.

Added a test covering that the renderer receives the raw text and its output lands in the help screen.

Render a command's long/short help text through a caller-supplied
function before it is displayed — for example, to render Markdown with
glamour. A nil renderer (the default) leaves the text unchanged, so this
is non-breaking. Threaded through helpFn/writeLongShort, applied right
before the existing text styling.
@bdsoha

bdsoha commented Jul 27, 2026

Copy link
Copy Markdown
Author

@charmcrush Hey, had a chance to look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant