Support boolean attributes
This commit is contained in:
parent
8f4a7c4907
commit
f0a9b96345
2 changed files with 21 additions and 1 deletions
|
@ -191,9 +191,21 @@
|
|||
style sub summary sup svg table tbody td template textarea tfoot th
|
||||
thead |time| title tr track u ul var video wbr)
|
||||
|
||||
(defparameter *boolean-attrs*
|
||||
'(allowfullscreen async autofocus autoplay checked controls default defer
|
||||
disabled formnovalidate inert ismap itemscope loop multiple muted nomodule
|
||||
novalidate open playsinline readonly required reversed selected))
|
||||
|
||||
(defmethod print-object ((attrs attrs) stream)
|
||||
(if (attrs-alist attrs)
|
||||
(format stream " ~{~a=~s~^ ~}" (util:alist-plist (attrs-alist attrs)))
|
||||
(let ((alist (attrs-alist attrs)))
|
||||
(dolist (pair alist)
|
||||
(let ((key (car pair))
|
||||
(value (cdr pair)))
|
||||
(if (member key *boolean-attrs* :test #'string=)
|
||||
(when value
|
||||
(format stream " ~a" (string-downcase key)))
|
||||
(format stream " ~a=~s" (string-downcase key) value)))))
|
||||
(format stream "")))
|
||||
|
||||
(defparameter *self-closing-tags*
|
||||
|
|
|
@ -148,6 +148,14 @@
|
|||
(is (string= "<div id=\"4\"><div id=\"3\"><div>some text</div><div id=\"2\"></div>some other text</div><div id=\"5\"><a href=\"a.html\">a</a></div></div>"
|
||||
(elem-str div4)))))
|
||||
|
||||
(test boolean-attrs
|
||||
(let ((script1 (script :defer t :data-domain "example.com" :src "example.com/script.js"))
|
||||
(script2 (script :defer nil :data-domain "example.com" :src "example.com/script.js")))
|
||||
(is (string= "<script defer data-domain=\"example.com\" src=\"example.com/script.js\"></script>"
|
||||
(element-string script1)))
|
||||
(is (string= "<script data-domain=\"example.com\" src=\"example.com/script.js\"></script>"
|
||||
(element-string script2)))))
|
||||
|
||||
(in-suite escape)
|
||||
|
||||
(defparameter *a-attrs*
|
||||
|
|
Loading…
Reference in a new issue