1 ;; validate.el --- Lisp code to validate SXEmacs web pages -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2008 - 2012 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2008-09-19>
8 ;; Homepage: http://www.sxemacs.org/
9 ;; Keywords: validate web html util
11 ;; This file is part of nothing really.
13 ;; Redistribution and use in source and binary forms, with or without
14 ;; modification, are permitted provided that the following conditions
17 ;; 1. Redistributions of source code must retain the above copyright
18 ;; notice, this list of conditions and the following disclaimer.
20 ;; 2. Redistributions in binary form must reproduce the above copyright
21 ;; notice, this list of conditions and the following disclaimer in the
22 ;; documentation and/or other materials provided with the distribution.
24 ;; 3. Neither the name of the author nor the names of any contributors
25 ;; may be used to endorse or promote products derived from this
26 ;; software without specific prior written permission.
28 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
29 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ;; This is some ugly lisp that is used to validate the SXEmacs web
43 ;; pages locally with PSGML
48 ;; OK, it works, now make it ugly-less
52 ;; Because we do some fancy things with SSI's and variable
53 ;; substitution it can sometimes be impossible to validate some
54 ;; of these pages locally. Here is a list of expected errors
55 ;; that you'll see when validating locally...
57 ;; onsgmls:SXEweb-nOHIVR:74:8:E: literal is missing closing delimiter
58 ;; onsgmls:SXEweb-nOHIVR:78:8:E: literal is missing closing delimiter
59 ;; onsgmls:SXEweb-nOHIVR:78:140:E: end tag for element "a" which is not open
61 ;; Those 3 errors are caused by the "inline shell-script snippets"
62 ;; we have for generating some dynamic content. onsgmls just can't
63 ;; cope with them. They can be safely ignored.
65 ;; Don't bother trying to validate any of these files...
73 "Validate the sxemacs html doc in the current buffer."
75 (let* ((vd (temp-directory))
76 (vf (make-temp-name (expand-file-name "SXEweb-" vd)))
77 (sf (buffer-file-name))
78 (td (file-name-as-directory
79 (expand-file-name "templates" (file-dirname sf)))))
80 ;; templates might be in .. rather than .
81 (and (file-directory-p (expand-file-name "../templates" (file-dirname sf)))
82 (setq td (file-name-as-directory
83 (expand-file-name "../templates" (file-dirname sf)))))
84 (with-current-buffer (get-buffer-create vf)
86 (insert-file-contents-literally sf) ; does that move point?
87 (goto-char (point-min))
88 (re-search-forward #r"support\.template\" -->" nil t)
90 (insert-file (expand-file-name "support.template" td))
91 (insert-file (expand-file-name "menu.template" td))
92 (insert-file (expand-file-name "header.template" td))
93 (goto-char (point-max))
94 (insert-file (expand-file-name "footer.template" td))
95 (insert-file (expand-file-name "stats.template" td))
96 (insert-file (expand-file-name "copyright.template" td))
97 (while (re-search-backward #r"<!--#echo var=\"css\" -->" nil t)
98 (replace-match "sxemacs.css"))
99 (write-region (point-min) (point-max) vf))
103 (sgml-validate (sgml-default-validate-command))))
105 ;;; validate.el ends here