package services

import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"html"
	"strings"
)

func GetReportContentSub(content string) (contentSub string, err error) {
	content = html.UnescapeString(content)
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
	if err != nil {
		fmt.Println("create doc err:", err.Error())
		return
	}
	n := 0
	doc.Find("p").Each(func(i int, s *goquery.Selection) {
		if n >= 5 {
			return
		}
		n++
		phtml, err := s.Html()
		if err != nil {
			fmt.Println("get html err", err.Error())
			return
		}
		if s.Text() != "" || strings.Contains(phtml, "src") {
			contentSub = contentSub + "<p>" + phtml + "</p>"
		}
	})
	return
}
