mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
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
This commit is contained in:
@@ -96,6 +96,7 @@ func New() Template {
|
|||||||
"isset": IsSet,
|
"isset": IsSet,
|
||||||
"echoParam": ReturnWhenSet,
|
"echoParam": ReturnWhenSet,
|
||||||
"safeHtml": SafeHtml,
|
"safeHtml": SafeHtml,
|
||||||
|
"markdownify": Markdownify,
|
||||||
"first": First,
|
"first": First,
|
||||||
"where": Where,
|
"where": Where,
|
||||||
"highlight": Highlight,
|
"highlight": Highlight,
|
||||||
@@ -422,6 +423,10 @@ func Highlight(in interface{}, lang string) template.HTML {
|
|||||||
return template.HTML(helpers.Highlight(html.UnescapeString(str), lang))
|
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 {
|
func SafeHtml(text string) template.HTML {
|
||||||
return template.HTML(text)
|
return template.HTML(text)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package tpl
|
package tpl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html/template"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user