@@ -80,15 +80,10 @@ const keywordClass = "issue-keyword"
8080
8181// IsLink reports whether link fits valid format.
8282func IsLink (link []byte ) bool {
83- return isLink (link )
84- }
85-
86- // isLink reports whether link fits valid format.
87- func isLink (link []byte ) bool {
8883 return validLinksPattern .Match (link )
8984}
9085
91- func isLinkStr (link string ) bool {
86+ func IsLinkStr (link string ) bool {
9287 return validLinksPattern .MatchString (link )
9388}
9489
@@ -344,7 +339,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
344339 node = node .FirstChild
345340 }
346341
347- visitNode (ctx , procs , procs , node )
342+ visitNode (ctx , procs , node )
348343
349344 newNodes := make ([]* html.Node , 0 , 5 )
350345
@@ -375,7 +370,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
375370 return nil
376371}
377372
378- func visitNode (ctx * RenderContext , procs , textProcs []processor , node * html.Node ) {
373+ func visitNode (ctx * RenderContext , procs []processor , node * html.Node ) {
379374 // Add user-content- to IDs and "#" links if they don't already have them
380375 for idx , attr := range node .Attr {
381376 val := strings .TrimPrefix (attr .Val , "#" )
@@ -390,35 +385,29 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node
390385 }
391386
392387 if attr .Key == "class" && attr .Val == "emoji" {
393- textProcs = nil
388+ procs = nil
394389 }
395390 }
396391
397392 // We ignore code and pre.
398393 switch node .Type {
399394 case html .TextNode :
400- textNode (ctx , textProcs , node )
395+ textNode (ctx , procs , node )
401396 case html .ElementNode :
402397 if node .Data == "img" {
403398 for i , attr := range node .Attr {
404399 if attr .Key != "src" {
405400 continue
406401 }
407- if len (attr .Val ) > 0 && ! isLinkStr (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
408- prefix := ctx .URLPrefix
409- if ctx .IsWiki {
410- prefix = util .URLJoin (prefix , "wiki" , "raw" )
411- }
412- prefix = strings .Replace (prefix , "/src/" , "/media/" , 1 )
413-
414- attr .Val = util .URLJoin (prefix , attr .Val )
402+ if len (attr .Val ) > 0 && ! IsLinkStr (attr .Val ) && ! strings .HasPrefix (attr .Val , "data:image/" ) {
403+ attr .Val = util .URLJoin (ctx .Links .ResolveMediaLink (ctx .IsWiki ), attr .Val )
415404 }
416405 attr .Val = camoHandleLink (attr .Val )
417406 node .Attr [i ] = attr
418407 }
419408 } else if node .Data == "a" {
420409 // Restrict text in links to emojis
421- textProcs = emojiProcessors
410+ procs = emojiProcessors
422411 } else if node .Data == "code" || node .Data == "pre" {
423412 return
424413 } else if node .Data == "i" {
@@ -444,7 +433,7 @@ func visitNode(ctx *RenderContext, procs, textProcs []processor, node *html.Node
444433 }
445434 }
446435 for n := node .FirstChild ; n != nil ; n = n .NextSibling {
447- visitNode (ctx , procs , textProcs , n )
436+ visitNode (ctx , procs , n )
448437 }
449438 }
450439 // ignore everything else
@@ -641,10 +630,6 @@ func mentionProcessor(ctx *RenderContext, node *html.Node) {
641630}
642631
643632func shortLinkProcessor (ctx * RenderContext , node * html.Node ) {
644- shortLinkProcessorFull (ctx , node , false )
645- }
646-
647- func shortLinkProcessorFull (ctx * RenderContext , node * html.Node , noLink bool ) {
648633 next := node .NextSibling
649634 for node != nil && node != next {
650635 m := shortLinkPattern .FindStringSubmatchIndex (node .Data )
@@ -665,7 +650,7 @@ func shortLinkProcessorFull(ctx *RenderContext, node *html.Node, noLink bool) {
665650 if equalPos := strings .IndexByte (v , '=' ); equalPos == - 1 {
666651 // There is no equal in this argument; this is a mandatory arg
667652 if props ["name" ] == "" {
668- if isLinkStr (v ) {
653+ if IsLinkStr (v ) {
669654 // If we clearly see it is a link, we save it so
670655
671656 // But first we need to ensure, that if both mandatory args provided
@@ -740,7 +725,7 @@ func shortLinkProcessorFull(ctx *RenderContext, node *html.Node, noLink bool) {
740725 DataAtom : atom .A ,
741726 }
742727 childNode .Parent = linkNode
743- absoluteLink := isLinkStr (link )
728+ absoluteLink := IsLinkStr (link )
744729 if ! absoluteLink {
745730 if image {
746731 link = strings .ReplaceAll (link , " " , "+" )
@@ -751,16 +736,9 @@ func shortLinkProcessorFull(ctx *RenderContext, node *html.Node, noLink bool) {
751736 link = url .PathEscape (link )
752737 }
753738 }
754- urlPrefix := ctx .URLPrefix
755739 if image {
756740 if ! absoluteLink {
757- if IsSameDomain (urlPrefix ) {
758- urlPrefix = strings .Replace (urlPrefix , "/src/" , "/raw/" , 1 )
759- }
760- if ctx .IsWiki {
761- link = util .URLJoin ("wiki" , "raw" , link )
762- }
763- link = util .URLJoin (urlPrefix , link )
741+ link = util .URLJoin (ctx .Links .ResolveMediaLink (ctx .IsWiki ), link )
764742 }
765743 title := props ["title" ]
766744 if title == "" {
@@ -789,18 +767,15 @@ func shortLinkProcessorFull(ctx *RenderContext, node *html.Node, noLink bool) {
789767 } else {
790768 if ! absoluteLink {
791769 if ctx .IsWiki {
792- link = util .URLJoin ("wiki" , link )
770+ link = util .URLJoin (ctx .Links .WikiLink (), link )
771+ } else {
772+ link = util .URLJoin (ctx .Links .SrcLink (), link )
793773 }
794- link = util .URLJoin (urlPrefix , link )
795774 }
796775 childNode .Type = html .TextNode
797776 childNode .Data = name
798777 }
799- if noLink {
800- linkNode = childNode
801- } else {
802- linkNode .Attr = []html.Attribute {{Key : "href" , Val : link }}
803- }
778+ linkNode .Attr = []html.Attribute {{Key : "href" , Val : link }}
804779 replaceContent (node , m [0 ], m [1 ], linkNode )
805780 node = node .NextSibling .NextSibling
806781 }
0 commit comments