1 ;; 07-html-sy.el --- HTML settings -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2007 - 2020 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Wednesday Feb 12, 2020 13:05:05 steve>
9 ;; Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;; HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/07-html-sy.html>
11 ;; Git Repo: git clone https://git.sxemacs.org/syinit
12 ;; Keywords: init, compile
14 ;; This file is part of SYinit
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;; notice, this list of conditions and the following disclaimer.
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;; notice, this list of conditions and the following disclaimer in the
25 ;; documentation and/or other materials provided with the distribution.
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;; may be used to endorse or promote products derived from this
29 ;; software without specific prior written permission.
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 ;; Sets up things for writing HTML.
49 ;; The HTML version of this file was created with Hrvoje Niksic's
50 ;; htmlize.el which is part of the XEmacs "text-modes" package.
58 ;:*=======================
59 ;:* General HTML settings.
61 html-helper-htmldtd-version
62 "<?xml version=\"1.0\" encoding=\"utf-8\"?>
63 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
64 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
65 html-helper-use-expert-menu t
66 hm--html-automatic-create-modified-line t
67 hm--html-automatic-update-modified-line t
68 hm--html-changed-comment-prefix "Changed with SXEmacs, by: "
69 hm--html-created-comment-prefix "Created with SXEmacs, by: "
71 hm--html-html-doctype-version
72 "\"-//W3C//DTD XHTML 1.0 Transitional//EN\"
73 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
74 hm--html-log-date-format "%y-%m-%d"
76 (file-name-as-directory
77 (expand-file-name "templates"
78 (locate-data-directory "hm--html-menus")))
79 hm--html-frame-template-file
80 (expand-file-name "frame.html.tmpl" hm--html-template-dir)
81 hm--html-title-date-format "%y-%m-%d"
82 hm--html-username "Steve Youngs"
83 html-sigusr1-signal-value 10)
87 sgml-auto-activate-dtd t
88 sgml-live-element-indicator t
89 sgml-validate-command "onsgmls -s -m %s %s")
92 (directory-files-recur "/usr/share/sgml" 'full nil nil 'subdir)
93 "List of directories for `sgml-system-path'.")
95 (setq sgml-system-path
97 "/usr/share/sxemacs/xemacs-packages/etc/psgml-dtds/")
100 (autoload 'html-mode "psgml-html" "Load psgml-html-mode" t)
101 (autoload 'css-mode "css-mode")
103 (add-hook 'html-mode-hook #'hm--html-minor-mode)
104 (eval-when-compile (defvar ispell-extra-args))
105 (add-hook 'html-mode-hook
107 (make-local-variable 'ispell-extra-args)
108 (push "-H" ispell-extra-args)))
109 (add-hook 'html-helper-timestamp-hook #'html-helper-default-insert-timestamp)
111 ;:*=======================
112 ;:* Hrvoje Niksic's htmlize
114 ;; `htmlize.el' comes with the "text-modes" XEmacs package, or you
115 ;; can get the latest version from:
117 ;; <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el>.
119 ;; `htmlize.el' is a lovely piece of code for converting Emacs buffers
120 ;; into HTML. The default settings should be fine for most people most
121 ;; of the time in most situations. But, by now, I'm sure that you've
122 ;; come to the realisation that I don't fit into that category. So
127 ;; Those "local-variables" declarations you sometimes see at the bottom
128 ;; of source files can cause quite a bit of havoc when it comes to
129 ;; "htmlize'ing" them. Basically what happens is that when you go to
130 ;; save the resulting HTML buffer XEmacs goes into an infinite loop
131 ;; complaining about bad local vars. I get around it with this next
132 ;; function which just a simple wrapper for `htmlize-buffer'.
133 (defun sy-htmlize-buffer (&optional buffer)
134 "This is just a simple wrapper for `htmlize-buffer'.
136 All it does is scan the buffer to be converted for any local variable
137 declarations and replaces them with a place holder. This prevents an
138 infloop when you go to save the resulting HTML buffer.
140 Original `htmlize-buffer' doc string:
142 Convert buffer to HTML, preserving the font-lock colorization.
143 The generated HTML is available in a new buffer, which is returned.
144 When invoked interactively, the new buffer is selected in the
147 (let ((htmlbuf (with-current-buffer (or buffer (current-buffer))
148 (goto-char (point-min))
149 (while (re-search-forward
150 ;; This concat is deliberately split accross
151 ;; 4 lines for a reason. Don't change it!
155 " Variables:$") nil t)
157 (concat comment-start
158 " Put the normal local variables declaration here")))
160 ;; Undo that replace-match.
161 (when (buffer-modified-p)
163 (when (interactive-p)
164 (switch-to-buffer htmlbuf))
167 ;; Use my function by default.
168 (defalias 'htmlize-buffer 'sy-htmlize-buffer)
170 ;; This function, run from `htmlize-after-hook' lets me embed HTML
171 ;; comments inside normal source comments and also allows me to set up
172 ;; relative hyperlinks. It has been hand-massaged after htmlizing to
173 ;; get the desired results for its doc string.
174 (defun sy-htmlize-after-hook ()
175 "Function run from `htmlize-after-hook'.
177 It takes care of any relative hyperlinks and also dequotes any HTML
178 comments that were incorrectly quoted.
180 Relative hyperlinks need to be prepared in a particular way in the
181 file that is to be converted to HTML. For example, in an emacs lisp
184 Get the latest rls=/src/foo.el;rld=version here;rle.
186 Which would be converted to:
188 Get the latest <a href=\"/src/foo.el\">version here</a>."
190 (goto-char (point-min))
192 '(lambda (x) (save-excursion (eval x)))
193 '((replace-string "rls=" "<a href=\"")
194 (replace-string ";rld=" "\">")
195 (replace-string ";rle" "</a>")
196 (replace-string "<!--" "<!--")
197 (replace-string "-->" "-->")))))
199 ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and
200 ;; are created by SXEmacs. So I announce the fact by adding the appropriate
201 ;; logos to the bottom of the page, together with a copyright notice. This
202 ;; is the raw HTML for that.
203 (defconst sy-htmlize-appendix
204 (concat "<!-- Logos -->
207 <!-- SXEmacs Logo -->
208 <a href=\"http://www.sxemacs.org/\">
209 <img style=\"border:0;width:88px;height:31px\"
210 src=\"/~steve/images/cbsx.png\"
211 alt=\"Created with SXEmacs\"></a>
212 <!-- End SXEmacs Logo -->
214 <!-- Valid XHTML 1.0 / CSS -->
215 <a href=\"http://validator.w3.org/check/referer\">
216 <img style=\"border:0;width:88px;height:31px\"
217 src=\"/~steve/images/valid-html401.png\"
218 alt=\"Valid HTML 4.01 Strict!\"></a>
219 <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">
220 <img style=\"border:0;width:88px;height:31px\"
221 src=\"/~steve/images/vcss.png\"
225 <!-- End Valid HTML / CSS-->
227 <h6>Copyright © "
228 (format-time-string "%Y")
230 Verbatim copying and distribution is permitted in any medium,
231 providing this notice is preserved.<br>
238 ;; Appends the above to each page. Run from `htmlize-after-hook'.
239 (defun sy-htmlize-append ()
240 "Append some things to the end of files produced by `htmlize.el'."
241 (goto-char (point-max))
242 (re-search-backward "</body>" nil t)
243 (insert sy-htmlize-appendix))
245 ;; Set a couple of basic things.
247 htmlize-html-charset "UTF-8"
248 htmlize-html-major-mode 'html-mode
250 "<meta name=\"author\" content=\"Steve Youngs\">
251 <meta name=\"owner\" content=\"steve@sxemacs.org\">
254 (setq htmlize-hyperlink-style "
257 background-color: inherit;
260 text-decoration: underline;
264 background-color: #FD00FD;
265 text-decoration: underline;
271 (defun sy-htmlize-before-hook ()
272 "Prepares the buffer for htmlising.
273 Turns off howm-mode as it can play havoc with the font-locking, and we
274 force a fontify of the buffer."
277 (turn-off-howm-mode))
278 (font-lock-fontify-buffer)))
280 (add-hook 'htmlize-before-hook #'sy-htmlize-before-hook)
281 (add-hook 'htmlize-after-hook
283 (sy-htmlize-after-hook)
285 (font-lock-fontify-buffer)))
286 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
287 (message "hm--html-mode initialised")