cli/pkg/markdown/markdown.go
Kynan Ware b8ee5c5eba Add godoc comments to exported symbols in remaining packages
Add documentation comments to exported symbols across all remaining
smaller packages including cmd/gen-docs, context, internal/browser,
internal/gh, internal/ghcmd, internal/ghinstance, internal/ghrepo,
internal/keyring, internal/run, internal/safepaths, internal/tableprinter,
internal/text, internal/update, pkg/cmd/accessibility, pkg/cmd/actions,
pkg/cmd/alias, pkg/cmd/api, pkg/cmd/browse, pkg/cmd/cache,
pkg/cmd/completion, pkg/cmd/copilot, pkg/cmd/factory, pkg/cmd/gpg-key,
pkg/cmd/label, pkg/cmd/licenses, pkg/cmd/org, pkg/cmd/preview,
pkg/cmd/ssh-key, pkg/cmd/version, pkg/extensions, pkg/jsoncolor,
pkg/markdown, pkg/option, pkg/set, pkg/ssh, pkg/surveyext, test,
internal/authflow, and utils.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-04 16:14:20 -07:00

44 lines
1.3 KiB
Go

package markdown
import (
"os"
"strconv"
"github.com/charmbracelet/glamour"
ghMarkdown "github.com/cli/go-gh/v2/pkg/markdown"
)
// WithoutIndentation returns a render option that disables indentation.
func WithoutIndentation() glamour.TermRendererOption {
return ghMarkdown.WithoutIndentation()
}
// WithWrap is a rendering option that set the character limit for soft
// wrapping the markdown rendering. There is a max limit of 120 characters,
// unless the user overrides with an environment variable.
// If 0 is passed then wrapping is disabled.
func WithWrap(w int) glamour.TermRendererOption {
width, err := strconv.Atoi(os.Getenv("GH_MDWIDTH"))
if err != nil {
width = 120
}
if w > width {
w = width
}
return ghMarkdown.WithWrap(w)
}
// WithTheme returns a render option that sets the glamour theme.
func WithTheme(theme string) glamour.TermRendererOption {
return ghMarkdown.WithTheme(theme)
}
// WithBaseURL returns a render option that sets the base URL for relative links.
func WithBaseURL(u string) glamour.TermRendererOption {
return ghMarkdown.WithBaseURL(u)
}
// Render converts markdown text to a terminal-friendly format.
func Render(text string, opts ...glamour.TermRendererOption) (string, error) {
return ghMarkdown.Render(text, opts...)
}