Skip to content

Commit

Permalink
fixed that values in attributes wouldn't optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Jan 9, 2011
1 parent 3bd908b commit d9479a7
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/markup.lisp
Expand Up @@ -41,20 +41,31 @@
(not (and (stringp val)
(string= val (escape-string val)))))

(defmacro %escape-string (val)
(defmacro %escape-string-form (val)
(let ((val2 (gensym)))
`(let ((,val2 ,val))
(if (should-escape-p ,val2)
`(escape-string ,,val2)
,val2))))

(defun %dirty-string-form (form)
(cond
((consp form) (let ((res (gensym)))
`(let ((,res ,form))
(if (listp ,res) (format nil "~{~A~}" ,res)
,res))))
((null form) "")
((stringp form) (%escape-string-form form))
((symbolp form) `(escape-string (ensure-string ,form)))
(t (%escape-string-form (format nil "~A" form)))))

(defmacro raw (&rest forms)
`(let (*auto-escape*) ,@forms))

(defmacro esc (&rest forms)
`(let ((*auto-escape* t))
,@(loop for form in forms
collect (%escape-string form))))
collect (%escape-string-form form))))

(defmacro %write-strings (&rest strings)
(let ((s (gensym)))
Expand Down Expand Up @@ -88,7 +99,7 @@
append `(,(concatenate 'string
(string-downcase key)
"=\"")
,(%escape-string `(ensure-string ,val))
,(%dirty-string-form val)
"\""
" ")))))

Expand All @@ -105,15 +116,7 @@
if (tagp elem)
append (tag->string elem)
else
collect (cond
((consp elem) (let ((res (gensym)))
`(let ((,res ,elem))
(if (listp ,res) (format nil "~{~A~}" ,res)
,res))))
((null elem) "")
((stringp elem) (%escape-string elem))
((symbolp elem) `(escape-string (ensure-string ,elem)))
(t (%escape-string (format nil "~A" elem)))))
collect (%dirty-string-form elem))
(list (format nil "</~(~A~)>" name)))
(if (eq *markup-language* :html)
(list ">")
Expand Down

0 comments on commit d9479a7

Please sign in to comment.