caddy/caddyhttp/markdown/summary/summary.go

18 lines
427 B
Go
Raw Normal View History

2016-06-06 12:39:23 +08:00
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{' '})
}