html-reader.scm 906 B

12345678910111213141516171819202122232425262728
  1. (define-module (html-reader)
  2. #:use-module (htmlprag)
  3. #:use-module (haunt post)
  4. #:use-module (haunt reader)
  5. #:use-module (srfi srfi-26)
  6. #:use-module (ice-9 match)
  7. #:export (html-reader*))
  8. (define (read-html-post port)
  9. (values (read-metadata-headers port)
  10. (catch #t
  11. (lambda ()
  12. (match (html->shtml port)
  13. (('*TOP* sxml ...) sxml)))
  14. (lambda (err)
  15. (display "WHOOPS: something went wrong when rendering HTML!\n")
  16. `((doctype "html")
  17. (html
  18. (head
  19. (title "whoops"))
  20. (body
  21. (h1 "Haha whoops lollerskates")
  22. (p "Hey, something went wrong when you were writing HTML"))))))))
  23. (define html-reader*
  24. (make-reader (make-file-extension-matcher "html")
  25. (cut call-with-input-file <> read-html-post)))