Files
common-server-public/bbs-go-active/server/internal/pkg/markdown/utils.go
2025-03-03 17:43:50 +08:00

38 lines
662 B
Go

package markdown
import (
"bbs-go/internal/pkg/html"
"sync"
"github.com/88250/lute"
"github.com/mlogclub/simple/common/strs"
)
var (
engine *lute.Lute
once sync.Once
)
func getEngine() *lute.Lute {
once.Do(func() {
engine = lute.New(func(lute *lute.Lute) {
// lute.SetToC(true)
lute.SetSanitize(true)
lute.SetGFMTaskListItem(true)
})
})
return engine
}
func ToHTML(markdownStr string) string {
if strs.IsBlank(markdownStr) {
return ""
}
return getEngine().MarkdownStr("", markdownStr)
}
func GetSummary(markdownStr string, summaryLen int) string {
htmlStr := ToHTML(markdownStr)
return html.GetSummary(htmlStr, summaryLen)
}