From b4eefc9d85acf31dfb50660eb862539fcd5ee9c1 Mon Sep 17 00:00:00 2001 From: Florian Schlachter Date: Sun, 20 Jul 2014 00:42:24 +0200 Subject: [PATCH] markdown-filter added. --- README.md | 13 ++++++++++--- filter_markdown.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 filter_markdown.go diff --git a/README.md b/README.md index fb46171..f41b777 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ -pongo2-addons -============= +# pongo2-addons -Official filter and tag addons for pongo2 +Official filter and tag add-ons for [pongo2](https://github.com/flosch/pongo2). Uses 3rd-party-libraries. + +## Filters + + - **markdown** (parses markdown text and outputs HTML; **hint**: use the **safe**-filter to make the output not being escaped) + +## Tags + +(nothing yet) \ No newline at end of file diff --git a/filter_markdown.go b/filter_markdown.go new file mode 100644 index 0000000..6d40363 --- /dev/null +++ b/filter_markdown.go @@ -0,0 +1,15 @@ +package pongo2addons + +import ( + "github.com/flosch/pongo2" + + "github.com/russross/blackfriday" +) + +func init() { + pongo2.RegisterFilter("markdown", filterMarkdown) +} + +func filterMarkdown(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, error) { + return pongo2.AsValue(string(blackfriday.MarkdownCommon([]byte(in.String())))), nil +}