Browse Source

Fix wrong package name and clean up tag-building

DRY the tag building for links and images.
pull/5/head
Aaron Fischer 1 year ago
parent
commit
0bec3c3eef
  1. 2
      config.go
  2. 18
      pkg/gmitohtml/convert.go

2
config.go

@ -1,4 +1,4 @@
package gmitohtml
package main
import (
"crypto/tls"

18
pkg/gmitohtml/convert.go

@ -128,7 +128,6 @@ func Convert(page []byte, u string) []byte {
linkLabel = line[splitStart:]
}
// If link ends with gif/png/jpg, add a image instead of a link
parts := strings.Split(string(linkURL), ".")
extension := parts[len(parts)-1]
isImage := false
@ -138,19 +137,14 @@ func Convert(page []byte, u string) []byte {
}
}
uri := html.EscapeString(rewriteURL(string(linkURL), parsedURL))
title := html.EscapeString(string(linkLabel))
// If link ends with gif/png/jpg, add a image instead of a link
if isImage && Config.ConvertImages {
img := append([]byte(`<img src="`), html.EscapeString(rewriteURL(string(linkURL), parsedURL))...)
img = append(img, []byte(`" alt="`)...)
img = append(img, html.EscapeString(string(linkLabel))...)
img = append(img, []byte(`"/>`)...)
result = append(result, img...)
result = append(result, []byte("<img src=\"" + uri + "\" alt=\"" + title + "\">")...)
} else {
link := append([]byte(`<a href="`), html.EscapeString(rewriteURL(string(linkURL), parsedURL))...)
link = append(link, []byte(`">`)...)
link = append(link, html.EscapeString(string(linkLabel))...)
link = append(link, []byte(`</a>`)...)
result = append(result, link...)
result = append(result, []byte("<br>")...)
result = append(result, []byte("<a href=\"" + uri + "\">" + title + "</a><br>")...)
}
continue

Loading…
Cancel
Save