;; validate.el --- Lisp code to validate SXEmacs web pages -*- Emacs-Lisp -*- ;; Copyright (C) 2008 - 2016 Steve Youngs ;; Author: Steve Youngs ;; Maintainer: Steve Youngs ;; Created: <2008-09-19> ;; Homepage: https://www.sxemacs.org/ ;; Keywords: validate web html util ;; This file is part of nothing really. ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; 3. Neither the name of the author nor the names of any contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; ;; This is some ugly lisp that is used to validate the SXEmacs web ;; pages locally with PSGML ;;; Todo: ;; ;; Make it work! ;; OK, it works, now make it ugly-less ;;; Expected Errors ;; ;; Because we do some fancy things with SSI's and variable ;; substitution it can sometimes be impossible to validate some ;; of these pages locally. Here is a list of expected errors ;; that you'll see when validating locally... ;; ;; onsgmls:SXEweb-nOHIVR:74:8:E: literal is missing closing delimiter ;; onsgmls:SXEweb-nOHIVR:78:8:E: literal is missing closing delimiter ;; onsgmls:SXEweb-nOHIVR:78:140:E: end tag for element "a" which is not open ;; ;; Those 3 errors are caused by the "inline shell-script snippets" ;; we have for generating some dynamic content. onsgmls just can't ;; cope with them. They can be safely ignored. ;; ;; Don't bother trying to validate any of these files... ;; 404.html ;; canvas.html ;; rpc_relay.html ;; ;;; Code: (defun validate () "Validate the sxemacs html doc in the current buffer." (interactive) (let* ((vd (temp-directory)) (vf (make-temp-name (expand-file-name "SXEweb-" vd))) (sf (buffer-file-name)) (td (file-name-as-directory (expand-file-name "templates" (file-dirname sf))))) ;; templates might be in .. rather than . (and (file-directory-p (expand-file-name "../templates" (file-dirname sf))) (setq td (file-name-as-directory (expand-file-name "../templates" (file-dirname sf))))) (with-current-buffer (get-buffer-create vf) (erase-buffer) (insert-file-contents-literally sf) ; does that move point? (goto-char (point-min)) (re-search-forward #r"support\.template\" -->" nil t) (forward-line 1) (insert-file (expand-file-name "support.template" td)) (insert-file (expand-file-name "menu.template" td)) (insert-file (expand-file-name "header.template" td)) (goto-char (point-max)) (insert-file (expand-file-name "footer.template" td)) (insert-file (expand-file-name "stats.template" td)) (insert-file (expand-file-name "copyright.template" td)) (while (re-search-backward #r"" nil t) (replace-match "sxemacs.css")) (write-region (point-min) (point-max) vf)) (find-file vf) (sgml-parse-prolog) (sleep-for 5) (sgml-validate (sgml-default-validate-command)))) ;;; validate.el ends here