diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index 3da5bf476..e76dd2271 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -99,6 +99,10 @@ var HelpTopics = []helpTopic{ %[1]sGH_PATH%[1]s: set the path to the gh executable, useful for when gh can not properly determine its own path such as in the cygwin terminal. + + %[1]sGH_MDWIDTH%[1]s: default maximum width for markdown render wrapping. The max width of lines + wrapped on the terminal will be taken as the lesser of the terminal width, this value, or 120 if + not specified. This value is used, for example, with %[1]spr view%[1]s subcommand. `, "`"), }, { diff --git a/pkg/markdown/markdown.go b/pkg/markdown/markdown.go index f3f4951af..63bd9233e 100644 --- a/pkg/markdown/markdown.go +++ b/pkg/markdown/markdown.go @@ -1,6 +1,9 @@ package markdown import ( + "os" + "strconv" + "github.com/charmbracelet/glamour" ghMarkdown "github.com/cli/go-gh/v2/pkg/markdown" ) @@ -10,11 +13,16 @@ func WithoutIndentation() glamour.TermRendererOption { } // WithWrap is a rendering option that set the character limit for soft -// wrapping the markdown rendering. There is a max limit of 120 characters. +// 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 { - if w > 120 { - w = 120 + width, err := strconv.Atoi(os.Getenv("GH_MDWIDTH")) + if err != nil { + width = 120 + } + if w > width { + w = width } return ghMarkdown.WithWrap(w) }