@@ 75,7 75,9 @@ func resolveLink(b, l string) (string, error) {
}
var are = regexp.MustCompile(`<a [^<>]*>`)
+var ire = regexp.MustCompile(`<img [^<>]*>`)
var hre = regexp.MustCompile(`href="([^"]+)"`)
+var sre = regexp.MustCompile(`src="([^"]+)"`)
func processContent(u, content string) (string, error) {
rv := are.ReplaceAllStringFunc(content, func(s string) string {
@@ 89,6 91,17 @@ func processContent(u, content string) (string, error) {
}
return s
})
+ rv = ire.ReplaceAllStringFunc(rv, func(s string) string {
+ matches := sre.FindStringSubmatch(s)
+ if len(matches) > 1 {
+ l, err := resolveLink(u, matches[1])
+ if err != nil {
+ return s
+ }
+ return strings.Replace(s, matches[0], "src=\""+l+"\"", 1)
+ }
+ return s
+ })
return rv, nil
}