From a4c3fca7153bba629c4f5c95ae68e1453afb0ed9 Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Mon, 9 Apr 2012 12:11:02 +0300 Subject: *HTML-NO-INDENT-TAGS* Tags in this list don't have their body indented even if *INDENT* is true.
 in particular is indentation sensitive, and it's irritating
  when rendering changes as :indent is flipped.
---
 packages.lisp |  1 +
 specials.lisp |  4 ++++
 test/simple   | 33 ++++++++++++++++++++++++++++++++-
 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))
-         "
") \ No newline at end of file + "
") + +;;; 24 +(string= (with-html-output-to-string (out) + (:div (:pre "Foo"))) + "
Foo
") + +;;; 25 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:pre "Foo"))) + " +
+
Foo
+
") + +;;; 26 +(string= (with-html-output-to-string (out nil :indent t) + (:div (:p "Bar"))) + " +
+

Bar +

+
") + +;;; 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"))))) + " +
+

Bar

+
") diff --git a/who.lisp b/who.lisp index f6dea56..0c1cd19 100644 --- a/who.lisp +++ b/who.lisp @@ -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 -- cgit v1.2.3