ref: 53c707bb1d467cde1645dbd7b073493d7a547fe1
parent: f04006978ae8c7f630c4b5944b69679ad50d806a
author: bep <[email protected]>
date: Tue Nov 18 17:42:49 EST 2014
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
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -96,6 +96,7 @@
"isset": IsSet,
"echoParam": ReturnWhenSet,
"safeHtml": SafeHtml,
+ "markdownify": Markdownify,
"first": First,
"where": Where,
"highlight": Highlight,
@@ -420,6 +421,10 @@
}
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 {
--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -1,6 +1,7 @@
package tpl
import (
+ "html/template"
"reflect"
"testing"
)
@@ -337,5 +338,16 @@
if !reflect.DeepEqual(results, this.expect) {
t.Errorf("[%d] Where clause matching %v with %v, got %v but expected %v", i, this.key, this.match, results, this.expect)
}
+ }
+}
+
+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)
}
}