Merge pull request #9626 from smemsh/markdown-maxwidth-env
configurable maxwidth for markdown WithWrap()
This commit is contained in:
commit
dfddb16ba3
2 changed files with 15 additions and 3 deletions
|
|
@ -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.
|
||||
`, "`"),
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue