mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-15 07:27: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 (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
|
@ -128,7 +128,6 @@ func Convert(page []byte, u string) []byte {
|
||||||
linkLabel = line[splitStart:]
|
linkLabel = line[splitStart:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// If link ends with gif/png/jpg, add a image instead of a link
|
|
||||||
parts := strings.Split(string(linkURL), ".")
|
parts := strings.Split(string(linkURL), ".")
|
||||||
extension := parts[len(parts)-1]
|
extension := parts[len(parts)-1]
|
||||||
isImage := false
|
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 {
|
if isImage && Config.ConvertImages {
|
||||||
img := append([]byte(`<img src="`), html.EscapeString(rewriteURL(string(linkURL), parsedURL))...)
|
result = append(result, []byte("<img src=\"" + uri + "\" alt=\"" + title + "\">")...)
|
||||||
img = append(img, []byte(`" alt="`)...)
|
|
||||||
img = append(img, html.EscapeString(string(linkLabel))...)
|
|
||||||
img = append(img, []byte(`"/>`)...)
|
|
||||||
result = append(result, img...)
|
|
||||||
} else {
|
} else {
|
||||||
link := append([]byte(`<a href="`), html.EscapeString(rewriteURL(string(linkURL), parsedURL))...)
|
result = append(result, []byte("<a href=\"" + uri + "\">" + title + "</a><br>")...)
|
||||||
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>")...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue