r8224: add entities argument to dtd-prologue
[lml2.git] / base.lisp
1 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          base.lisp
6 ;;;; Purpose:       Lisp Markup Language functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Aug 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of LML2, is Copyright (c) 2000-2003 by Kevin Rosenberg.
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
14 ;;;;
15 ;;;; *************************************************************************
16
17 (in-package #:lml2)
18
19
20 (defun lml-format (str &rest args)
21   (when (streamp *html-stream*)
22     (if args
23         (apply #'format *html-stream* str args)
24         (write-string str *html-stream*))))
25
26 (defun lml-princ (s)
27   (princ s *html-stream*))
28
29 (defun lml-print (s)
30   (format *html-stream* "~A~%" s))
31
32 (defun lml-write-char (char)
33   (write-char char *html-stream*))
34
35 (defun lml-write-string (str)
36   (write-string str *html-stream*))
37
38 (defun lml-print-date (date)
39   (lml-write-string (date-string date)))
40
41 (defun dtd-prologue (&optional (format :xhtml11) &key entities)
42   (case format
43     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
44      (lml-write-string +xml-prologue-string+)
45      (lml-write-char #\newline)
46      (case format
47        ((:xhtml11 :xhtml)
48         (lml-write-string +xhtml11-dtd-string+))
49        (:xhtml10-strict
50         (lml-write-string +xhtml10-strict-dtd-string+))
51        (:xhtml10-transitional
52         (lml-write-string +xhtml10-transitional-dtd-string+))
53        (:xhtml10-frameset
54         (lml-write-string +xhtml10-frameset-dtd-string+)))
55      (when entities
56        (lml-write-char #\space)
57        (lml-write-char #\[)
58        (lml-write-char #\Newline)
59        (lml-write-string entities)
60        (lml-write-char #\Newline)
61        (lml-write-char #\]))
62      (lml-write-char #\>))
63     (:html
64      (lml-write-string +html4-dtd-string+)))
65   (lml-write-char #\newline))
66
67
68 (defmacro html-file-page ((out-file &key (format :xhtml11))
69                           &body body)
70   `(with-open-file (*html-stream*
71                     (lml-file-name ,out-file :output)
72                     :direction :output
73                     :if-exists :supersede)
74      (dtd-prologue ,format)
75      (html
76       ((:html :xmlns "http://www.w3.org/1999/xhtml")
77        ,@body))))
78                      
79
80 (defmacro alink (url desc)
81   `(html
82     ((:a :href ,url) ,desc)))
83
84 (defmacro alink-c (class url desc)
85   `(html
86     ((:a :class ,class :href ,url) ,desc)))