aboutsummaryrefslogtreecommitdiff
path: root/pkg/template/template.go
diff options
context:
space:
mode:
authorSergey Dryabzhinsky <sergey.dryabzhinsky@gmail.com>2018-05-29 01:42:27 +0300
committer无闻 <u@gogs.io>2018-05-29 06:42:27 +0800
commitb5a1daa756b181f15a1318a53aba09478b988e6a (patch)
tree3fbb3cafd2965dbd07e7bada2aa6d2914f503d9e /pkg/template/template.go
parent5a47301dbd85e8d3c240cdf2eb248974b7fe5f06 (diff)
template: simple html filter for repository description (#5242)
* Add markdown renderer function to templates, use it for description in repo template * Fix function call * Define function Md2html in template namespace * Change filter from Md2html to nl2br * Change filter name to NewLine2br as suggested * Update description output: - just replace `\n` by `<br>` - sanitize html after replace
Diffstat (limited to 'pkg/template/template.go')
-rw-r--r--pkg/template/template.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/pkg/template/template.go b/pkg/template/template.go
index dd92ba61..f56194b9 100644
--- a/pkg/template/template.go
+++ b/pkg/template/template.go
@@ -65,6 +65,7 @@ func NewFuncMap() []template.FuncMap {
"Safe": Safe,
"Sanitize": bluemonday.UGCPolicy().Sanitize,
"Str2html": Str2html,
+ "NewLine2br": NewLine2br,
"TimeSince": tool.TimeSince,
"RawTimeSince": tool.RawTimeSince,
"FileSize": tool.FileSize,
@@ -130,6 +131,11 @@ func Str2html(raw string) template.HTML {
return template.HTML(markup.Sanitize(raw))
}
+// Simple filter, converts newline symbols to <br>
+func NewLine2br(raw string) template.HTML {
+ return template.HTML(strings.Replace(raw, "\n", "<br>", -1))
+}
+
func List(l *list.List) chan interface{} {
e := l.Front()
c := make(chan interface{})