r8598: Automated commit for Debian build of lml2 upstream-version-1.5.0
[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 xml-header-stream (stream &key (version "1.0") (standalone :unspecified)
42                    (encoding :unspecified))
43   (format stream "<?xml version=\"~A\"~A~A ?>"
44           version
45           (if (eq standalone :unspecified)
46               ""
47               (format nil " standalone=\"~A\"" standalone))
48           (if (eq encoding :unspecified)
49               ""
50               (format nil " encoding=\"~A\"" encoding))))
51           
52 (defun dtd-prologue (&optional (format :xhtml11) &key entities)
53   (case format
54     ((:xhtml :xhtml11 :xhtml10-strict :xhtml10-transitional :xhtml10-frameset :xml)
55      (lml-write-string +xml-prologue-string+)
56      (lml-write-char #\newline)
57      (case format
58        ((:xhtml11 :xhtml)
59         (lml-write-string +xhtml11-dtd-string+))
60        (:xhtml10-strict
61         (lml-write-string +xhtml10-strict-dtd-string+))
62        (:xhtml10-transitional
63         (lml-write-string +xhtml10-transitional-dtd-string+))
64        (:xhtml10-frameset
65         (lml-write-string +xhtml10-frameset-dtd-string+)))
66      (when entities
67        (lml-write-char #\space)
68        (lml-write-char #\[)
69        (lml-write-char #\Newline)
70        (lml-write-string entities)
71        (lml-write-char #\Newline)
72        (lml-write-char #\]))
73      (lml-write-char #\>))
74     (:html
75      (lml-write-string +html4-dtd-string+)))
76   (lml-write-char #\newline))
77
78
79 (defmacro html-file-page ((out-file &key (format :xhtml11))
80                           &body body)
81   `(with-open-file (*html-stream*
82                     (lml-file-name ,out-file :output)
83                     :direction :output
84                     :if-exists :supersede)
85      (dtd-prologue ,format)
86      (html
87       ((:html :xmlns "http://www.w3.org/1999/xhtml")
88        ,@body))))
89                      
90
91 (defmacro alink (url desc)
92   `(html
93     ((:a :href ,url) ,desc)))
94
95 (defmacro alink-c (class url desc)
96   `(html
97     ((:a :class ,class :href ,url) ,desc)))