docs(pier,seaglass,sunrise,sunscreen,tide): compile README Go examples via src= (quick-261118-qsd)

This commit is contained in:
Jakub Zych
2026-11-18 20:04:47 +01:00
parent 6409837b0c
commit cd55a3980d
9 changed files with 449 additions and 69 deletions

View File

@@ -0,0 +1,33 @@
package seaglass_test
import (
"fmt"
"git.golem15.com/golem15/summercms/modules/seaglass"
)
func ExampleSanitizeReport() {
clean, report := seaglass.SanitizeReport(`<p onclick="x()">Hi</p><script>alert(1)</script>`)
fmt.Println(clean)
fmt.Println(report.Elements, report.Attributes, report.Changed)
// Output:
// <p>Hi</p>
// [script] [onclick] true
}
func ExampleCheck() {
for _, stored := range []string{
`<p class="lead">Hi <a href="tel:+48123">call</a></p>`,
`<p><a href="javascript:alert(1)">x</a></p>`,
} {
if err := seaglass.Check(stored); err != nil {
// stored HTML would change under the policy
fmt.Println(err)
continue
}
fmt.Println("kept whole")
}
// Output:
// kept whole
// seaglass: HTML contains elements, attributes or URLs that are not allowed
}