@@ -322,7 +322,7 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
322
322
node = node .FirstChild
323
323
}
324
324
325
- visitNode (ctx , procs , node , true )
325
+ visitNode (ctx , procs , procs , node )
326
326
327
327
newNodes := make ([]* html.Node , 0 , 5 )
328
328
@@ -354,24 +354,22 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
354
354
return nil
355
355
}
356
356
357
- func visitNode (ctx * RenderContext , procs []processor , node * html.Node , visitText bool ) {
357
+ func visitNode (ctx * RenderContext , procs , textProcs []processor , node * html.Node ) {
358
358
// Add user-content- to IDs if they don't already have them
359
359
for idx , attr := range node .Attr {
360
360
if attr .Key == "id" && ! (strings .HasPrefix (attr .Val , "user-content-" ) || blackfridayExtRegex .MatchString (attr .Val )) {
361
361
node .Attr [idx ].Val = "user-content-" + attr .Val
362
362
}
363
363
364
364
if attr .Key == "class" && attr .Val == "emoji" {
365
- visitText = false
365
+ textProcs = nil
366
366
}
367
367
}
368
368
369
- // We ignore code, pre and already generated links .
369
+ // We ignore code and pre .
370
370
switch node .Type {
371
371
case html .TextNode :
372
- if visitText {
373
- textNode (ctx , procs , node )
374
- }
372
+ textNode (ctx , textProcs , node )
375
373
case html .ElementNode :
376
374
if node .Data == "img" {
377
375
for i , attr := range node .Attr {
@@ -390,7 +388,8 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node, visitText
390
388
node .Attr [i ] = attr
391
389
}
392
390
} else if node .Data == "a" {
393
- visitText = false
391
+ // Restrict text in links to emojis
392
+ textProcs = emojiProcessors
394
393
} else if node .Data == "code" || node .Data == "pre" {
395
394
return
396
395
} else if node .Data == "i" {
@@ -416,7 +415,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node, visitText
416
415
}
417
416
}
418
417
for n := node .FirstChild ; n != nil ; n = n .NextSibling {
419
- visitNode (ctx , procs , n , visitText )
418
+ visitNode (ctx , procs , textProcs , n )
420
419
}
421
420
}
422
421
// ignore everything else
0 commit comments