@@ -234,6 +234,23 @@ func RenderCommitMessage(
234
234
return ctx .postProcess (rawHTML )
235
235
}
236
236
237
+ // RenderDescriptionHTML will use similar logic as PostProcess, but will
238
+ // use a single special linkProcessor.
239
+ func RenderDescriptionHTML (
240
+ rawHTML []byte ,
241
+ urlPrefix string ,
242
+ metas map [string ]string ,
243
+ ) ([]byte , error ) {
244
+ ctx := & postProcessCtx {
245
+ metas : metas ,
246
+ urlPrefix : urlPrefix ,
247
+ procs : []processor {
248
+ descriptionLinkProcessor ,
249
+ },
250
+ }
251
+ return ctx .postProcess (rawHTML )
252
+ }
253
+
237
254
var byteBodyTag = []byte ("<body>" )
238
255
var byteBodyTagClosing = []byte ("</body>" )
239
256
@@ -668,3 +685,34 @@ func genDefaultLinkProcessor(defaultLink string) processor {
668
685
node .FirstChild , node .LastChild = ch , ch
669
686
}
670
687
}
688
+
689
+ // descriptionLinkProcessor creates links for DescriptionHTML
690
+ func descriptionLinkProcessor (ctx * postProcessCtx , node * html.Node ) {
691
+ m := linkRegex .FindStringIndex (node .Data )
692
+ if m == nil {
693
+ return
694
+ }
695
+ uri := node .Data [m [0 ]:m [1 ]]
696
+ replaceContent (node , m [0 ], m [1 ], createDescriptionLink (uri , uri ))
697
+ }
698
+
699
+ func createDescriptionLink (href , content string ) * html.Node {
700
+ textNode := & html.Node {
701
+ Type : html .TextNode ,
702
+ Data : content ,
703
+ }
704
+ linkNode := & html.Node {
705
+ FirstChild : textNode ,
706
+ LastChild : textNode ,
707
+ Type : html .ElementNode ,
708
+ Data : "a" ,
709
+ DataAtom : atom .A ,
710
+ Attr : []html.Attribute {
711
+ {Key : "href" , Val : href },
712
+ {Key : "target" , Val : "_blank" },
713
+ {Key : "rel" , Val : "noopener noreferrer" },
714
+ },
715
+ }
716
+ textNode .Parent = linkNode
717
+ return linkNode
718
+ }
0 commit comments