mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 02:52:14 -05:00
parent
bec9b92d0c
commit
be627fa718
2 changed files with 8 additions and 2 deletions
|
@ -948,8 +948,14 @@ func Highlight(in interface{}, lang string) template.HTML {
|
|||
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 {
|
||||
|
|
|
@ -956,7 +956,7 @@ func TestMarkdownify(t *testing.T) {
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue