mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-15 05:17:52 +01:00
Fix wrong package name and clean up tag-building
DRY the tag building for links and images.
This commit is contained in:
parent
586b293bef
commit
0bec3c3eef
2 changed files with 7 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
package gmitohtml
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
|
|
@ -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…
Reference in a new issue