1 ;; 07-html-sy.el --- HTML settings
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: <Tuesday Apr 14, 2020 17:04:47 steve>
9 ;; Download: <https://downloads.sxemacs.org/SYinits/>
10 ;; HTMLised: <https://www.sxemacs.org/SYinits/07-html.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" SXEmacs package.
116 ;; `htmlize.el' is a lovely piece of code for converting Emacs buffers
117 ;; into HTML. The default settings should be fine for most people most
118 ;; of the time in most situations. But, by now, I'm sure that you've
119 ;; come to the realisation that I don't fit into that category. So
124 ;; Force XHTML 1.0 Transitional
125 (defun htmlize-default-doctype ()
127 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
128 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
130 ;; File-local variables can cause problems so this advice simply
131 ;; disables them when htmlize runs.
132 (defadvice htmlize-buffer (around nolocals (&rest args) activate)
133 "Turn off file local variables during htmlize-buffer."
134 (let ((enable-local-variables nil)
137 (when (interactive-p) (switch-to-buffer buf))))
139 ;; By default htmlize would turn 'file.el' into 'file.el.html', I
140 ;; prefer that it turned it into 'file.html'. That's what this advice
142 (defadvice htmlize-make-file-name (before filename activate)
143 "Prefer filenames \"file.ext\" -> \"file.html\"."
144 (setq file (file-name-sans-extension file)))
146 ;; This function, run from `htmlize-after-hook' lets me embed HTML
147 ;; comments inside normal source comments and also allows me to set up
148 ;; relative hyperlinks.
149 (defun sy-htmlize-set-links ()
150 "Function run from `htmlize-after-hook'.
152 It takes care of any relative hyperlinks and also dequotes any HTML
153 comments that were incorrectly quoted.
155 Relative hyperlinks need to be prepared in a particular way in the
156 file that is to be converted to HTML. For example, in an emacs lisp
159 Get the latest rls=/src/foo.el;rld=version here;rle.
161 Which would be converted to:
163 Get the latest <a href=\"/src/foo.el\">version here</a>."
164 ;; LOL, we actually need to _NOT_ do it in _this_ file so the doc
165 ;; string for this function looks right.
166 (unless (string-match "07-html" (buffer-name htmlbuf))
168 (goto-char (point-min))
170 '(lambda (x) (save-excursion (eval x)))
171 '((replace-string "rls=" "<a href=\"")
172 (replace-string ";rld=" "\">")
173 (replace-string ";rle" "</a>")
174 (replace-string "<!--" "<!--")
175 (replace-string "-->" "-->"))))))
177 (defun sy-htmlize-add-xmlns ()
178 "Adds a xmlns property to the html tag.
180 Because we are trying to output XHTML we need to add the xmlns to the
181 html tag. Done via `htmlize-after-hook'."
183 (goto-char (point-min))
184 (re-search-forward "<html>" nil t)
186 "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">")))
188 ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and
189 ;; are created by SXEmacs. So I announce the fact by adding the appropriate
190 ;; logos to the bottom of the page, together with a copyright notice. This
191 ;; is the raw HTML for that.
192 (defconst sy-htmlize-appendix
193 (concat "<!-- SXEmacs Logo -->
195 <a href=\"https://www.sxemacs.org/\">
196 <img style=\"padding:0px 5px 0px 0px;border:0;width:88px;height:31px\"
197 src=\"/Images/cbsx.png\"
198 title=\"This page was created entirely in SXEmacs\"
199 alt=\"Created with SXEmacs\" />
201 <!-- End SXEmacs Logo -->
203 <!-- Valid XHTML 1.0 / CSS -->
204 <a href=\"http://validator.w3.org/check?uri=referer\">
205 <img style=\"padding:0px 5px 0px 10px;border:0;width:88px;height:31px\"
206 src=\"/Images/valid-xhtml10.png\"
207 title=\"Valid XHTML 1.0 Transitional!\"
208 alt=\"Valid XHTML 1.0 Transitional!\" />
210 <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">
211 <img style=\"padding:0px 0px 0px 5px;border:0;width:88px;height:31px\"
212 src=\"/Images/vcss.png\"
213 title=\"Valid CSS!\" alt=\"Valid CSS!\" />
217 <!-- End Valid HTML / CSS-->
219 <h6>Copyright © "
220 (format-time-string "%Y") " Steve Youngs<br />
221 Verbatim copying and distribution is permitted in any medium,
222 providing this notice is preserved.<br />
230 ;; Appends the above to each page. Run from `htmlize-after-hook'.
231 (defun sy-htmlize-append ()
232 "Append some things to the end of files produced by `htmlize.el'."
233 (goto-char (point-max))
234 (re-search-backward "</body>" nil t)
235 (insert sy-htmlize-appendix))
237 ;; Set a couple of basic things.
239 htmlize-html-charset nil
240 htmlize-html-major-mode 'html-mode
242 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
243 <meta name=\"author\" content=\"Steve Youngs\" />
244 <meta name=\"owner\" content=\"steve@sxemacs.org\" />
247 (setq htmlize-hyperlink-style "
250 background-color: inherit;
253 text-decoration: underline;
257 background-color: #FD00FD;
258 text-decoration: underline;
261 background-color: #000000;
262 text-decoration: none;
267 (defvar sy-htmlize-this-file nil
268 "The name of the file we htmlize'd.")
269 (defun sy-htmlize-before-hook ()
270 "Prepares the buffer for htmlising.
271 Turns off howm-mode as it can play havoc with the font-locking, and we
272 force a fontify of the buffer."
273 (setq sy-htmlize-this-file (buffer-file-name))
274 (and howm-mode (howm-mode 0))
275 (font-lock-fontify-buffer))
277 (defun sy-htmlize-after-hook ()
278 (sy-htmlize-set-links)
280 (sy-htmlize-add-xmlns)
281 (with-current-buffer (get-file-buffer sy-htmlize-this-file)
282 (normal-mode)) ; Will turn howm-mode back on if it was off
283 (setq sy-htmlize-this-file nil))
285 (add-hook 'htmlize-before-hook #'sy-htmlize-before-hook)
286 (add-hook 'htmlize-after-hook #'sy-htmlize-after-hook)
287 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
288 (message "HTML settings initialised")