0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/caddyhttp/markdown/summary/summary.go
2016-06-05 22:39:23 -06:00

17 lines
427 B
Go

package summary
import (
"bytes"
"github.com/russross/blackfriday"
)
// Markdown formats input using a plain-text renderer, and
// then returns up to the first `wordcount` words as a summary.
func Markdown(input []byte, wordcount int) []byte {
words := bytes.Fields(blackfriday.Markdown(input, renderer{}, 0))
if wordcount > len(words) {
wordcount = len(words)
}
return bytes.Join(words[0:wordcount], []byte{' '})
}