shithub: hugo

Download patch

ref: be627fa718d23278aeb53da5651a8a4a1be14c27
parent: bec9b92d0cf45a893d3cd56460270b55d97c93f7
author: bep <[email protected]>
date: Wed Apr 1 11:40:08 EDT 2015

Remove paragraph tags produced by markdownify

Fixes #1025

--- a/tpl/template.go
+++ b/tpl/template.go
@@ -948,8 +948,14 @@
 	return template.HTML(helpers.Highlight(html.UnescapeString(str), lang))
 }
 
+var markdownTrimPrefix = []byte("<p>")
+var markdownTrimSuffix = []byte("</p>\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 {
--- a/tpl/template_test.go
+++ b/tpl/template_test.go
@@ -956,7 +956,7 @@
 
 	result := Markdownify("Hello **World!**")
 
-	expect := template.HTML("<p>Hello <strong>World!</strong></p>\n")
+	expect := template.HTML("Hello <strong>World!</strong>")
 
 	if result != expect {
 		t.Errorf("Markdownify: got '%s', expected '%s'", result, expect)