|
32 | 32 | (define responsive-images |
33 | 33 | (let ([magick-notice-displayed? #f]) |
34 | 34 | (λ (xs) |
| 35 | + (define (remote-host url) |
| 36 | + (url-host (string->url url))) |
35 | 37 | (define (do-it xs) |
36 | 38 | (for/list ([x xs]) |
37 | 39 | (match x |
38 | 40 | [`(div ([class ,classes]) |
39 | | - (img ([src ,url] ,attrs ...)) |
| 41 | + (img ,(list-no-order `[src ,url] attrs ...)) |
40 | 42 | ,content ...) |
41 | 43 | #:when (and (regexp-match #px"\\bfigure\\b" classes) |
42 | | - (not (url-host (string->url url)))) |
| 44 | + (not (remote-host url))) |
43 | 45 | (let ([sizes-attr (assq 'sizes attrs)]) |
44 | 46 | `(div ([class ,classes]) |
45 | | - (img ([class "img-responsive"] ; Bootstrap class |
| 47 | + (img ([class "img-responsive"] ; Add Bootstrap class |
46 | 48 | ,@(make-responsive url (cond [sizes-attr => second] |
47 | 49 | [#t #f])) |
48 | 50 | ,@(if sizes-attr |
49 | 51 | (remove sizes-attr attrs) |
50 | 52 | attrs))) |
51 | 53 | ,@content)) |
52 | 54 | ] |
| 55 | + ;; xexpr-map? |
| 56 | + [`(p () (img ,(list-no-order `[src ,url] `[class ,classes] attrs ...))) |
| 57 | + #:when (and (regexp-match #px"\\bimg-responsive\\b" classes) |
| 58 | + (not (remote-host url))) |
| 59 | + `(p () (img ([class ,classes] |
| 60 | + ,@(make-responsive url #f) ; TODO honor custom sizes? |
| 61 | + ,@attrs)))] |
53 | 62 | [x x]))) |
54 | 63 | (cond [(current-responsive-images?) |
55 | 64 | (if magick-available? |
|
86 | 95 | [src "/img/1x1.gif"] |
87 | 96 | [srcset "/img/1x1.gif 2w"] |
88 | 97 | [sizes "some-custom-size-spec"]))))) |
| 98 | + (test-equal? "Img with img-responsive class inside p tag" |
| 99 | + (responsive-images |
| 100 | + '((p () (img ([src "/img/1x1.gif"] |
| 101 | + [alt ""] |
| 102 | + [class "img-responsive among-others"] |
| 103 | + [foo-attr "bar"]))))) |
| 104 | + '((p () (img ([class "img-responsive among-others"] |
| 105 | + [src "/img/1x1.gif"] |
| 106 | + [srcset "/img/1x1.gif 2w"] |
| 107 | + [sizes "(max-width: 2px) 100vw, 2px"] |
| 108 | + [alt ""] |
| 109 | + [foo-attr "bar"]))))) |
89 | 110 | (test-equal? "Image bigger than maximum size" |
90 | 111 | (responsive-images |
91 | 112 | '((div ([class "figure pull-right"]) |
|
0 commit comments