diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-07-03 22:40:22 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-07-03 22:40:22 +0100 |
commit | 7bf14a95b4a4adb7f55308532e7d6ffc8305bdc1 (patch) | |
tree | d4b0af6ce08e18d23e3bcdbaf9446657b6854bb7 /templ.go | |
parent | 8be60b1580de638d2c9151646cb42b78b5f229ae (diff) |
Template system refined
Diffstat (limited to 'templ.go')
-rw-r--r-- | templ.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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 |