summaryrefslogtreecommitdiff
path: root/templ.go
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-03 22:40:22 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-03 22:40:22 +0100
commit7bf14a95b4a4adb7f55308532e7d6ffc8305bdc1 (patch)
treed4b0af6ce08e18d23e3bcdbaf9446657b6854bb7 /templ.go
parent8be60b1580de638d2c9151646cb42b78b5f229ae (diff)
Template system refined
Diffstat (limited to 'templ.go')
-rw-r--r--templ.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/templ.go b/templ.go
index f12fbd6..8c290fa 100644
--- a/templ.go
+++ b/templ.go
@@ -34,8 +34,29 @@ import (
"io/ioutil"
"os"
"regexp"
+ "strings"
+ "strconv"
)
+func format_rows(content string) (string) {
+
+ var ret string
+
+ lines := strings.Split(content, "\n")
+
+ ret += "<table class='content'>"
+
+ for l_num, l := range lines {
+ ret += "<tr>\n"
+ ret += "<td class='lineno'><pre>"+ strconv.Itoa(l_num+1) + "</pre></td>"
+ ret += "<td class='line'><pre>"+ l +"</pre></td>"
+ ret += "</tr>"
+ }
+ ret += "</table>"
+ return ret
+}
+
+
func prepare_paste_page(title, date, content, templ_dir string) (string, error) {
s := ""
@@ -72,6 +93,9 @@ func prepare_paste_page(title, date, content, templ_dir string) (string, error)
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(date)))
re, _ = regexp.Compile("{{CONTENT}}")
+ tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(format_rows(content))))
+
+ re, _ = regexp.Compile("{{RAW_CONTENT}}")
tmpl = string(re.ReplaceAll([]byte(tmpl), []byte(content)))
s += tmpl