From leslie.polzer at gmx.net Thu May 1 18:54:01 2008 From: leslie.polzer at gmx.net (Leslie P. Polzer) Date: Thu, 1 May 2008 20:54:01 +0200 (CEST) Subject: [cl-who-devel] ESC inside FMT doesn't get expanded Message-ID: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> Is this some kind of CL limitation? Leslie From edi at agharta.de Thu May 1 19:35:45 2008 From: edi at agharta.de (Edi Weitz) Date: Thu, 01 May 2008 21:35:45 +0200 Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> (Leslie P. Polzer's message of "Thu, 1 May 2008 20:54:01 +0200 (CEST)") References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> Message-ID: On Thu, 1 May 2008 20:54:01 +0200 (CEST), "Leslie P. Polzer" wrote: > Is this some kind of CL limitation? Not exactly sure what you mean (some example code would be helpful), but it sounds as if you're expecting something that you shouldn't expect. Edi. From leslie.polzer at gmx.net Thu May 1 20:29:35 2008 From: leslie.polzer at gmx.net (Leslie P. Polzer) Date: Thu, 1 May 2008 22:29:35 +0200 (CEST) Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> Message-ID: <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> > Not exactly sure what you mean (some example code would be helpful), > but it sounds as if you're expecting something that you shouldn't > expect. I guess so, but I'm interested in the background. Here's the case: [4]> (in-package :cl-who) # WHO[5]> (with-html-output (*standard-output*) (:p (fmt "~A" (esc "foo"))))

