diff --git a/tpl/template.go b/tpl/template.go index 2db7c4f79..fc7457e55 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -948,8 +948,14 @@ func Highlight(in interface{}, lang string) template.HTML { return template.HTML(helpers.Highlight(html.UnescapeString(str), lang)) } +var markdownTrimPrefix = []byte("

") +var markdownTrimSuffix = []byte("

\n") + func Markdownify(text string) template.HTML { - return template.HTML(helpers.RenderBytes(&helpers.RenderingContext{Content: []byte(text), PageFmt: "markdown"})) + m := helpers.RenderBytes(&helpers.RenderingContext{Content: []byte(text), PageFmt: "markdown"}) + m = bytes.TrimPrefix(m, markdownTrimPrefix) + m = bytes.TrimSuffix(m, markdownTrimSuffix) + return template.HTML(m) } func refPage(page interface{}, ref, methodName string) template.HTML { diff --git a/tpl/template_test.go b/tpl/template_test.go index 20a887b1c..8e99f2fb4 100644 --- a/tpl/template_test.go +++ b/tpl/template_test.go @@ -956,7 +956,7 @@ func TestMarkdownify(t *testing.T) { result := Markdownify("Hello **World!**") - expect := template.HTML("

Hello World!

\n") + expect := template.HTML("Hello World!") if result != expect { t.Errorf("Markdownify: got '%s', expected '%s'", result, expect)