1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Html generator helper
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2011 Philippe Brochard <hocwp@free.fr>
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;; --------------------------------------------------------------------------
28 (in-package :common-lisp-user
)
31 (:use
:common-lisp
:tools
)
32 (:export
:insert-html-doctype
36 :produce-html-string
))
41 (defun insert-html-doctype ()
42 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
43 \"http://www.w3.org/TR/html4/transitional.dtd\">")
46 (defun escape-html (string &optional
(replace '((">" ">") ("<" "<"))))
48 (aif (search (caar replace
) string
)
49 (escape-html (concatenate 'string
(subseq string
0 it
)
51 (subseq string
(+ it
(length (caar replace
)))))
53 (escape-html string
(cdr replace
)))
59 (defun produce-html (tree &optional
(level 0) (stream *standard-output
*))
61 (print-space level stream
)
62 (format stream
"~(<~A>~)~%" (first tree
))
63 (dolist (subtree (rest tree
))
64 (produce-html subtree
(+ 2 level
) stream
))
65 (print-space level stream
)
66 (format stream
"~(</~A>~)~%"
67 (if (stringp (first tree
))
68 (subseq (first tree
) 0 (position #\Space
(first tree
)))
71 (print-space level stream
)
72 (format stream
(if (stringp tree
) "~A~%" "~(~A~)~%") tree
))))
75 (defmacro with-html
((&optional
(stream t
)) &rest rest
)
76 `(produce-html ',@rest
0 ,stream
))
79 (defun produce-html-string (tree &optional
(level 0))
80 (with-output-to-string (str)
81 (produce-html tree level str
)))
94 ,(format nil
"Plip=~A" (+ 3 5))
95 ("a href=\"index.html\"" index
)
106 "<img src=\"toto.png\">"
116 (produce-html-string `(html
123 ,(format nil
"Plip=~A" (+ 3 5))
125 ("a href=\"index.html\"" Index
)