openidec

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

commit c308e2ac9712b5d1813dc6be30dcd912b7f09e8a
parent 5b7152e1711944ed170b8c352bde3f00e6c6b31b
Author: Peter Kosyh <p.kosyh@gmail.com>
Date:   Fri,  4 Sep 2020 21:04:44 +0300

url handling

Diffstat:
Mii-node/lib/style.css | 8+++-----
Mii-node/web.go | 12++++++++++--
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css @@ -1,9 +1,7 @@ -.msgtext { - white-space: pre-wrap; +.text { + overflow-wrap: break-word; } -/* .selected { */ -/* background: red; */ -/* } */ + #body { max-width: 60em; margin-left:auto; diff --git a/ii-node/web.go b/ii-node/web.go @@ -382,8 +382,8 @@ func www_reply(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request, i ii.Error.Printf("Error while store reply msg %s: %s", m.MsgId, err) return err } - topic := m.MsgId - http.Redirect(w, r, "/" + topic + "/-1", http.StatusSeeOther) + // topic := m.MsgId + http.Redirect(w, r, "/" + m.MsgId + "#" + m.MsgId, http.StatusSeeOther) return nil } return nil @@ -397,6 +397,7 @@ func str_esc(l string) string { } var quoteRegex = regexp.MustCompile("^[^>]*>") +var urlRegex = regexp.MustCompile(`(http|ftp|https)://[^ <>"]+`) func msg_format(txt string) template.HTML { txt = strings.Replace(txt, "\r", "", -1) @@ -407,6 +408,13 @@ func msg_format(txt string) template.HTML { for _, l := range strings.Split(txt, "\n") { if quoteRegex.MatchString(l) { l = fmt.Sprintf("<span class=\"quote\">%s</span>", str_esc(l)) + } else { + l = string(urlRegex.ReplaceAllFunc([]byte(l), + func (line []byte) []byte { + s := string(line) + return []byte(fmt.Sprintf(`<a href="%s" class="url">%s</a>`, + s, str_esc(s))) + })) } f += l + "<br>\n" }