From 7bf14a95b4a4adb7f55308532e7d6ffc8305bdc1 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 3 Jul 2017 22:40:22 +0100 Subject: Template system refined --- templ.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'templ.go') 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 += "" + + for l_num, l := range lines { + ret += "\n" + ret += "" + ret += "" + ret += "" + } + ret += "
"+ strconv.Itoa(l_num+1) + "
"+ l +"
" + 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 -- cgit v1.2.3