@@ -7,38 +7,54 @@ import (
77 "github.com/charmbracelet/glamour"
88)
99
10- func Render (text , style string , baseURL string ) (string , error ) {
10+ type RenderOpts []glamour.TermRendererOption
11+
12+ func render (text string , opts RenderOpts ) (string , error ) {
1113 // Glamour rendering preserves carriage return characters in code blocks, but
1214 // we need to ensure that no such characters are present in the output.
1315 text = strings .ReplaceAll (text , "\r \n " , "\n " )
1416
15- tr , err := glamour .NewTermRenderer (
16- glamour .WithStylePath (style ),
17- glamour .WithBaseURL (baseURL ),
18- // glamour.WithWordWrap(80), // TODO: make configurable
19- )
17+ tr , err := glamour .NewTermRenderer (opts ... )
2018 if err != nil {
2119 return "" , err
2220 }
2321
2422 return tr .Render (text )
2523}
2624
27- func RenderWrap (text , style string , wrap int ) (string , error ) {
28- // Glamour rendering preserves carriage return characters in code blocks, but
29- // we need to ensure that no such characters are present in the output.
30- text = strings .ReplaceAll (text , "\r \n " , "\n " )
25+ func Render (text , style string ) (string , error ) {
26+ opts := RenderOpts {
27+ glamour .WithStylePath (style ),
28+ }
29+
30+ return render (text , opts )
31+ }
32+
33+ func RenderWithOpts (text , style string , opts RenderOpts ) (string , error ) {
34+ defaultOpts := RenderOpts {
35+ glamour .WithStylePath (style ),
36+ }
37+ opts = append (defaultOpts , opts ... )
38+
39+ return render (text , opts )
40+ }
41+
42+ func RenderWithBaseURL (text , style , baseURL string ) (string , error ) {
43+ opts := RenderOpts {
44+ glamour .WithStylePath (style ),
45+ glamour .WithBaseURL (baseURL ),
46+ }
47+
48+ return render (text , opts )
49+ }
3150
32- tr , err := glamour .NewTermRenderer (
51+ func RenderWithWrap (text , style string , wrap int ) (string , error ) {
52+ opts := RenderOpts {
3353 glamour .WithStylePath (style ),
34- // glamour.WithBaseURL(""), // TODO: make configurable
3554 glamour .WithWordWrap (wrap ),
36- )
37- if err != nil {
38- return "" , err
3955 }
4056
41- return tr . Render (text )
57+ return render (text , opts )
4258}
4359
4460func GetStyle (defaultStyle string ) string {
0 commit comments