aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--test/simple.tl11
-rw-r--r--who.tl14
3 files changed, 24 insertions, 7 deletions
diff --git a/README.md b/README.md
index 12bb321..3ef41c6 100644
--- a/README.md
+++ b/README.md
@@ -195,6 +195,12 @@ Here are the differences to be aware of:
* TL-WHO's `esc` accepts arguments which are not strings. They
are turned to a string using `tostringp`, and HTML-escaped.
+* TL-WHO allows `fmt` as well as `escj` to be used to calculate attributes.
+ These local macros have alternative definitions when used in attributes.
+ The remaining local macros don't make sense in attributes, and make
+ a mess of the output if used; unlike CL-WHO, TL-WHO warns when they
+ are used in attributes.
+
Additionally, users (of CL-WHO and TL-WHO alike) are advised to watch for the
following issue: the CL-WHO documentation is not accurately maintained and
makes some references to material that no longer exists in CL-WHO, such as the
diff --git a/test/simple.tl b/test/simple.tl
index 3ed4685..4dc5b88 100644
--- a/test/simple.tl
+++ b/test/simple.tl
@@ -453,9 +453,9 @@
;;; 41
;;; Test that warning is produced when any of the WHO local macros are used in
;;; an Lisp expression that calculates an attribute
-(each ((sym '(htm noesc-fmt fmt esc escq escj str)))
+(each ((sym '(htm noesc-fmt esc escq str)))
(test (catch
- (eval '(progn
+ (eval ^(progn
(with-html-output-to-string (out)
(:foo :attr (,sym "abc")))
nil))
@@ -480,3 +480,10 @@
(test (with-html-output-to-string (out)
(:p (esc 5) (escq 6) (escj 7)))
"<p>567</p>")
+
+;;; 45
+;;; Test that we can use fmt and escj on attributes
+(test (with-html-output-to-string (out)
+ (:div :span (fmt "~a&" 42)
+ :color (escj "</script>")))
+ "<div span='42&amp;' color='&lt;\\/script&gt;'></div>")
diff --git a/who.tl b/who.tl
index 8ac2ebc..3817e43 100644
--- a/who.tl
+++ b/who.tl
@@ -88,11 +88,15 @@
(defun attr-warning-macrolet (form)
(with-gensyms (warn)
^(macrolet ((,warn (f . rest)
- ^(compile-warning ,f
- "not recommended in attribute expr")))
- (macrolet ,(collect-each ((sym '(htm noesc-fmt fmt esc escq escj str)))
- ^(,sym (:form f . rest) (,warn f) f))
- ,form))))
+ ^(compile-warning ,f
+ "not recommended in attribute expr")))
+ (macrolet ((fmt (. args)
+ ^(usr:fmt ,*args))
+ (escj (thing)
+ ^[(tojson (tostringp ,thing)) 1..-1])
+ ,*(collect-each ((sym '(htm noesc-fmt esc escq str)))
+ ^(,sym (:form f . rest) (,warn f) f)))
+ ,form))))
;; Helper function for convert-tag-to-string-list which converts the
;; alist attr-list of attributes into a list of strings and/or Lisp