@@ -290,7 +290,7 @@ func (ctx *postProcessCtx) postProcess(rawHTML []byte) ([]byte, error) {
290
290
}
291
291
292
292
for _ , node := range nodes {
293
- ctx .visitNode (node )
293
+ ctx .visitNode (node , true )
294
294
}
295
295
296
296
// Create buffer in which the data will be placed again. We know that the
@@ -313,7 +313,7 @@ func (ctx *postProcessCtx) postProcess(rawHTML []byte) ([]byte, error) {
313
313
return res , nil
314
314
}
315
315
316
- func (ctx * postProcessCtx ) visitNode (node * html.Node ) {
316
+ func (ctx * postProcessCtx ) visitNode (node * html.Node , visitText bool ) {
317
317
// Add user-content- to IDs if they don't already have them
318
318
for idx , attr := range node .Attr {
319
319
if attr .Key == "id" && ! (strings .HasPrefix (attr .Val , "user-content-" ) || blackfridayExtRegex .MatchString (attr .Val )) {
@@ -323,13 +323,37 @@ func (ctx *postProcessCtx) visitNode(node *html.Node) {
323
323
// We ignore code, pre and already generated links.
324
324
switch node .Type {
325
325
case html .TextNode :
326
- ctx .textNode (node )
326
+ if visitText {
327
+ ctx .textNode (node )
328
+ }
327
329
case html .ElementNode :
328
- if node .Data == "a" || node .Data == "code" || node .Data == "pre" {
330
+ if node .Data == "img" {
331
+ attrs := node .Attr
332
+ for idx , attr := range attrs {
333
+ if attr .Key != "src" {
334
+ continue
335
+ }
336
+ link := []byte (attr .Val )
337
+ if len (link ) > 0 && ! IsLink (link ) {
338
+ prefix := ctx .urlPrefix
339
+ if ctx .isWikiMarkdown {
340
+ prefix = util .URLJoin (prefix , "wiki" , "raw" )
341
+ }
342
+ prefix = strings .Replace (prefix , "/src/" , "/media/" , 1 )
343
+
344
+ lnk := string (link )
345
+ lnk = util .URLJoin (prefix , lnk )
346
+ link = []byte (lnk )
347
+ }
348
+ node .Attr [idx ].Val = string (link )
349
+ }
350
+ } else if node .Data == "a" {
351
+ visitText = false
352
+ } else if node .Data == "code" || node .Data == "pre" {
329
353
return
330
354
}
331
355
for n := node .FirstChild ; n != nil ; n = n .NextSibling {
332
- ctx .visitNode (n )
356
+ ctx .visitNode (n , visitText )
333
357
}
334
358
}
335
359
// ignore everything else
0 commit comments