`,
want: "Visible",
},
{
name: "strips head and title",
html: `Page TitleContent`,
want: "Content",
},
{
name: "plain text passthrough",
html: `
Line one
Line two
`,
want: "Line one\nLine two",
},
{
name: "mixed non-text and text tags",
html: `
Only this
`,
want: "Only this",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := plainTextFromHTML(tt.html)
if got != tt.want {
t.Errorf("plainTextFromHTML() = %q, want %q", got, tt.want)
}
})
}
}
func TestPlainTextFromHTMLDeepNesting(t *testing.T) {
// Build HTML with 10000 levels of nesting — would overflow the stack
// with the old recursive implementation.
const depth = 10_000
var b strings.Builder
for i := 0; i < depth; i++ {
b.WriteString("
")
}
b.WriteString("deep")
for i := 0; i < depth; i++ {
b.WriteString("