1
0

api.go 599 B

123456789101112131415161718192021222324252627282930
  1. package app
  2. import (
  3. "net/http"
  4. "github.com/microcosm-cc/bluemonday"
  5. "gopkg.in/macaron.v1"
  6. )
  7. func ipynbSanitizer() *bluemonday.Policy {
  8. p := bluemonday.UGCPolicy()
  9. p.AllowAttrs("class", "data-prompt-number").OnElements("div")
  10. p.AllowAttrs("class").OnElements("img")
  11. p.AllowURLSchemes("data")
  12. return p
  13. }
  14. func SanitizeIpynb() macaron.Handler {
  15. p := ipynbSanitizer()
  16. return func(c *macaron.Context) {
  17. html, err := c.Req.Body().String()
  18. if err != nil {
  19. c.Error(http.StatusInternalServerError, "read body")
  20. return
  21. }
  22. c.PlainText(http.StatusOK, []byte(p.Sanitize(html)))
  23. }
  24. }