*** - EVAL: undefined function ESC Leslie From edi at agharta.de Thu May 1 20:36:13 2008 From: edi at agharta.de (Edi Weitz) Date: Thu, 01 May 2008 22:36:13 +0200 Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> (Leslie P. Polzer's message of "Thu, 1 May 2008 22:29:35 +0200 (CEST)") References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> Message-ID: On Thu, 1 May 2008 22:29:35 +0200 (CEST), "Leslie P. Polzer" wrote: > Here's the case: > > [4]> (in-package :cl-who) > # > WHO[5]> (with-html-output (*standard-output*) > (:p (fmt "~A" (esc "foo")))) >

> *** - EVAL: undefined function ESC Works as described: http://weitz.de/cl-who/#syntax The macro sees (fmt "~A" (esc "foo")) and substitutes (format s "~A" (esc "foo")) for it. At this point, CL-WHO stops expanding, and ESC is treated like any other symbol. Try this: http://weitz.de/cl-who/#escape-string From leslie.polzer at gmx.net Fri May 2 06:29:49 2008 From: leslie.polzer at gmx.net (Leslie P. Polzer) Date: Fri, 2 May 2008 08:29:49 +0200 (CEST) Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> Message-ID: <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> > At this point, CL-WHO stops expanding, and ESC is treated > like any other symbol. The point for me is, why does it stop expanding? It would be nice to have the ESC shortcut in this case. Leslie From osei.poku at gmail.com Fri May 2 07:15:05 2008 From: osei.poku at gmail.com (Osei Poku) Date: Fri, 2 May 2008 03:15:05 -0400 Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> Message-ID: <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> On May 2, 2008, at 2:29 AM, Leslie P. Polzer wrote: > >> At this point, CL-WHO stops expanding, and ESC is treated >> like any other symbol. > > The point for me is, why does it stop expanding? > It would be nice to have the ESC shortcut in this case. Why do you need to do that? You don't need to escape after that point. You can just directly put the string (or any other lisp expression) as the argument to fmt. Osei From leslie.polzer at gmx.net Fri May 2 09:10:45 2008 From: leslie.polzer at gmx.net (Leslie P. Polzer) Date: Fri, 2 May 2008 11:10:45 +0200 (CEST) Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> Message-ID: <62009.88.73.226.33.1209719445.squirrel@mail.stardawn.org> > Why do you need to do that? > > You don't need to escape after that point. You can just directly put > the string (or any other lisp expression) as the argument to fmt. Assume a malicious string ("" in this case): WHO[8]> (with-html-output (*standard-output*) (fmt "<~A>" "")) <> NIL WHO[9]> (with-html-output (*standard-output*) (fmt "<~A>" (escape-string ""))) <<html>> NIL Or did I misunderstand your question? Leslie From osei.poku at gmail.com Fri May 2 13:36:05 2008 From: osei.poku at gmail.com (Osei Poku) Date: Fri, 2 May 2008 09:36:05 -0400 Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <62009.88.73.226.33.1209719445.squirrel@mail.stardawn.org> References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> <62009.88.73.226.33.1209719445.squirrel@mail.stardawn.org> Message-ID: <1D1861F4-6B9E-4675-8E0D-7A90AF370ED9@gmail.com> On May 2, 2008, at 5:10 AM, Leslie P. Polzer wrote: >> >> Why do you need to do that? >> >> You don't need to escape after that point. You can just directly put >> the string (or any other lisp expression) as the argument to fmt. > > Assume a malicious string ("" in this case): > > WHO[8]> (with-html-output (*standard-output*) (fmt "<~A>" "")) > <> > NIL > WHO[9]> (with-html-output (*standard-output*) (fmt "<~A>" (escape- > string ""))) > <<html>> > NIL > Why don't you use escape-string directly instead then? Like in your example. Why use esc at all? From leslie.polzer at gmx.net Fri May 2 14:06:25 2008 From: leslie.polzer at gmx.net (Leslie P. Polzer) Date: Fri, 2 May 2008 16:06:25 +0200 (CEST) Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <1D1861F4-6B9E-4675-8E0D-7A90AF370ED9@gmail.com> References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> <62009.88.73.226.33.1209719445.squirrel@mail.stardawn.org> <1D1861F4-6B9E-4675-8E0D-7A90AF370ED9@gmail.com> Message-ID: <63578.88.73.226.33.1209737185.squirrel@mail.stardawn.org> > Why don't you use escape-string directly instead then? Like in your > example. Why use esc at all? It's shorter. When you use this function a lot (and I have to) the lines tend to get long. Plus, I don't think the behaviour in question is intuitive. Leslie From edi at agharta.de Fri May 2 14:19:02 2008 From: edi at agharta.de (Edi Weitz) Date: Fri, 02 May 2008 16:19:02 +0200 Subject: [cl-who-devel] ESC inside FMT doesn't get expanded In-Reply-To: <63578.88.73.226.33.1209737185.squirrel@mail.stardawn.org> (Leslie P. Polzer's message of "Fri, 2 May 2008 16:06:25 +0200 (CEST)") References: <63158.88.73.204.37.1209668041.squirrel@mail.stardawn.org> <64708.88.73.204.37.1209673775.squirrel@mail.stardawn.org> <62374.88.73.226.33.1209709789.squirrel@mail.stardawn.org> <107C8B97-5B53-4967-B7D3-578AFB8C86F3@gmail.com> <62009.88.73.226.33.1209719445.squirrel@mail.stardawn.org> <1D1861F4-6B9E-4675-8E0D-7A90AF370ED9@gmail.com> <63578.88.73.226.33.1209737185.squirrel@mail.stardawn.org> Message-ID: On Fri, 2 May 2008 16:06:25 +0200 (CEST), "Leslie P. Polzer" wrote: > It's shorter. When you use this function a lot (and I have to) the > lines tend to get long. (defun esc (string) (escape-string string)) Or use Arc... From mail at chaitanyagupta.com Sun May 25 07:23:09 2008 From: mail at chaitanyagupta.com (Chaitanya Gupta) Date: Sun, 25 May 2008 12:53:09 +0530 Subject: [cl-who-devel] When tagname/attributes can be determined only at runtime (WITH-HTML-TAG) Message-ID: <483913DD.3090104@chaitanyagupta.com> Hi, While using CL-WHO recently, I ran into a small problem wherein some tagnames/attributes could be determined only at runtime. Not knowing any easy way to do this "out of the box" in CL-WHO, I wrote this small macro (inspired by XML-EMITTER:WITH-TAG) - (defmacro with-html-tag ((name &optional attributes) &body body) (let ((body-fn (gensym))) `(flet ((,body-fn () , at body)) (call-with-html-tag ,name ,attributes #',body-fn)))) (defun call-with-html-tag (name attributes body-fn) (let ((tag-name (typecase name (symbol (string-downcase name)) (t name)))) (format t "<~A" tag-name) (when attributes (format t "~{~A~}" (cl-who:convert-attributes attributes))) (format t ">") (funcall body-fn) (format t "" tag-name))) Note that it writes only to *standard-output*. Usage ----- (defvar *x* :blockquote) => *X* (with-output-to-string (*standard-output*) (cl-who:with-html-output (*standard-output*) (:body (with-html-tag (*x*) (cl-who:htm (:p "foo bar")))))) => "

foo bar

" (with-output-to-string (*standard-output*) (cl-who:with-html-output (*standard-output*) (:body (with-html-tag (*x* '(("id" . "foo123"))) (cl-who:htm (:p "foo bar")))))) => "

foo bar

" I think this will be a useful addition to CL-WHO (although this particular implementation can be improved a bit). Or did I miss out on some other way that CL-WHO can easily handle this? Chaitanya