20251209
This commit is contained in:
37
archive/bbs-go-active/server/internal/pkg/markdown/utils.go
Normal file
37
archive/bbs-go-active/server/internal/pkg/markdown/utils.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user