mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-26 10:13:39 +08:00
18 lines
427 B
Go
18 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{' '})
|
||
|
}
|