openidec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 55a9f7403c3359bd89b5699b944a0885e38343fc
parent b7a92b6e7b3d665c0c5dfa245583b8d855c2a856
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Sun,  6 Sep 2020 11:49:14 +0300

handle ii:// links

Diffstat:
Mii-node/web.go | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/ii-node/web.go b/ii-node/web.go @@ -458,6 +458,7 @@ func str_esc(l string) string { var quoteRegex = regexp.MustCompile("^[^ >]*>") var urlRegex = regexp.MustCompile(`(http|ftp|https)://[^ <>"]+`) var url2Regex = regexp.MustCompile(`{{{href=[0-9]+}}}`) +var urlIIRegex = regexp.MustCompile(`ii://[a-zA-Z0-9]{20}`) func msg_clean(txt string) string { txt = strings.Replace(txt, "\r", "", -1) @@ -494,6 +495,15 @@ func ReverseStr(s string) string { func msg_esc(l string) string { var links []string link := 0 + l = string(urlIIRegex.ReplaceAllFunc([]byte(l), + func(line []byte) []byte { + s := string(line) + url := strings.TrimPrefix(s, "ii://") + links = append(links, fmt.Sprintf(`<a href="/%s#%s" class="url">%s</a>`, + url, url, str_esc(s))) + link++ + return []byte(fmt.Sprintf(`{{{href=%d}}}`, link-1)) + })) l = string(urlRegex.ReplaceAllFunc([]byte(l), func(line []byte) []byte { s := string(line)