@@ -227,6 +227,23 @@ func RenderCommitMessage(
227227 return ctx .postProcess (rawHTML )
228228}
229229
230+ // RenderDescriptionHTML will use similar logic as PostProcess, but will
231+ // use a single special linkProcessor.
232+ func RenderDescriptionHTML (
233+ rawHTML []byte ,
234+ urlPrefix string ,
235+ metas map [string ]string ,
236+ ) ([]byte , error ) {
237+ ctx := & postProcessCtx {
238+ metas : metas ,
239+ urlPrefix : urlPrefix ,
240+ procs : []processor {
241+ descriptionLinkProcessor ,
242+ },
243+ }
244+ return ctx .postProcess (rawHTML )
245+ }
246+
230247var byteBodyTag = []byte ("<body>" )
231248var byteBodyTagClosing = []byte ("</body>" )
232249
@@ -658,3 +675,34 @@ func genDefaultLinkProcessor(defaultLink string) processor {
658675 node .FirstChild , node .LastChild = ch , ch
659676 }
660677}
678+
679+ // descriptionLinkProcessor creates links for DescriptionHTML
680+ func descriptionLinkProcessor (ctx * postProcessCtx , node * html.Node ) {
681+ m := linkRegex .FindStringIndex (node .Data )
682+ if m == nil {
683+ return
684+ }
685+ uri := node .Data [m [0 ]:m [1 ]]
686+ replaceContent (node , m [0 ], m [1 ], createDescriptionLink (uri , uri ))
687+ }
688+
689+ func createDescriptionLink (href , content string ) * html.Node {
690+ textNode := & html.Node {
691+ Type : html .TextNode ,
692+ Data : content ,
693+ }
694+ linkNode := & html.Node {
695+ FirstChild : textNode ,
696+ LastChild : textNode ,
697+ Type : html .ElementNode ,
698+ Data : "a" ,
699+ DataAtom : atom .A ,
700+ Attr : []html.Attribute {
701+ {Key : "href" , Val : href },
702+ {Key : "target" , Val : "_blank" },
703+ {Key : "rel" , Val : "noopener noreferrer" },
704+ },
705+ }
706+ textNode .Parent = linkNode
707+ return linkNode
708+ }
0 commit comments