image修正版

WiLiKiで許可されたサイトのみの画像リンクを許し,属性も指定できる.山口さんのと違って,属性と属性の間にコンマは入れません.

使用例:

 [http://www.zukeran.org/shin/z.png](http://www.zukeran.org/shin/z.png)  

http://www.zukeran.org/shin/z.png

(define-reader-macro (image url . str)
  (define opts (fold
		(lambda (s opts)
		  (let1 sl (string-split s "=")
		    (if (= (length sl) 2)
			(let ((key (first sl))
			      (value (second sl)))
			  (acons key value opts)))))
		'()
		str))
  (define (get-opt key)
    (let1 p (find (lambda (opt) (string=? (car opt) key)) opts)
      (if (pair? p) `((,(car p) ,(cdr p))) '())))
  (define (alt) (let ((opt (get-opt "alt")))
		  (cond 
		   ((null? opt) "[image]")
		   (else (cadar opt)))))
  (define (badimg) `((a (@ (href ,url)) ,(alt))))
  (let loop ((urls (image-urls-of (wiliki))))
    (if (pair? urls)
	(receive (pred action)
	    (if (pair? (car urls))
		(values (caar urls) (cadar urls))
		(values (car urls) 'allow))
	  (if (pred url)
	      (if (eq? action 'allow)
		  `((img (@ (src ,url)
			    ,@(get-opt "width")
			    ,@(get-opt "height")
			    ,@(get-opt "longdesc")
			    ,@(get-opt "alt")
			    ,@(get-opt "align")
			    ,@(get-opt "id")
			    ,@(get-opt "class")
			    ,@(get-opt "title"))))	    

		  (badimg))
	      (loop (cdr urls))))
	(badimg)))
    )