From 4ccca26227f00908773b897cd98566c989454b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20B=C3=B8hmer?= Date: Fri, 29 Jul 2016 01:14:56 +0200 Subject: Special variable to enable empty attribute syntax See https://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty for spesification. --- packages.lisp | 3 ++- specials.lisp | 8 ++++++++ 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 . In HTML5 boolean attributes +can be defined as ") + (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 diff --git a/who.lisp b/who.lisp index b2d0337..6315612 100644 --- a/who.lisp +++ b/who.lisp @@ -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* "")) ((:xml) (setf *html-mode* :xml + *empty-attribute-syntax* nil *empty-tag-end* " />" *prologue* "")) ((:html5) (setf *html-mode* :html5 + *empty-attribute-syntax* t *empty-tag-end* ">" *prologue* "")))) @@ -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 -- cgit v1.2.3