commit f4d0cd163f605d38bfc0de9a96212c65b274ac58
parent 4ccd5c71fdb810f0dc5b2678b6ae2104c440df64
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Fri, 4 Sep 2020 21:32:03 +0300
formatting
Diffstat:
2 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css
@@ -2,6 +2,17 @@
overflow-wrap: break-word;
}
+.code {
+ overflow-x: auto;
+ white-space: pre-wrap;
+ white-space: -moz-pre-wrap;
+ white-space: -pre-wrap;
+ white-space: -o-pre-wrap;
+ word-wrap: break-word;
+ background: #eaffff;
+ padding: 1em;
+}
+
#body {
max-width: 60em;
margin-left:auto;
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -404,7 +404,22 @@ func msg_format(txt string) template.HTML {
txt = strings.TrimRight(txt, "\n")
txt = strings.TrimSuffix(txt, "\n")
f := ""
+ pre := false
for _, l := range strings.Split(txt, "\n") {
+ if strings.Trim(l, " ") == "====" {
+ if !pre {
+ pre = true
+ f += "<pre class=\"code\">\n"
+ continue
+ }
+ pre = false
+ f += "</pre>\n"
+ continue
+ }
+ if pre {
+ f += l + "\n"
+ continue
+ }
if quoteRegex.MatchString(l) {
l = fmt.Sprintf("<span class=\"quote\">%s</span>", str_esc(l))
} else {
@@ -417,6 +432,10 @@ func msg_format(txt string) template.HTML {
}
f += l + "<br>\n"
}
+ if pre {
+ pre = false
+ f += "</pre>\n"
+ }
return template.HTML(f)
}