add url->pollen function

pull/9/head
Matthew Butterick 11 years ago
parent 372c4775f7
commit 8743a1b8c5

@ -1,5 +1,5 @@
#lang racket/base
(require sugar txexpr racket/list racket/string pollen/world xml html racket/file racket/match pollen/html)
(require sugar txexpr racket/list racket/string pollen/world xml html racket/file racket/match pollen/html net/url racket/port)
(define (attrs->pollen attrs)
(string-join (flatten (map (λ(pair) (list (format "'~a:" (car pair)) (format "\"~a\"" (cadr pair)))) attrs)) " "))
@ -37,6 +37,13 @@
; xexpr-results will be a list with whitespace elements, so strip those out
(xexpr->pollen #:p-breaks p-breaks (car (filter-not (λ(x) (and (string? x) (regexp-match #px"\\s+" x))) xexpr-results))))
(define/contract+provide (url->pollen url-or-string #:p-breaks [p-breaks #f])
(((or/c string? url?)) (#:p-breaks boolean?) . ->* . string?)
(define url (if (string? url-or-string) (string->url url-or-string) url-or-string))
(define url-result (port->string (get-pure-port url)))
(html->pollen url-result #:p-breaks p-breaks))
(module+ main
; (xexpr->pollen '(p "You are puppy"))
; (xexpr->pollen '(p ((class "foo")) "You are puppy"))

Loading…
Cancel
Save