@@ -21,6 +21,7 @@ import (
2121 "unicode"
2222
2323 "github.com/pkg/errors"
24+ "github.com/russross/blackfriday/v2"
2425 "k8s.io/gengo/parser"
2526 "k8s.io/gengo/types"
2627 "k8s.io/klog"
@@ -52,6 +53,9 @@ type generatorConfig struct {
5253 // TypeDisplayNamePrefixOverrides is a mapping of how to override displayed
5354 // name for types with certain prefixes with what value.
5455 TypeDisplayNamePrefixOverrides map [string ]string `json:"typeDisplayNamePrefixOverrides"`
56+
57+ // MarkdownDisabled controls markdown rendering for comment lines.
58+ MarkdownDisabled bool `json:"markdownDisabled"`
5559}
5660
5761type externalPackage struct {
@@ -252,15 +256,23 @@ func isLocalType(t *types.Type) bool {
252256 return false
253257}
254258
255- func showComments (s []string ) string {
259+ func renderComments (s []string , markdown bool ) string {
256260 s = filterCommentTags (s )
257- return strings .Join (s , "\n " )
261+ doc := strings .Join (s , "\n " )
262+
263+ if markdown {
264+ // TODO(ahmetb): when a comment includes stuff like "http://<service>"
265+ // we treat this as a HTML tag with markdown renderer below. solve this.
266+ return string (blackfriday .Run ([]byte (doc )))
267+ }
268+ return nl2br (doc )
258269}
259270
271+ func safe (s string ) template.HTML { return template .HTML (s ) }
272+
260273func nl2br (s string ) string {
261274 return strings .Replace (s , "\n \n " , string (template .HTML ("<br/><br/>" )), - 1 )
262275}
263- func safe (s string ) template.HTML { return template .HTML (s ) }
264276
265277func hiddenMember (m types.Member , c generatorConfig ) bool {
266278 for _ , v := range c .HiddenMemberFields {
@@ -484,8 +496,7 @@ func render(w io.Writer, pkgs []*types.Package, config generatorConfig) error {
484496 "typeIdentifier" : func (t * types.Type ) string { return typeIdentifier (t , config ) },
485497 "typeDisplayName" : func (t * types.Type ) string { return typeDisplayName (t , config ) },
486498 "visibleTypes" : func (t []* types.Type ) []* types.Type { return visibleTypes (t , config ) },
487- "showComments" : showComments ,
488- "nl2br" : nl2br ,
499+ "renderComments" : func (s []string ) string { return renderComments (s , ! config .MarkdownDisabled ) },
489500 "packageDisplayName" : packageDisplayName ,
490501 "apiGroup" : func (t * types.Type ) string { return apiVersions [t .Name .Package ] },
491502 "linkForType" : func (t * types.Type ) string {
0 commit comments