diff options
author | Nikodemus Siivola <nikodemus@random-state.net> | 2012-04-09 12:11:02 +0300 |
---|---|---|
committer | Nikodemus Siivola <nikodemus@random-state.net> | 2012-04-09 12:18:20 +0300 |
commit | a4c3fca7153bba629c4f5c95ae68e1453afb0ed9 (patch) | |
tree | ec1a088cc495c12f5413987eb30ddaf3a3f575fc | |
parent | 9078ffa62e030f4419cd465ee604da81750da11b (diff) | |
download | tl-who-a4c3fca7153bba629c4f5c95ae68e1453afb0ed9.tar.gz tl-who-a4c3fca7153bba629c4f5c95ae68e1453afb0ed9.tar.bz2 tl-who-a4c3fca7153bba629c4f5c95ae68e1453afb0ed9.zip |
*HTML-NO-INDENT-TAGS*
Tags in this list don't have their body indented even if
*INDENT* is true.
<pre> in particular is indentation sensitive, and it's irritating
when rendering changes as :indent is flipped.
-rw-r--r-- | packages.lisp | 1 | ||||
-rwxr-xr-x | specials.lisp | 4 | ||||
-rw-r--r-- | test/simple | 33 | ||||
-rw-r--r-- | who.lisp | 15 |
4 files changed, 45 insertions, 8 deletions
diff --git a/packages.lisp b/packages.lisp index 89d56de..752545e 100644 --- a/packages.lisp +++ b/packages.lisp @@ -37,6 +37,7 @@ :*escape-char-p* :*prologue* :*downcase-tokens-p* + :*html-no-indent-tags* :*html-empty-tags* :*html-empty-tag-aware-p* :conc diff --git a/specials.lisp b/specials.lisp index 349c7fc..c731a78 100755 --- a/specials.lisp +++ b/specials.lisp @@ -64,6 +64,10 @@ needs to output case sensitive XML.") (defvar *empty-tag-end* " />" "End of an empty tag. Default is XML style.") +(defvar *html-no-indent-tags* + '(:pre) + "List of HTML tags that disable indentation inside them. Default list containts only :PRE.") + (defvar *html-empty-tags* '(:area :atop diff --git a/test/simple b/test/simple index 96686a1..c952fa0 100644 --- a/test/simple +++ b/test/simple @@ -260,4 +260,35 @@ (with-html-output (var (pop list)) (progn (htm (:br)))) (get-output-stream-string stream)) - "<br />")
\ No newline at end of file + "<br />") + +;;; 24 +(string= (with-html-output-to-string (out) + (:div (:pre "Foo"))) + "<div><pre>Foo</pre></div>") + +;;; 25 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:pre "Foo"))) + " +<div> + <pre>Foo</pre> +</div>") + +;;; 26 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:p "Bar"))) + " +<div> + <p>Bar + </p> +</div>") + +;;; 27 +(string= (let ((*html-no-indent-tags* (cons :p *html-no-indent-tags*))) + (eval `(with-html-output-to-string (out nil :indent t) + (:div (:p "Bar"))))) + " +<div> + <p>Bar</p> +</div>") @@ -144,7 +144,11 @@ 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 (if *downcase-tokens-p* (string-downcase tag) (string 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))) + (+ 2 *indent*)))) (nconc (if *indent* ;; indent by *INDENT* spaces @@ -157,13 +161,10 @@ can use EQL specializers on the first argument." (if body (append (list ">") - ;; now hand over the tag's body to TREE-TO-TEMPLATE, increase - ;; *INDENT* by 2 if necessary - (if *indent* - (let ((*indent* (+ 2 *indent*))) - (funcall body-fn body)) + ;; now hand over the tag's body to TREE-TO-TEMPLATE + (let ((*indent* body-indent)) (funcall body-fn body)) - (if *indent* + (when body-indent ;; indentation (list +newline+ (n-spaces *indent*))) ;; closing tag |