You've already forked golang-base-project
Improves documentation (#13)
* Documents all env variables and adds an example project * Adds godoc comments * Fixed package naming issue
This commit is contained in:
24
text/html.go
Normal file
24
text/html.go
Normal file
@ -0,0 +1,24 @@
|
||||
package text
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Nl2Br converts \n to HTML <br> tags
|
||||
func Nl2Br(s string) string {
|
||||
return strings.Replace(s, "\n", "<br>", -1)
|
||||
}
|
||||
|
||||
// LinkToHTMLLink converts regular links to HTML links
|
||||
func LinkToHTMLLink(s string) string {
|
||||
s = strings.Replace(s, "\n", " \n ", -1)
|
||||
for _, p := range strings.Split(s, " ") {
|
||||
u, err := url.ParseRequestURI(p)
|
||||
if err == nil && u.Scheme != "" {
|
||||
s = strings.Replace(s, p, fmt.Sprintf("<a href=\"%s\">%s</a>", p, p), 1)
|
||||
}
|
||||
}
|
||||
return strings.Replace(s, " \n ", "\n", -1)
|
||||
}
|
Reference in New Issue
Block a user