hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 53c707bb1d467cde1645dbd7b073493d7a547fe1
parent f04006978ae8c7f630c4b5944b69679ad50d806a
Author: bep <bjorn.erik.pedersen@gmail.com>
Date:   Tue, 18 Nov 2014 22:42:49 +0100

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:
Mtpl/template.go | 5+++++
Mtpl/template_test.go | 12++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git 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
@@ -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)
+	}
+}