diff options
author | Knut Olav Bøhmer <bohmer@gmail.com> | 2016-07-29 01:14:56 +0200 |
---|---|---|
committer | Knut Olav Bøhmer <bohmer@gmail.com> | 2016-07-29 01:14:56 +0200 |
commit | 4ccca26227f00908773b897cd98566c989454b7f (patch) | |
tree | fe41ae0b7a7ee654453838f016d9023ffc0212a3 | |
parent | e4518c4d994dc2784e2f4a7ba2d1c6b40bd90641 (diff) | |
download | tl-who-4ccca26227f00908773b897cd98566c989454b7f.tar.gz tl-who-4ccca26227f00908773b897cd98566c989454b7f.tar.bz2 tl-who-4ccca26227f00908773b897cd98566c989454b7f.zip |
Special variable to enable empty attribute syntax
See https://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty for
spesification.
-rw-r--r-- | packages.lisp | 3 | ||||
-rw-r--r-- | specials.lisp | 8 | ||||
-rw-r--r-- | who.lisp | 22 |
3 files changed, 21 insertions, 12 deletions
diff --git a/packages.lisp b/packages.lisp index 5ea0159..e5656d7 100644 --- a/packages.lisp +++ b/packages.lisp @@ -35,6 +35,7 @@ #+:sbcl (:shadow :defconstant) #+:sb-package-locks (:lock t) (:export :*attribute-quote-char* + :*empty-attribute-syntax* :*escape-char-p* :*prologue* :*downcase-tokens-p* @@ -62,4 +63,4 @@ :with-html-output :with-html-output-to-string)) -(pushnew :cl-who *features*)
\ No newline at end of file +(pushnew :cl-who *features*) diff --git a/specials.lisp b/specials.lisp index 9cf065d..c55c3e0 100644 --- a/specials.lisp +++ b/specials.lisp @@ -53,6 +53,14 @@ indentation dynamically.") (defvar *html-mode* :xml ":SGML for \(SGML-)HTML, :XML \(default) for XHTML, :HTML5 for HTML5.") +(defvar *empty-attribute-syntax* nil + "Set this to t to enable attribute minimization (also called +'boolean attributes', or 'empty attribute syntax' according to the w3 +html standard). In XHTML attribute minimization is forbidden, and all +attributes must have a value. Thus in XHTML boolean attributes must be +defined as <input disabled='disabled' />. In HTML5 boolean attributes +can be defined as <input disabled>") + (defvar *downcase-tokens-p* t "If NIL, a keyword symbol representing a tag or attribute name will not be automatically converted to lowercase. This is useful when one @@ -40,14 +40,17 @@ XHTML and :HTML5 for HTML5 (HTML syntax)." (ecase mode ((:sgml) (setf *html-mode* :sgml + *empty-attribute-syntax* t *empty-tag-end* ">" *prologue* "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">")) ((:xml) (setf *html-mode* :xml + *empty-attribute-syntax* nil *empty-tag-end* " />" *prologue* "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")) ((:html5) (setf *html-mode* :html5 + *empty-attribute-syntax* t *empty-tag-end* ">" *prologue* "<!DOCTYPE html>")))) @@ -93,7 +96,7 @@ forms." (string orig-attr)) unless (null val) ;; no attribute at all if VAL is NIL if (constantp val) - if (and (eq *html-mode* :sgml) (eq val t)) ; special case for SGML + if (and *empty-attribute-syntax* (eq val t)) ; special case for SGML and HTML5 nconc (list " " attr) else nconc (list " " @@ -115,16 +118,13 @@ forms." nconc (list `(let ((,=var= ,val)) (cond ((null ,=var=)) ((eq ,=var= t) - ,(case *html-mode* - (:sgml - `(fmt " ~A" ,attr)) - ;; otherwise default to :xml mode - (t - `(fmt " ~A=~C~A~C" - ,attr - *attribute-quote-char* - ,attr - *attribute-quote-char*)))) + ,(if *empty-attribute-syntax* + `(fmt " ~A" ,attr) + `(fmt " ~A=~C~A~C" + ,attr + *attribute-quote-char* + ,attr + *attribute-quote-char*))) (t (fmt " ~A=~C~A~C" ,attr |