1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

perf(readability): significantly improve transformMisusedDivsIntoParagraphs

This commit is contained in:
jvoisin 2025-07-01 15:58:11 +02:00 committed by Frédéric Guillot
parent 2f7b2e7375
commit 89c32d518d

View file

@ -361,10 +361,24 @@ func getWeight(s string) int {
func transformMisusedDivsIntoParagraphs(document *goquery.Document) {
document.Find("div").Each(func(i int, s *goquery.Selection) {
html, _ := s.Html()
if !divToPElementsRegexp.MatchString(html) {
nodes := s.Children().Nodes
if len(nodes) == 0 {
node := s.Get(0)
node.Data = "p"
return
}
for _, node := range nodes {
switch node.Data {
case "a", "blockquote", "div", "dl",
"img", "ol", "p", "pre",
"table", "ul":
return
default:
node := s.Get(0)
node.Data = "p"
}
}
})
}