Skip to content

Commit

Permalink
downcase a tag only when it is in the same case (useful for some came…
Browse files Browse the repository at this point in the history
…l case XML tags).
  • Loading branch information
mgi authored and stassats committed Jun 7, 2019
1 parent 4661aba commit 0d38264
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions specials.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ 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
needs to output case sensitive XML.")
not be automatically converted to lowercase. If T, the tag and
attribute name will be converted to lowercase only if it is in the
same case. This is useful when one needs to output case sensitive
XML.")

(defvar *attribute-quote-char* #\'
"Quote character for attributes.")
Expand Down
11 changes: 11 additions & 0 deletions util.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,14 @@ character set."
(eql (first form) 'cl:declare))
do (push form declarations)
finally (return (values (nreverse declarations) forms))))

(defun same-case-p (string)
"Test if all characters of a string are in the same case."
(or (every #'(lambda (c) (or (not (alpha-char-p c)) (lower-case-p c))) string)
(every #'(lambda (c) (or (not (alpha-char-p c)) (upper-case-p c))) string)))

(defun maybe-downcase (symbol)
(let ((string (string symbol)))
(if (and *downcase-tokens-p* (same-case-p string))
(string-downcase string)
string)))
6 changes: 2 additions & 4 deletions who.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ forms."
(declare (optimize speed space))
(loop with =var= = (gensym)
for (orig-attr . val) in attr-list
for attr = (if *downcase-tokens-p*
(string-downcase orig-attr)
(string orig-attr))
for attr = (maybe-downcase orig-attr)
unless (null val) ;; no attribute at all if VAL is NIL
if (constantp val)
if (and *empty-attribute-syntax* (eq val t)) ; special case for SGML and HTML5
Expand Down Expand Up @@ -144,7 +142,7 @@ a list of strings or Lisp forms."))
"The standard method which is not specialized. The idea is that you
can use EQL specializers on the first argument."
(declare (optimize speed space))
(let ((tag (if *downcase-tokens-p* (string-downcase tag) (string tag)))
(let ((tag (maybe-downcase tag))
(body-indent
;; increase *INDENT* by 2 for body -- or disable it
(when (and *indent* (not (member tag *html-no-indent-tags* :test #'string-equal)))
Expand Down

0 comments on commit 0d38264

Please sign in to comment.