Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorbep <bjorn.erik.pedersen@gmail.com>2014-11-19 00:42:49 +0300
committerspf13 <steve.francia@gmail.com>2014-11-25 07:17:25 +0300
commit53c707bb1d467cde1645dbd7b073493d7a547fe1 (patch)
tree529f0bb303b3d5479349d671299b1924ee89f39b /tpl
parentf04006978ae8c7f630c4b5944b69679ad50d806a (diff)
Add markdownify template filter
Note that this is a Markdownify filter, and is named as such; it's not a Asccidoc filter or in any way connected to a Page. Fixes #524
Diffstat (limited to 'tpl')
-rw-r--r--tpl/template.go5
-rw-r--r--tpl/template_test.go12
2 files changed, 17 insertions, 0 deletions
diff --git a/tpl/template.go b/tpl/template.go
index b536c4626..9ea84dea8 100644
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -96,6 +96,7 @@ func New() Template {
"isset": IsSet,
"echoParam": ReturnWhenSet,
"safeHtml": SafeHtml,
+ "markdownify": Markdownify,
"first": First,
"where": Where,
"highlight": Highlight,
@@ -422,6 +423,10 @@ func Highlight(in interface{}, lang string) template.HTML {
return template.HTML(helpers.Highlight(html.UnescapeString(str), lang))
}
+func Markdownify(text string) template.HTML {
+ return template.HTML(helpers.RenderBytes([]byte(text), "markdown", ""))
+}
+
func SafeHtml(text string) template.HTML {
return template.HTML(text)
}
diff --git a/tpl/template_test.go b/tpl/template_test.go
index 5eff0f067..066c75dde 100644
--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -1,6 +1,7 @@
package tpl
import (
+ "html/template"
"reflect"
"testing"
)
@@ -339,3 +340,14 @@ func TestWhere(t *testing.T) {
}
}
}
+
+func TestMarkdownify(t *testing.T) {
+
+ result := Markdownify("Hello **World!**")
+
+ expect := template.HTML("<p>Hello <strong>World!</strong></p>\n")
+
+ if result != expect {
+ t.Errorf("Markdownify: got '%s', expected '%s'", result, expect)
+ }
+}