Update htmlize code to output XHTML
authorSteve Youngs <steve@sxemacs.org>
Tue, 14 Apr 2020 07:09:32 +0000 (17:09 +1000)
committerSteve Youngs <steve@sxemacs.org>
Tue, 14 Apr 2020 07:09:32 +0000 (17:09 +1000)
* 07-html.el (htmlize-default-doctype): XHTML 1.0 Transitional,
thank you very much.
(sy-htmlize-add-xmlns): New. Called from htmlize-after-hook to add
the xmlns prop to the html tag.
(sy-htmlize-appendix): Update for XHTML 1.0 compliance.
(htmlize-html-charset): Set to nil so I can have better control
over what is put into the head section.
(htmlize-head-tags): Updated.
(sy-htmlize-after-hook): Also run #'sy-htmlize-add-xmlns.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
07-html.el

index c1f60f8..40d121d 100644 (file)
@@ -5,7 +5,7 @@
 ;;     Author: Steve Youngs <steve@sxemacs.org>
 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
 ;;    Created: <2007-12-02>
-;; Time-stamp: <Friday Apr 10, 2020 15:14:04 steve>
+;; Time-stamp: <Tuesday Apr 14, 2020 17:04:47 steve>
 ;;   Download: <https://downloads.sxemacs.org/SYinits/>
 ;;   HTMLised: <https://www.sxemacs.org/SYinits/07-html.html>
 ;;   Git Repo: git clone https://git.sxemacs.org/syinit
 (eval-and-compile
   (require 'htmlize))
 
+;; Force XHTML 1.0 Transitional
+(defun htmlize-default-doctype ()
+  nil
+  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
+ \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
+
 ;; File-local variables can cause problems so this advice simply
 ;; disables them when htmlize runs.
 (defadvice htmlize-buffer (around nolocals (&rest args) activate)
@@ -168,6 +174,17 @@ Which would be converted to:
         (replace-string "&lt;!--" "<!--")
         (replace-string "--&gt;" "-->"))))))
 
+(defun sy-htmlize-add-xmlns ()
+  "Adds a xmlns property to the html tag.
+
+Because we are trying to output XHTML we need to add the xmlns to the
+html tag.  Done via `htmlize-after-hook'."
+  (save-excursion
+    (goto-char (point-min))
+    (re-search-forward "<html>" nil t)
+    (replace-match
+     "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">")))
+
 ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and
 ;; are created by SXEmacs.  So I announce the fact by adding the appropriate
 ;; logos to the bottom of the page, together with a copyright notice.  This
@@ -179,30 +196,30 @@ Which would be converted to:
        <img style=\"padding:0px 5px 0px 0px;border:0;width:88px;height:31px\"
          src=\"/Images/cbsx.png\"
          title=\"This page was created entirely in SXEmacs\"
-         alt=\"Created with SXEmacs\">
+         alt=\"Created with SXEmacs\" />
       </a>
 <!--  End SXEmacs Logo -->
 
 <!--  Valid XHTML 1.0 / CSS -->
-      <a href=\"http://validator.w3.org/check/referer\">
+      <a href=\"http://validator.w3.org/check?uri=referer\">
         <img style=\"padding:0px 5px 0px 10px;border:0;width:88px;height:31px\"
-         src=\"/Images/valid-html401.png\"
-         title=\"Valid HTML 4.01 Strict!\"
-         alt=\"Valid HTML 4.01 Strict!\">
+         src=\"/Images/valid-xhtml10.png\"
+         title=\"Valid XHTML 1.0 Transitional!\"
+         alt=\"Valid XHTML 1.0 Transitional!\" />
       </a>
       <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">
        <img style=\"padding:0px 0px 0px 5px;border:0;width:88px;height:31px\"
          src=\"/Images/vcss.png\"
-         title=\"Valid CSS!\" alt=\"Valid CSS!\">
+         title=\"Valid CSS!\" alt=\"Valid CSS!\" />
       </a>
     </div>
-</p>
+
 <!--  End Valid HTML / CSS-->
 
     <h6>Copyright &#169; "
-         (format-time-string "%Y") " Steve Youngs<br>
+         (format-time-string "%Y") " Steve Youngs<br />
      Verbatim copying and distribution is permitted in any medium,
-    providing this notice is preserved.<br>
+    providing this notice is preserved.<br />
 <!-- hhmts start -->
 <!-- hhmts end -->
    </h6>
@@ -219,11 +236,12 @@ Which would be converted to:
 
 ;; Set a couple of basic things.
 (setq
- htmlize-html-charset "UTF-8"
+ htmlize-html-charset nil
  htmlize-html-major-mode 'html-mode
  htmlize-head-tags
- "<meta name=\"author\" content=\"Steve Youngs\">
-<meta name=\"owner\" content=\"steve@sxemacs.org\">
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
+    <meta name=\"author\" content=\"Steve Youngs\" />
+    <meta name=\"owner\" content=\"steve@sxemacs.org\" />
 ")
 
 (setq htmlize-hyperlink-style "
@@ -259,6 +277,7 @@ force a fontify of the buffer."
 (defun sy-htmlize-after-hook ()
   (sy-htmlize-set-links)
   (sy-htmlize-append)
+  (sy-htmlize-add-xmlns)
   (with-current-buffer (get-file-buffer sy-htmlize-this-file)
     (normal-mode)) ; Will turn howm-mode back on if it was off
   (setq sy-htmlize-this-file nil))