fix
This commit is contained in:
@@ -140,26 +140,29 @@ func ShouldRefuseEnhanceHashSkip(priorDesc string, titles ...string) bool {
|
||||
|
||||
// DescriptionMissingFormulaHTMLTags is true when sectionTypes require HTML tags
|
||||
// (h1/h2/h3/h4, p, ul) that are absent from desc — formula-mismatch for skip/clear.
|
||||
// Counts matter: a formula with two h2 sections needs at least two <h2 opens.
|
||||
func DescriptionMissingFormulaHTMLTags(desc string, sectionTypes []string) bool {
|
||||
if len(sectionTypes) == 0 {
|
||||
return false
|
||||
}
|
||||
lower := strings.ToLower(desc)
|
||||
need := map[string]int{}
|
||||
for _, raw := range sectionTypes {
|
||||
typ := strings.ToLower(strings.TrimSpace(raw))
|
||||
switch typ {
|
||||
case "h1", "h2", "h3", "h4":
|
||||
if !strings.Contains(lower, "<"+typ) {
|
||||
return true
|
||||
}
|
||||
case "ul":
|
||||
if !strings.Contains(lower, "<ul") {
|
||||
return true
|
||||
}
|
||||
case "h1", "h2", "h3", "h4", "ul":
|
||||
need[typ]++
|
||||
case "p", "":
|
||||
if !strings.Contains(lower, "<p") {
|
||||
return true
|
||||
}
|
||||
need["p"]++
|
||||
}
|
||||
}
|
||||
if len(need) == 0 {
|
||||
return false
|
||||
}
|
||||
lower := strings.ToLower(desc)
|
||||
for typ, n := range need {
|
||||
needle := "<" + typ
|
||||
if strings.Count(lower, needle) < n {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -48,4 +48,12 @@ func TestDescriptionMissingFormulaHTMLTags(t *testing.T) {
|
||||
if DescriptionMissingFormulaHTMLTags("<h1>T</h1><p>Body</p><ul><li>x</li></ul>", types) {
|
||||
t.Fatal("full HTML must match")
|
||||
}
|
||||
twoH2 := []string{"h2", "p", "h2", "p", "ul"}
|
||||
if !DescriptionMissingFormulaHTMLTags("<h2>A</h2><p>One</p><ul><li>x</li></ul>", twoH2) {
|
||||
t.Fatal("single h2 must fail when formula needs two")
|
||||
}
|
||||
ok := "<h2>A</h2><p>One</p><h2>B</h2><p>Two</p><ul><li>x</li></ul>"
|
||||
if DescriptionMissingFormulaHTMLTags(ok, twoH2) {
|
||||
t.Fatal("two h2 + two p + ul should satisfy")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user