This commit is contained in:
12600k-rog-d4
2025-12-09 20:33:57 +08:00
parent 144ed3cbdf
commit 8f4d399cfd
1498 changed files with 3778 additions and 3654 deletions

View 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)
}