emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] export to various flavors of (X)HTML
@ 2013-04-19  9:57 Eric Abrahamsen
  2013-04-19 15:37 ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-19  9:57 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: rick

[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]

I'm starting a new thread for this since the previous discussion was
buried in with something tangential.

I've attached what I think is a working patch to allow ox-html to export
to different flavors of (X)HTML. It works via `org-html-doctype': in
addition to setting it to a doctype string directly, you can also set it
to one of the following (defaults to xhtml-strict):

html4-strict
html4-transitional
html4-frameset
xhtml-strict
xhtml-transitional
xhtml-framset
xhtml-11
html5

The doctype will be set correctly, and the HTML output will be adjusted
to conform to the requirements of that doctype, with No Errors
Whatsoever™. The results validate, anyway...

I'm not proud of some of the implementation (self-closing vs
non-self-closing tags are ugly, and I wish org-html-html5-p and
org-html-xhtml-p were variables, not functions), but there it is, it
seems to work.

If this is deemed okay I'll send a version of the patch with a proper
commit message, and also updated documentation.

And once that's done I've got another that builds on this, allowing you
to use stuff like <canvas> and <video>. Whee!

Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Export-to-different-flavors-of-x-html.patch --]
[-- Type: text/x-patch, Size: 18945 bytes --]

From 6ab61bbd573b7625e23e33f439aa2c579880cf56 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Fri, 19 Apr 2013 15:39:40 +0800
Subject: [PATCH] Export to different flavors of (x)html.

---
 lisp/ox-html.el | 209 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 140 insertions(+), 69 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 54c6a45..ede983d 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -143,6 +143,26 @@
 (defvar org-html--pre/postamble-class "status"
   "CSS class used for pre/postamble")
 
+(defconst org-html-doctype-alist
+  '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
+\"http://www.w3.org/TR/html4/strict.dtd\">")
+    ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+\"http://www.w3.org/TR/html4/loose.dtd\">")
+    ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
+\"http://www.w3.org/TR/html4/frameset.dtd\">")
+
+    ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
+    ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
+    ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
+    ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
+
+    ("html5" . "<!DOCTYPE html>"))
+  "An alist mapping (x)html flavors to specific doctypes.")
+
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
@@ -150,6 +170,10 @@
     ("\\.\\.\\." . "&#x2026;"))		; hellip
   "Regular expressions for special string conversion.")
 
+(defconst org-html-cdata-regexp
+  "\\(<!--/\\*--><!\\[CDATA\\[/\\*><!--\\*/\n\\|/\\*\\]\\]>\\*/\\{1,3\\}-->\n\\)"
+  "Regexp used to strip escape tags from script blocks")
+
 (defconst org-html-scripts
   "<script type=\"text/javascript\">
 /*
@@ -748,7 +772,9 @@ in all modes you want.  Then, use the command
   '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
   "Default attributes and values which will be used in table tags.
 This is a plist where attributes are symbols, starting with
-colons, and values are strings."
+colons, and values are strings.
+
+When exporting to HTML5, these values will be disregarded."
   :group 'org-export-html
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -856,7 +882,9 @@ CSS classes, then this prefix can be very useful."
   "The extension for exported HTML files.
 %s will be replaced with the charset of the exported file.
 This may be a string, or an alist with export extensions
-and corresponding declarations."
+and corresponding declarations.
+
+This declaration only applies when exporting to XHTML."
   :group 'org-export-html
   :type '(choice
 	  (string :tag "Single declaration")
@@ -872,8 +900,7 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :type 'coding-system)
 
-(defcustom org-html-doctype
-  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
+(defcustom org-html-doctype "xhtml-strict"
   "Document type definition to use for exported HTML files.
 Can be set with the in-buffer HTML_DOCTYPE property or for
 publishing, with :html-doctype."
@@ -962,7 +989,8 @@ You can also customize this for each buffer, using something like
 		    (const :format "       " mathml) (boolean))))
 
 (defcustom org-html-mathjax-template
-  "<script type=\"text/javascript\" src=\"%PATH\">
+  "<script type=\"text/javascript\" src=\"%PATH\"></script>
+<script type=\"text/javascript\">
 <!--/*--><![CDATA[/*><!--*/
     MathJax.Hub.Config({
         // Only one of the two following lines, depending on user settings
@@ -1035,7 +1063,7 @@ precedence over this variable."
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"creator\">%c</p>
-<p class=\"xhtml-validation\">%v</p>"))
+<p class=\"validation\">%v</p>"))
   "Alist of languages and format strings for the HTML postamble.
 
 The first element of each list is the language code, as used for
@@ -1060,7 +1088,7 @@ like that: \"%%\"."
 		:value-type (string :tag "Format string")))
 
 (defcustom org-html-validation-link
-  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
+  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
   "Link to HTML validation service."
   :group 'org-export-html
   :type 'string)
@@ -1240,6 +1268,19 @@ CSS classes, then this prefix can be very useful."
 \f
 ;;; Internal Functions
 
+(defun org-html-xhtml-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+    (string-match-p dt "xhtml")))
+
+(defun org-html-html5-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+	(member dt '("html5" "<!doctype html>"))))
+
+(defun org-html-close-tag (info)
+  (if (org-html-xhtml-p info)
+      " />"
+    ">"))
+
 (defun org-html--make-attribute-string (attributes)
   "Return a list of attributes, as a string.
 ATTRIBUTES is a plist where values are either strings or nil. An
@@ -1253,7 +1294,7 @@ attributes with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
-(defun org-html-format-inline-image (src &optional
+(defun org-html-format-inline-image (src &optional info
 					 caption label attr standalone-p)
   "Format an inline image from SRC.
 CAPTION, LABEL and ATTR are optional arguments providing the
@@ -1273,12 +1314,14 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
 				   (file-name-nondirectory src)))))))
     (cond
      (standalone-p
-      (let ((img (format "<img src=\"%s\" %s/>" src attr)))
+      (let ((img (format "<img src=\"%s\" %s%s" src attr
+			 (org-html-close-tag info))))
 	(format "\n<div%s class=\"figure\">%s%s\n</div>"
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
 		    (format "\n<p>%s</p>" caption) ""))))
-     (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
+     (t (format "<img src=\"%s\" %s%s" src (concat attr id)
+		(org-html-close-tag info))))))
 
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
@@ -1437,7 +1480,8 @@ INFO is a plist used as a communication channel."
 				 (cons 'plain-text org-element-all-objects)
 			       'identity info))))))
 	(description (plist-get info :description))
-	(keywords (plist-get info :keywords)))
+	(keywords (plist-get info :keywords))
+	(close (org-html-close-tag info)))
     (concat
      (format "<title>%s</title>\n" title)
      (format
@@ -1445,36 +1489,45 @@ INFO is a plist used as a communication channel."
 	(format-time-string
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
      (format
-      "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
+      (if (org-html-html5-p info)
+	  "<meta charset=\"%s\">\n"
+	"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"%s\n")
       (or (and org-html-coding-system
 	       (fboundp 'coding-system-get)
 	       (coding-system-get org-html-coding-system 'mime-charset))
-	  "iso-8859-1"))
-     (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
+	  "iso-8859-1") close)
+     (format "<meta name=\"generator\" content=\"Org-mode\"%s\n" close)
      (and (org-string-nw-p author)
-	  (format "<meta name=\"author\" content=\"%s\"/>\n"
-		  (funcall protect-string author)))
+	  (format "<meta name=\"author\" content=\"%s\"%s\n"
+		  (funcall protect-string author) close))
      (and (org-string-nw-p description)
-	  (format "<meta name=\"description\" content=\"%s\"/>\n"
-		  (funcall protect-string description)))
+	  (format "<meta name=\"description\" content=\"%s\"%s\n"
+		  (funcall protect-string description) close))
      (and (org-string-nw-p keywords)
-	  (format "<meta name=\"keywords\" content=\"%s\"/>\n"
-		  (funcall protect-string keywords))))))
+	  (format "<meta name=\"keywords\" content=\"%s\"%s\n"
+		  (funcall protect-string keywords) close)))))
 
 (defun org-html--build-head (info)
   "Return information for the <head>..</head> of the HTML output.
 INFO is a plist used as a communication channel."
-  (org-element-normalize-string
-   (concat
-    (when (plist-get info :html-head-include-default-style)
-      (org-element-normalize-string org-html-style-default))
-    (org-element-normalize-string (plist-get info :html-head))
-    (org-element-normalize-string (plist-get info :html-head-extra))
-    (when (and (plist-get info :html-htmlized-css-url)
-	       (eq org-html-htmlize-output-type 'css))
-      (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
-	      (plist-get info :html-htmlized-css-url)))
-    (when (plist-get info :html-head-include-scripts) org-html-scripts))))
+  (let ((head-string
+	 (org-element-normalize-string
+	  (concat
+	   (when (plist-get info :html-head-include-default-style)
+	     (org-element-normalize-string org-html-style-default))
+	   (org-element-normalize-string (plist-get info :html-head))
+	   (org-element-normalize-string (plist-get info :html-head-extra))
+	   (when (and (plist-get info :html-htmlized-css-url)
+		      (eq org-html-htmlize-output-type 'css))
+	     (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" %s\n"
+		     (plist-get info :html-htmlized-css-url)
+		     (org-html-close-tag info)))
+	   (when (plist-get info :html-head-include-scripts)
+	     org-html-scripts)))))
+    (when (org-html-html5-p info)
+      (setq head-string
+	    (replace-regexp-in-string org-html-cdata-regexp "" head-string)))
+    head-string))
 
 (defun org-html--build-mathjax-config (info)
   "Insert the user setup into the mathjax template.
@@ -1507,6 +1560,10 @@ INFO is a plist used as a communication channel."
 	  (setq template (replace-match yes t t template)))
       (if (string-match ":MMLNO:" template)
 	  (setq template (replace-match no t t template)))
+      ;; remove CDATA escapes for html5
+      (when (org-html-html5-p info)
+	(setq template (replace-regexp-in-string
+			org-html-cdata-regexp "" template)))
       ;; Return the modified template.
       (org-element-normalize-string template))))
 
@@ -1570,7 +1627,7 @@ communication channel."
 		       (format-time-string org-html-metadata-timestamp-format)))
 		    (when (plist-get info :with-creator)
 		      (format "<p class=\"creator\">%s</p>\n" creator))
-		    (format "<p class=\"xhtml-validation\">%s</p>\n"
+		    (format "<p class=\"validation\">%s</p>\n"
 			    validation-link))))
 		(t (format-spec
 		    (or (cadr (assoc
@@ -1612,23 +1669,31 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
   (concat
-   (format
-    (or (and (stringp org-html-xml-declaration)
-	     org-html-xml-declaration)
-	(cdr (assoc (plist-get info :html-extension)
-		    org-html-xml-declaration))
-	(cdr (assoc "html" org-html-xml-declaration))
-
-	"")
-    (or (and org-html-coding-system
-	     (fboundp 'coding-system-get)
-	     (coding-system-get org-html-coding-system 'mime-charset))
-	"iso-8859-1"))
-   "\n"
-   (plist-get info :html-doctype)
+   (when (org-html-xhtml-p info)
+     (format "%s\n"
+	     (format (or (and (stringp org-html-xml-declaration)
+			      org-html-xml-declaration)
+			 (cdr (assoc (plist-get info :html-extension)
+				     org-html-xml-declaration))
+			 (cdr (assoc "html" org-html-xml-declaration))
+
+			 "")
+		     (or (and org-html-coding-system
+			      (fboundp 'coding-system-get)
+			      (coding-system-get org-html-coding-system 'mime-charset))
+			 "iso-8859-1"))))
+   (let* ((dt (plist-get info :html-doctype))
+	  (dt-cons (assoc dt org-html-doctype-alist)))
+     (if dt-cons
+	 (cdr dt-cons)
+       dt))
    "\n"
-   (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
-	   (plist-get info :language) (plist-get info :language))
+   (concat "<html"
+	   (when (org-html-xhtml-p info)
+	     (format
+	      " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
+	      (plist-get info :language) (plist-get info :language)))
+	   ">\n")
    "<head>\n"
    (org-html--build-meta-info info)
    (org-html--build-head info)
@@ -2179,7 +2244,7 @@ holding contextual information."
       ;; Build the real contents of the sub-tree.
       (let* ((type (if numberedp 'ordered 'unordered))
 	     (itemized-body (org-html-format-list-item
-			     contents type nil nil full-text)))
+			     contents type nil info nil full-text)))
 	(concat
 	 (and (org-export-first-sibling-p headline info)
 	      (org-html-begin-plain-list type))
@@ -2239,7 +2304,7 @@ holding contextual information."
 (defun org-html-horizontal-rule (horizontal-rule contents info)
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<hr/>")
+  (format "<hr%s" (org-html-close-tag info)))
 
 ;;;; Inline Src Block
 
@@ -2275,8 +2340,9 @@ holding contextual information."
       (org-html-format-headline--wrap
        inlinetask info format-function :contents contents)))
    ;; Otherwise, use a default template.
-   (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
+   (t (format "<div class=\"inlinetask\">\n<b>%s</b><br%s\n%s</div>"
 	      (org-html-format-headline--wrap inlinetask info)
+	      (org-html-close-tag info)
 	      contents))))
 
 ;;;; Italic
@@ -2296,11 +2362,12 @@ contextual information."
 	(trans "<code>[-]</code>")
 	(t "")))
 
-(defun org-html-format-list-item (contents type checkbox
+(defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     headline)
   "Format a list item into HTML."
-  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
+  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
+	(br (format "<br%s" (org-html-close-tag info))))
     (concat
      (case type
        (ordered
@@ -2308,13 +2375,13 @@ contextual information."
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (unordered
 	(let* ((id term-counter-id)
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (descriptive
 	(let* ((term term-counter-id))
 	  (setq term (or term "(no term)"))
@@ -2340,7 +2407,7 @@ contextual information."
 	 (tag (let ((tag (org-element-property :tag item)))
 		(and tag (org-export-data tag info)))))
     (org-html-format-list-item
-     contents type checkbox (or tag counter))))
+     contents type checkbox info (or tag counter))))
 
 ;;;; Keyword
 
@@ -2399,7 +2466,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(when (and formula-link
 		   (string-match "file:\\([^]]*\\)" formula-link))
 	  (org-html-format-inline-image
-	   (match-string 1 formula-link) caption label attr t))))
+	   (match-string 1 formula-link) info caption label attr t))))
      (t latex-frag))))
 
 ;;;; Latex Fragment
@@ -2418,7 +2485,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 (when (and formula-link
 		    (string-match "file:\\([^]]*\\)" formula-link))
 	   (org-html-format-inline-image
-	    (match-string 1 formula-link)))))
+	    (match-string 1 formula-link) info))))
       (t latex-frag))))
 
 ;;;; Line Break
@@ -2426,7 +2493,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<br/>\n")
+  (format "<br%s\n" (org-html-close-tag info)))
 
 ;;;; Link
 
@@ -2451,7 +2518,7 @@ Inline images can have these attributes:
 	 (label (org-element-property :name parent)))
     ;; Return proper string, depending on DISPOSITION.
     (org-html-format-inline-image
-     path caption label
+     path info caption label
      (org-html--make-attribute-string
       (org-export-read-attribute :attr_html parent))
      (org-html-standalone-image-p link info))))
@@ -2772,7 +2839,8 @@ contextual information."
     (when (plist-get info :preserve-breaks)
       (setq output
 	    (replace-regexp-in-string
-	     "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
+	     "\\(\\\\\\\\\\)?[ \t]*\n"
+	     (format "<br%s\n" (org-html-close-tag info)) output)))
     ;; Return value.
     output))
 
@@ -3047,11 +3115,12 @@ contextual information."
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (attributes
-	     (org-html--make-attribute-string
-	      (org-combine-plists
-	       (and label (list :id (org-export-solidify-link-text label)))
-	       (plist-get info :html-table-attributes)
-	       (org-export-read-attribute :attr_html table))))
+	     (if (org-html-html5-p info) ""
+	       (org-html--make-attribute-string
+		(org-combine-plists
+		 (and label (list :id (org-export-solidify-link-text label)))
+		 (plist-get info :html-table-attributes)
+		 (org-export-read-attribute :attr_html table)))))
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3069,7 +3138,8 @@ contextual information."
 			     table-cell info)
 			"\n<colgroup>")
 		      ;; Add a column.  Also specify it's alignment.
-		      (format "\n<col %s/>" (format alignspec alignment))
+		      (format "\n<col %s%s" (format alignspec alignment)
+			      (org-html-close-tag info))
 		      ;; End a colgroup?
 		      (when (org-export-table-cell-ends-colgroup-p
 			     table-cell info)
@@ -3131,9 +3201,10 @@ contextual information."
   ;; Replace each newline character with line break.  Also replace
   ;; each blank line with a line break.
   (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" "<br/>\n"
+		  "^ *\\\\\\\\$" (format "<br%s\n" (org-html-close-tag info))
 		  (replace-regexp-in-string
-		   "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
+		   "\\(\\\\\\\\\\)?[ \t]*\n"
+		   (format " <br%s\n" (org-html-close-tag info)) contents)))
   ;; Replace each white space at beginning of a line with a
   ;; non-breaking space.
   (while (string-match "^[ \t]+" contents)
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-19  9:57 [PATCH] export to various flavors of (X)HTML Eric Abrahamsen
@ 2013-04-19 15:37 ` Rick Frankel
  2013-04-20  2:59   ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-04-19 15:37 UTC (permalink / raw)
  To: emacs-orgmode

On 19.04.2013 05:57, Eric Abrahamsen wrote:
> I'm starting a new thread for this since the previous discussion was
> buried in with something tangential.

> I'm not proud of some of the implementation (self-closing vs
> non-self-closing tags are ugly, and I wish org-html-html5-p and
> org-html-xhtml-p were variables, not functions), but there it is, it
> seems to work.
>
> If this is deemed okay I'll send a version of the patch with a proper
> commit message, and also updated documentation.

I disagree with the minimized closing patch change.

All versions of html accept the " />" idiom (with the extra space so 
that html4 only browsers
don't break) for minimized tags (also "></{elem}", e.g. "<hr></hr>" is,
i believe, always valid). html5 certainly accepts valid xhtml as input. 
It would entirely break e.g, nxml-mode or xsl post-processing to make 
this change.

Other things that don't need to be removed for html5:

    - CDATA escapes
    - xmns: .. xml:lang declarations (as long as you keep the html valid 
xml)


As a positive side effect, backing out these changes would simplify the 
patch a lot :)


The doctype (and fix to the text/javascript closing tag) changes look 
great.

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-19 15:37 ` Rick Frankel
@ 2013-04-20  2:59   ` Eric Abrahamsen
  2013-04-23  1:00     ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-20  2:59 UTC (permalink / raw)
  To: emacs-orgmode

Rick Frankel <rick@rickster.com> writes:

> On 19.04.2013 05:57, Eric Abrahamsen wrote:
>> I'm starting a new thread for this since the previous discussion was
>> buried in with something tangential.
>
>> I'm not proud of some of the implementation (self-closing vs
>> non-self-closing tags are ugly, and I wish org-html-html5-p and
>> org-html-xhtml-p were variables, not functions), but there it is, it
>> seems to work.
>>
>> If this is deemed okay I'll send a version of the patch with a proper
>> commit message, and also updated documentation.

Thanks for looking at this!

> I disagree with the minimized closing patch change.
>
> All versions of html accept the " />" idiom (with the extra space so
> that html4 only browsers
> don't break) for minimized tags (also "></{elem}", e.g. "<hr></hr>" is,
> i believe, always valid). html5 certainly accepts valid xhtml as
> input. It would entirely break e.g, nxml-mode or xsl post-processing
> to make this change.

The " />" style doesn't validate for html4, that's what I was going on.
It certainly doesn't make my browser explode, but I wanted that little
green checkmark! If we can live with that, that's fine, or I can try to
come up with a less hacky way of handling closing tags -- a macro maybe.

> Other things that don't need to be removed for html5:
>
>    - CDATA escapes
>    - xmns: .. xml:lang declarations (as long as you keep the html
> valid xml)

I'd be happy to leave the CDATA escapes in there, since it really
doesn't seem to make any difference, and the implementation is ugly. I
think I'm erring on the side of pedantic correctness.

The xmns declaration, on the other hand, seems quite meaningless for
anything that isn't xhtml (even if it doesn't actually break), and it's
only a couple of lines of code to deal with, I'd rather keep that in
there...

Thanks again,
Eric

>
> As a positive side effect, backing out these changes would simplify
> the patch a lot :)
>
>
> The doctype (and fix to the text/javascript closing tag) changes look
> great.
>
> rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-20  2:59   ` Eric Abrahamsen
@ 2013-04-23  1:00     ` Rick Frankel
  2013-04-23  4:30       ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-04-23  1:00 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

On Sat, Apr 20, 2013 at 10:59:32AM +0800, Eric Abrahamsen wrote:
> 
> The " />" style doesn't validate for html4, that's what I was going on.
> It certainly doesn't make my browser explode, but I wanted that little
> green checkmark! If we can live with that, that's fine, or I can try to
> come up with a less hacky way of handling closing tags -- a macro
> maybe.

It should validate. According to the w3c compatibility guidelines
(http://www.w3.org/TR/xhtml1/guidelines.html):

C.2. Empty Elements

Include a space before the trailing / and > of empty elements,
e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. 
Also, use the minimized tag syntax for empty elements, e.g. <br />, 
as the alternative syntax <br></br> allowed by XML gives uncertain 
results in many existing user agents.

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY
(for example, an empty title or paragraph) do not use the minimized 
form (e.g. use <p> </p> and not <p />).

> 
> The xmns declaration, on the other hand, seems quite meaningless for
> anything that isn't xhtml (even if it doesn't actually break), and it's
> only a couple of lines of code to deal with, I'd rather keep that in
> there...

fair enough.

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23  1:00     ` Rick Frankel
@ 2013-04-23  4:30       ` Eric Abrahamsen
  2013-04-23  4:57         ` Samuel Wales
  2013-04-23 12:09         ` François Pinard
  0 siblings, 2 replies; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-23  4:30 UTC (permalink / raw)
  To: emacs-orgmode

Rick Frankel <rick@rickster.com> writes:

> On Sat, Apr 20, 2013 at 10:59:32AM +0800, Eric Abrahamsen wrote:
>> 
>> The " />" style doesn't validate for html4, that's what I was going on.
>> It certainly doesn't make my browser explode, but I wanted that little
>> green checkmark! If we can live with that, that's fine, or I can try to
>> come up with a less hacky way of handling closing tags -- a macro
>> maybe.
>
> It should validate. According to the w3c compatibility guidelines
> (http://www.w3.org/TR/xhtml1/guidelines.html):
>
> C.2. Empty Elements
>
> Include a space before the trailing / and > of empty elements,
> e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. 
> Also, use the minimized tag syntax for empty elements, e.g. <br />, 
> as the alternative syntax <br></br> allowed by XML gives uncertain 
> results in many existing user agents.
>
> C.3. Element Minimization and Empty Element Content
>
> Given an empty instance of an element whose content model is not EMPTY
> (for example, an empty title or paragraph) do not use the minimized 
> form (e.g. use <p> </p> and not <p />).

Right, but as the note at the top of that page says:

"This appendix summarizes design guidelines for authors who wish their
XHTML documents to render on existing HTML user agents."

I read that as just a better statement of what I was trying to say
earlier: self-closing tags will render in HTML4, but they're not
_strictly correct_ HTML4.

Try the validation link at the bottom of this page:

http://ericabrahamsen.net/html4test.html

It's not a disaster.

I'm happy to do whatever needs to be done with the patch, whether that
means dropping the closing-tags fix, re-implementing it, or whatever. It
would be good to hear other HTML-users' opinions on this, if anyone has
one!

E

>> The xmns declaration, on the other hand, seems quite meaningless for
>> anything that isn't xhtml (even if it doesn't actually break), and it's
>> only a couple of lines of code to deal with, I'd rather keep that in
>> there...
>
> fair enough.
>
> rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23  4:30       ` Eric Abrahamsen
@ 2013-04-23  4:57         ` Samuel Wales
  2013-04-23  6:55           ` Carsten Dominik
  2013-04-23 12:09         ` François Pinard
  1 sibling, 1 reply; 28+ messages in thread
From: Samuel Wales @ 2013-04-23  4:57 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

As a non-expert HTML user, I'd want whatever works on the most
browsers, even old ones, as my audience is likely to include many who
have old browsers in addition to many who have new ones, mobile ones,
and accessibility-oriented browsers and extensions.

Dunno if that helps at all.

Samuel

-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

The disease DOES progress.  MANY people have died from it.  ANYBODY
can get it.  There is NO hope without action.  This means YOU.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23  4:57         ` Samuel Wales
@ 2013-04-23  6:55           ` Carsten Dominik
  2013-04-23  7:54             ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Carsten Dominik @ 2013-04-23  6:55 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Eric Abrahamsen, emacs-orgmode


On 23.4.2013, at 06:57, Samuel Wales <samologist@gmail.com> wrote:

> As a non-expert HTML user, I'd want whatever works on the most
> browsers, even old ones, as my audience is likely to include many who
> have old browsers in addition to many who have new ones, mobile ones,
> and accessibility-oriented browsers and extensions.
> 
> Dunno if that helps at all.


This is a valid point.  While I do not object to a way to select
an html flavor, the default should render correctly on as many
browsers as possible.

- Carsten

> 
> Samuel
> 
> -- 
> The Kafka Pandemic: http://thekafkapandemic.blogspot.com
> 
> The disease DOES progress.  MANY people have died from it.  ANYBODY
> can get it.  There is NO hope without action.  This means YOU.
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23  6:55           ` Carsten Dominik
@ 2013-04-23  7:54             ` Eric Abrahamsen
  0 siblings, 0 replies; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-23  7:54 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Carsten Dominik

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On 23.4.2013, at 06:57, Samuel Wales <samologist@gmail.com> wrote:
>
>> As a non-expert HTML user, I'd want whatever works on the most
>> browsers, even old ones, as my audience is likely to include many who
>> have old browsers in addition to many who have new ones, mobile ones,
>> and accessibility-oriented browsers and extensions.
>> 
>> Dunno if that helps at all.
>
>
> This is a valid point.  While I do not object to a way to select
> an html flavor, the default should render correctly on as many
> browsers as possible.
>
> - Carsten

Yup, absolutely. Inasmuch as anything is certain with HTML, it seems
fairly clear that self-closing tags will /render/ properly in HTML4,
even if they don't validate, so maybe it doesn't matter.

I'll have a think and see if I can't come up with a less hideous way of
handling the tags. If I can't, maybe we can just leave it.

E

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23  4:30       ` Eric Abrahamsen
  2013-04-23  4:57         ` Samuel Wales
@ 2013-04-23 12:09         ` François Pinard
  2013-04-24  1:17           ` Christian Wittern
  1 sibling, 1 reply; 28+ messages in thread
From: François Pinard @ 2013-04-23 12:09 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> I read that as just a better statement of what I was trying to say
> earlier: self-closing tags will render in HTML4, but they're not
> _strictly correct_ HTML4.

I do not understand this assertion.  I thought that HTML, up to but
excluding HTML5, *is* also valid SGML.  If I remember well, self-closing
tags date back to SGML, not requiring (but also not forbidding) an
introducing space to the closing slash.  SGML does allow for closing
tags to be optionally omitted (and for opening tags as well) but such
optional omissions have to described in the DTD.

These features were all meant to favor human legibility of SGML
documents, and HTML did use them a lot.  These, combined with the
generality of the described grammar, made generic SGML validating
parsers quite difficult to write, and also, quite expensive at the time
(no real problem as most SGML projects usually involved big money).  XML
was all of a swing in the other direction: trading human legibility in
favor of much easier parsing, and was quite successful as it addressed
the same problems as SGML, but in a much cheaper and democratic way.

But XML (and XHTML) are not SGML anymore.  And HTML5 is neither :-).

François

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-23 12:09         ` François Pinard
@ 2013-04-24  1:17           ` Christian Wittern
  2013-04-24 13:10             ` François Pinard
  0 siblings, 1 reply; 28+ messages in thread
From: Christian Wittern @ 2013-04-24  1:17 UTC (permalink / raw)
  To: emacs-orgmode

On 2013-04-23 21:09, François Pinard wrote:
> If I remember well, self-closing
> tags date back to SGML, not requiring (but also not forbidding) an
> introducing space to the closing slash.  SGML does allow for closing
> tags to be optionally omitted (and for opening tags as well) but such
> optional omissions have to described in the DTD.
Well, in this case you are misremembering, empty elements, aka as 
self-closing tags are one of the innovations of XML; they did not exist in 
SGML (where you could simple omit the closing tag completely for emtpy 
elements).

Just my nit to pick,

Christian

-- 
Christian Wittern, Kyoto

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-24  1:17           ` Christian Wittern
@ 2013-04-24 13:10             ` François Pinard
  2013-04-25 21:20               ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: François Pinard @ 2013-04-24 13:10 UTC (permalink / raw)
  To: emacs-orgmode

Christian Wittern <cwittern@gmail.com> writes:

> On 2013-04-23 21:09, François Pinard wrote:

>> If I remember well [...]

> Well, in this case you are misremembering, empty elements, aka as
> self-closing tags are one of the innovations of XML.  Just my nit to pick,

A friendly nit-picking is always a good way to get one another to
improve.  Thanks!

François

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-24 13:10             ` François Pinard
@ 2013-04-25 21:20               ` Eric Abrahamsen
  2013-04-26 13:49                 ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-25 21:20 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

François Pinard <pinard@iro.umontreal.ca> writes:

> Christian Wittern <cwittern@gmail.com> writes:
>
>> On 2013-04-23 21:09, François Pinard wrote:
>
>>> If I remember well [...]
>
>> Well, in this case you are misremembering, empty elements, aka as
>> self-closing tags are one of the innovations of XML.  Just my nit to pick,
>
> A friendly nit-picking is always a good way to get one another to
> improve.  Thanks!

Who knew this would turn out to be such a fraught issue! All I wanted
was that little green checkmark from the W3C...

Here's what I think should be an acceptable final patch. I dropped the
CDATA mess, and came up with a slightly different implementation for
handling self-closing tags. It's maybe a little /bulkier/ than the
previous implementation, but not so hacky, and may continue to be useful
in the future. There's also a documentation patch.

Hope this works,
E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0011-ox-html.el-Export-to-various-flavors-of-X-HTML.patch --]
[-- Type: text/x-patch, Size: 21008 bytes --]

From d3af8f41480eea27e0165e4dcd594ce3475e56cd Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Thu, 25 Apr 2013 14:00:24 -0700
Subject: [PATCH 11/11] ox-html.el: Export to various flavors of (X)HTML

lisp/ox-html.el
(org-html-doctype-alist): New variable holding an alist of (X)HTML
			 doctypes

(org-html-xhtml-p): New function
(org-html-html5-p): New function
(org-html-close-tag): New function

Significant changes to `org-html-format-inline-image',
`org-html--build-meta-info', `org-html--build-head',
`org-html--build-pre/postable', `org-html-template',
`org-html-horizontal-rule', `org-html-format-list-item',
`org-html-line-break', `org-html-table', and `org-html-verse-block'.

doc/org.texi: Document the above
---
 doc/org.texi    |  41 ++++++++++++-
 lisp/ox-html.el | 187 +++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 163 insertions(+), 65 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 3f2d1b8..c7fae6d 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -596,6 +596,7 @@ Exporting
 HTML export
 
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10959,6 +10960,7 @@ language, but with additional support for tables.
 
 @menu
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10970,7 +10972,7 @@ language, but with additional support for tables.
 * JavaScript support::          Info and Folding in a web browser
 @end menu
 
-@node HTML Export commands, HTML preamble and postamble, HTML export, HTML export
+@node HTML Export commands, HTML doctypes, HTML export, HTML export
 @subsection HTML export commands
 
 @table @kbd
@@ -10998,7 +11000,42 @@ Export to a temporary buffer.  Do not create a file.
 @c @noindent
 @c creates two levels of headings and does the rest as items.
 
-@node HTML preamble and postamble, Quoting HTML tags, HTML Export commands, HTML export
+@node HTML doctypes, HTML preamble and postamble, HTML Export commands, HTML export
+@subsection HTML doctypes
+@vindex org-html-doctype
+@vindex org-html-doctype-alist
+
+Org can export to various (X)HTML flavors.
+
+Setting the variable @var{org-html-doctype} allows you to export to different
+(X)HTML variants. The exported HTML will be adjusted according to the sytax
+requirements of that variant. You can either set this variable to a doctype
+string directly, in which case the exporter will try to adjust the syntax
+automatically, or you can use a ready-made doctype. The ready-made options
+are:
+
+@itemize
+@item
+``html4-strict''
+@item
+``html4-transitional''
+@item
+``html4-frameset''
+@item
+``xhtml-strict''
+@item
+``xhtml-transitional''
+@item
+``xhtml-frameset''
+@item
+``xhtml-11''
+@item
+``html5''
+@end itemize
+
+See the variable @var{org-html-doctype-alist} for details. The default is ``xhtml-strict''.
+
+@node HTML preamble and postamble, Quoting HTML tags, HTML doctypes, HTML export
 @subsection HTML preamble and postamble
 @vindex org-html-preamble
 @vindex org-html-postamble
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index ef7d15a..eddc122 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -143,6 +143,26 @@
 (defvar org-html--pre/postamble-class "status"
   "CSS class used for pre/postamble")
 
+(defconst org-html-doctype-alist
+  '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
+\"http://www.w3.org/TR/html4/strict.dtd\">")
+    ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+\"http://www.w3.org/TR/html4/loose.dtd\">")
+    ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
+\"http://www.w3.org/TR/html4/frameset.dtd\">")
+
+    ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
+    ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
+    ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
+    ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
+
+    ("html5" . "<!DOCTYPE html>"))
+  "An alist mapping (x)html flavors to specific doctypes.")
+
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
@@ -748,7 +768,9 @@ in all modes you want.  Then, use the command
   '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
   "Default attributes and values which will be used in table tags.
 This is a plist where attributes are symbols, starting with
-colons, and values are strings."
+colons, and values are strings.
+
+When exporting to HTML5, these values will be disregarded."
   :group 'org-export-html
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -856,7 +878,9 @@ CSS classes, then this prefix can be very useful."
   "The extension for exported HTML files.
 %s will be replaced with the charset of the exported file.
 This may be a string, or an alist with export extensions
-and corresponding declarations."
+and corresponding declarations.
+
+This declaration only applies when exporting to XHTML."
   :group 'org-export-html
   :type '(choice
 	  (string :tag "Single declaration")
@@ -872,8 +896,7 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :type 'coding-system)
 
-(defcustom org-html-doctype
-  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
+(defcustom org-html-doctype "xhtml-strict"
   "Document type definition to use for exported HTML files.
 Can be set with the in-buffer HTML_DOCTYPE property or for
 publishing, with :html-doctype."
@@ -962,7 +985,8 @@ You can also customize this for each buffer, using something like
 		    (const :format "       " mathml) (boolean))))
 
 (defcustom org-html-mathjax-template
-  "<script type=\"text/javascript\" src=\"%PATH\">
+  "<script type=\"text/javascript\" src=\"%PATH\"></script>
+<script type=\"text/javascript\">
 <!--/*--><![CDATA[/*><!--*/
     MathJax.Hub.Config({
         // Only one of the two following lines, depending on user settings
@@ -1035,7 +1059,7 @@ precedence over this variable."
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"creator\">%c</p>
-<p class=\"xhtml-validation\">%v</p>"))
+<p class=\"validation\">%v</p>"))
   "Alist of languages and format strings for the HTML postamble.
 
 The first element of each list is the language code, as used for
@@ -1060,7 +1084,7 @@ like that: \"%%\"."
 		:value-type (string :tag "Format string")))
 
 (defcustom org-html-validation-link
-  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
+  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
   "Link to HTML validation service."
   :group 'org-export-html
   :type 'string)
@@ -1240,6 +1264,18 @@ CSS classes, then this prefix can be very useful."
 \f
 ;;; Internal Functions
 
+(defun org-html-xhtml-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+    (string-match-p "xhtml" dt)))
+
+(defun org-html-html5-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+	(member dt '("html5" "<!doctype html>"))))
+
+(defun org-html-close-tag (tag attr info)
+  (concat "<" tag (or attr "")
+	  (if (org-html-xhtml-p info) " />" ">")))
+
 (defun org-html--make-attribute-string (attributes)
   "Return a list of attributes, as a string.
 ATTRIBUTES is a plist where values are either strings or nil. An
@@ -1253,7 +1289,7 @@ attributes with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
-(defun org-html-format-inline-image (src &optional
+(defun org-html-format-inline-image (src info &optional
 					 caption label attr standalone-p)
   "Format an inline image from SRC.
 CAPTION, LABEL and ATTR are optional arguments providing the
@@ -1262,6 +1298,7 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
   (let* ((id (if (not label) ""
 	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
 	 (attr (concat attr
+		       (format " src=\"%s\"" src)
 		       (cond
 			((string-match "\\<alt=" (or attr "")) "")
 			((string-match "^ltxpng/" src)
@@ -1273,12 +1310,12 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
 				   (file-name-nondirectory src)))))))
     (cond
      (standalone-p
-      (let ((img (format "<img src=\"%s\" %s/>" src attr)))
+      (let ((img (org-html-close-tag "img" attr info)))
 	(format "\n<div%s class=\"figure\">%s%s\n</div>"
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
 		    (format "\n<p>%s</p>" caption) ""))))
-     (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
+     (t (org-html-close-tag "img" (concat attr id) info)))))
 
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
@@ -1437,7 +1474,11 @@ INFO is a plist used as a communication channel."
 				 (cons 'plain-text org-element-all-objects)
 			       'identity info))))))
 	(description (plist-get info :description))
-	(keywords (plist-get info :keywords)))
+	(keywords (plist-get info :keywords))
+	(charset (or (and org-html-coding-system
+			  (fboundp 'coding-system-get)
+			  (coding-system-get org-html-coding-system 'mime-charset))
+		     "iso-8859-1")))
     (concat
      (format "<title>%s</title>\n" title)
      (format
@@ -1445,21 +1486,24 @@ INFO is a plist used as a communication channel."
 	(format-time-string
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
      (format
-      "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
-      (or (and org-html-coding-system
-	       (fboundp 'coding-system-get)
-	       (coding-system-get org-html-coding-system 'mime-charset))
-	  "iso-8859-1"))
-     (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
+      (if (org-html-html5-p info)
+	  "<meta charset=\"%s\">\n"
+	(org-html-close-tag
+	 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" info))
+      charset) "\n"
+     (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info) "\n"
      (and (org-string-nw-p author)
-	  (format "<meta name=\"author\" content=\"%s\"/>\n"
-		  (funcall protect-string author)))
+	  (org-html-close-tag "meta" (format " name=\"author\" content=\"%s\""
+					     (funcall protect-string author)) info)
+	  "\n")
      (and (org-string-nw-p description)
-	  (format "<meta name=\"description\" content=\"%s\"/>\n"
-		  (funcall protect-string description)))
+	  (org-html-close-tag "meta" (format " name=\"description\" content=\"%s\"%s\n"
+					     (funcall protect-string description)) info)
+	  "\n")
      (and (org-string-nw-p keywords)
-	  (format "<meta name=\"keywords\" content=\"%s\"/>\n"
-		  (funcall protect-string keywords))))))
+	  (org-html-close-tag "meta" (format " name=\"keywords\" content=\"%s\""
+					     (funcall protect-string keywords)) info)
+	  "\n"))))
 
 (defun org-html--build-head (info)
   "Return information for the <head>..</head> of the HTML output.
@@ -1472,8 +1516,10 @@ INFO is a plist used as a communication channel."
     (org-element-normalize-string (plist-get info :html-head-extra))
     (when (and (plist-get info :html-htmlized-css-url)
 	       (eq org-html-htmlize-output-type 'css))
-      (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
-	      (plist-get info :html-htmlized-css-url)))
+      (org-html-close-tag "link"
+			  (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
+				  (plist-get info :html-htmlized-css-url))
+			  info))
     (when (plist-get info :html-head-include-scripts) org-html-scripts))))
 
 (defun org-html--build-mathjax-config (info)
@@ -1570,7 +1616,7 @@ communication channel."
 		       (format-time-string org-html-metadata-timestamp-format)))
 		    (when (plist-get info :with-creator)
 		      (format "<p class=\"creator\">%s</p>\n" creator))
-		    (format "<p class=\"xhtml-validation\">%s</p>\n"
+		    (format "<p class=\"validation\">%s</p>\n"
 			    validation-link))))
 		(t (format-spec
 		    (or (cadr (assoc
@@ -1612,23 +1658,31 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
   (concat
-   (format
-    (or (and (stringp org-html-xml-declaration)
-	     org-html-xml-declaration)
-	(cdr (assoc (plist-get info :html-extension)
-		    org-html-xml-declaration))
-	(cdr (assoc "html" org-html-xml-declaration))
-
-	"")
-    (or (and org-html-coding-system
-	     (fboundp 'coding-system-get)
-	     (coding-system-get org-html-coding-system 'mime-charset))
-	"iso-8859-1"))
-   "\n"
-   (plist-get info :html-doctype)
+   (when (org-html-xhtml-p info)
+     (format "%s\n"
+	     (format (or (and (stringp org-html-xml-declaration)
+			      org-html-xml-declaration)
+			 (cdr (assoc (plist-get info :html-extension)
+				     org-html-xml-declaration))
+			 (cdr (assoc "html" org-html-xml-declaration))
+
+			 "")
+		     (or (and org-html-coding-system
+			      (fboundp 'coding-system-get)
+			      (coding-system-get org-html-coding-system 'mime-charset))
+			 "iso-8859-1"))))
+   (let* ((dt (plist-get info :html-doctype))
+	  (dt-cons (assoc dt org-html-doctype-alist)))
+     (if dt-cons
+	 (cdr dt-cons)
+       dt))
    "\n"
-   (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
-	   (plist-get info :language) (plist-get info :language))
+   (concat "<html"
+	   (when (org-html-xhtml-p info)
+	     (format
+	      " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
+	      (plist-get info :language) (plist-get info :language)))
+	   ">\n")
    "<head>\n"
    (org-html--build-meta-info info)
    (org-html--build-head info)
@@ -2179,7 +2233,7 @@ holding contextual information."
       ;; Build the real contents of the sub-tree.
       (let* ((type (if numberedp 'ordered 'unordered))
 	     (itemized-body (org-html-format-list-item
-			     contents type nil nil full-text)))
+			     contents type nil info nil full-text)))
 	(concat
 	 (and (org-export-first-sibling-p headline info)
 	      (org-html-begin-plain-list type))
@@ -2239,7 +2293,7 @@ holding contextual information."
 (defun org-html-horizontal-rule (horizontal-rule contents info)
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<hr/>")
+  (org-html-close-tag "hr" nil info))
 
 ;;;; Inline Src Block
 
@@ -2275,8 +2329,9 @@ holding contextual information."
       (org-html-format-headline--wrap
        inlinetask info format-function :contents contents)))
    ;; Otherwise, use a default template.
-   (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
+   (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
 	      (org-html-format-headline--wrap inlinetask info)
+	      (org-html-close-tag "br" nil info)
 	      contents))))
 
 ;;;; Italic
@@ -2296,11 +2351,12 @@ contextual information."
 	(trans "<code>[-]</code>")
 	(t "")))
 
-(defun org-html-format-list-item (contents type checkbox
+(defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     headline)
   "Format a list item into HTML."
-  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
+  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
+	(br (org-html-close-tag "br" nil info)))
     (concat
      (case type
        (ordered
@@ -2308,13 +2364,13 @@ contextual information."
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (unordered
 	(let* ((id term-counter-id)
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (descriptive
 	(let* ((term term-counter-id))
 	  (setq term (or term "(no term)"))
@@ -2340,7 +2396,7 @@ contextual information."
 	 (tag (let ((tag (org-element-property :tag item)))
 		(and tag (org-export-data tag info)))))
     (org-html-format-list-item
-     contents type checkbox (or tag counter))))
+     contents type checkbox info (or tag counter))))
 
 ;;;; Keyword
 
@@ -2399,7 +2455,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(when (and formula-link
 		   (string-match "file:\\([^]]*\\)" formula-link))
 	  (org-html-format-inline-image
-	   (match-string 1 formula-link) caption label attr t))))
+	   (match-string 1 formula-link) info caption label attr t))))
      (t latex-frag))))
 
 ;;;; Latex Fragment
@@ -2418,7 +2474,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 (when (and formula-link
 		    (string-match "file:\\([^]]*\\)" formula-link))
 	   (org-html-format-inline-image
-	    (match-string 1 formula-link)))))
+	    (match-string 1 formula-link) info))))
       (t latex-frag))))
 
 ;;;; Line Break
@@ -2426,7 +2482,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<br/>\n")
+  (concat (org-html-close-tag "br" nil info) "\n"))
 
 ;;;; Link
 
@@ -2451,7 +2507,7 @@ Inline images can have these attributes:
 	 (label (org-element-property :name parent)))
     ;; Return proper string, depending on DISPOSITION.
     (org-html-format-inline-image
-     path caption label
+     path info caption label
      (org-html--make-attribute-string
       (org-export-read-attribute :attr_html parent))
      (org-html-standalone-image-p link info))))
@@ -2769,7 +2825,8 @@ contextual information."
     (when (plist-get info :preserve-breaks)
       (setq output
 	    (replace-regexp-in-string
-	     "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
+	     "\\(\\\\\\\\\\)?[ \t]*\n"
+	     (concat (org-html-close-tag "br" nil info) "\n") output)))
     ;; Return value.
     output))
 
@@ -3044,11 +3101,12 @@ contextual information."
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (attributes
-	     (org-html--make-attribute-string
-	      (org-combine-plists
-	       (and label (list :id (org-export-solidify-link-text label)))
-	       (plist-get info :html-table-attributes)
-	       (org-export-read-attribute :attr_html table))))
+	     (if (org-html-html5-p info) ""
+	       (org-html--make-attribute-string
+		(org-combine-plists
+		 (and label (list :id (org-export-solidify-link-text label)))
+		 (plist-get info :html-table-attributes)
+		 (org-export-read-attribute :attr_html table)))))
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3066,7 +3124,9 @@ contextual information."
 			     table-cell info)
 			"\n<colgroup>")
 		      ;; Add a column.  Also specify it's alignment.
-		      (format "\n<col %s/>" (format alignspec alignment))
+		      (format "\n%s"
+			      (org-html-close-tag
+			       "col" (concat " " (format alignspec alignment)) info))
 		      ;; End a colgroup?
 		      (when (org-export-table-cell-ends-colgroup-p
 			     table-cell info)
@@ -3128,9 +3188,10 @@ contextual information."
   ;; Replace each newline character with line break.  Also replace
   ;; each blank line with a line break.
   (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" "<br/>\n"
+		  "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
 		  (replace-regexp-in-string
-		   "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
+		   "\\(\\\\\\\\\\)?[ \t]*\n"
+		   (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
   ;; Replace each white space at beginning of a line with a
   ;; non-breaking space.
   (while (string-match "^[ \t]+" contents)
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-25 21:20               ` Eric Abrahamsen
@ 2013-04-26 13:49                 ` Rick Frankel
  2013-04-26 17:14                   ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-04-26 13:49 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: eric

On 25.04.2013 17:20, Eric Abrahamsen wrote:
> Who knew this would turn out to be such a fraught issue! All I wanted
> was that little green checkmark from the W3C...
>
> Here's what I think should be an acceptable final patch. I dropped 
> the
> CDATA mess, and came up with a slightly different implementation for
> handling self-closing tags. It's maybe a little /bulkier/ than the
> previous implementation, but not so hacky, and may continue to be 
> useful
> in the future. There's also a documentation patch.

Overall, looks good, but again, i would _strongly_ argue that html5 
should generate valid xhtml.
If it doesn't, it will really break my post-processing workflow...

Therefore, `org-html-close-tag' should check that the doctype is not a 
flavor of html4 rather than a flavor of xhtml. An alternative would be 
to add ("xhtml5" . "<!DOCTYPE html>") to the doctype alist, and the 
appropriate testing for being html5 and xhtml.

See the discussions of polyglot markup @ 
http://en.wikipedia.org/wiki/Polyglot_markup
and 
http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#dfn-polyglot-markup 
for the rationale.

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-26 13:49                 ` Rick Frankel
@ 2013-04-26 17:14                   ` Eric Abrahamsen
  2013-04-26 18:49                     ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-26 17:14 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1534 bytes --]

Rick Frankel <rick@rickster.com> writes:

> On 25.04.2013 17:20, Eric Abrahamsen wrote:
>> Who knew this would turn out to be such a fraught issue! All I wanted
>> was that little green checkmark from the W3C...
>>
>> Here's what I think should be an acceptable final patch. I dropped
>> the
>> CDATA mess, and came up with a slightly different implementation for
>> handling self-closing tags. It's maybe a little /bulkier/ than the
>> previous implementation, but not so hacky, and may continue to be
>> useful
>> in the future. There's also a documentation patch.
>
> Overall, looks good, but again, i would _strongly_ argue that html5
> should generate valid xhtml.
> If it doesn't, it will really break my post-processing workflow...
>
> Therefore, `org-html-close-tag' should check that the doctype is not a
> flavor of html4 rather than a flavor of xhtml. An alternative would be
> to add ("xhtml5" . "<!DOCTYPE html>") to the doctype alist, and the
> appropriate testing for being html5 and xhtml.
>
> See the discussions of polyglot markup @
> http://en.wikipedia.org/wiki/Polyglot_markup
> and
> http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#dfn-polyglot-markup
> for the rationale.

Ah, those were interesting links, I hadn't considered those issues.
Luckily, your second option was a three-line change to the existing
patch: using "xhtml5" now produces the same output as "html5", except
that self-closing tags are self-closed, and there's a xmlns declaration
in the <html> element. Best of all worlds, I hope.

E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0011-ox-html.el-Export-to-various-flavors-of-X-HTML.patch --]
[-- Type: text/x-patch, Size: 21097 bytes --]

From 12472f7fe52848a011cc218e36b01416cfa6c146 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Fri, 26 Apr 2013 10:04:47 -0700
Subject: [PATCH 11/11] ox-html.el: Export to various flavors of (X)HTML

lisp/ox-html.el
(org-html-doctype-alist): New variable holding an alist of (X)HTML
			 doctypes

(org-html-xhtml-p): New function
(org-html-html5-p): New function
(org-html-close-tag): New function

Significant changes to `org-html-format-inline-image',
`org-html--build-meta-info', `org-html--build-head',
`org-html--build-pre/postable', `org-html-template',
`org-html-horizontal-rule', `org-html-format-list-item',
`org-html-line-break', `org-html-table', and `org-html-verse-block'.

doc/org.texi: Document the above
---
 doc/org.texi    |  43 ++++++++++++-
 lisp/ox-html.el | 188 +++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 166 insertions(+), 65 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 3f2d1b8..0815c49 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -596,6 +596,7 @@ Exporting
 HTML export
 
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10959,6 +10960,7 @@ language, but with additional support for tables.
 
 @menu
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10970,7 +10972,7 @@ language, but with additional support for tables.
 * JavaScript support::          Info and Folding in a web browser
 @end menu
 
-@node HTML Export commands, HTML preamble and postamble, HTML export, HTML export
+@node HTML Export commands, HTML doctypes, HTML export, HTML export
 @subsection HTML export commands
 
 @table @kbd
@@ -10998,7 +11000,44 @@ Export to a temporary buffer.  Do not create a file.
 @c @noindent
 @c creates two levels of headings and does the rest as items.
 
-@node HTML preamble and postamble, Quoting HTML tags, HTML Export commands, HTML export
+@node HTML doctypes, HTML preamble and postamble, HTML Export commands, HTML export
+@subsection HTML doctypes
+@vindex org-html-doctype
+@vindex org-html-doctype-alist
+
+Org can export to various (X)HTML flavors.
+
+Setting the variable @var{org-html-doctype} allows you to export to different
+(X)HTML variants. The exported HTML will be adjusted according to the sytax
+requirements of that variant. You can either set this variable to a doctype
+string directly, in which case the exporter will try to adjust the syntax
+automatically, or you can use a ready-made doctype. The ready-made options
+are:
+
+@itemize
+@item
+``html4-strict''
+@item
+``html4-transitional''
+@item
+``html4-frameset''
+@item
+``xhtml-strict''
+@item
+``xhtml-transitional''
+@item
+``xhtml-frameset''
+@item
+``xhtml-11''
+@item
+``html5''
+@item
+``xhtml5''
+@end itemize
+
+See the variable @var{org-html-doctype-alist} for details. The default is ``xhtml-strict''.
+
+@node HTML preamble and postamble, Quoting HTML tags, HTML doctypes, HTML export
 @subsection HTML preamble and postamble
 @vindex org-html-preamble
 @vindex org-html-postamble
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index ef7d15a..8223a18 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -143,6 +143,27 @@
 (defvar org-html--pre/postamble-class "status"
   "CSS class used for pre/postamble")
 
+(defconst org-html-doctype-alist
+  '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
+\"http://www.w3.org/TR/html4/strict.dtd\">")
+    ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+\"http://www.w3.org/TR/html4/loose.dtd\">")
+    ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
+\"http://www.w3.org/TR/html4/frameset.dtd\">")
+
+    ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
+    ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
+    ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
+    ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
+
+    ("html5" . "<!DOCTYPE html>")
+    ("xhtml5" . "<!DOCTYPE html>"))
+  "An alist mapping (x)html flavors to specific doctypes.")
+
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
@@ -748,7 +769,9 @@ in all modes you want.  Then, use the command
   '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
   "Default attributes and values which will be used in table tags.
 This is a plist where attributes are symbols, starting with
-colons, and values are strings."
+colons, and values are strings.
+
+When exporting to HTML5, these values will be disregarded."
   :group 'org-export-html
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -856,7 +879,9 @@ CSS classes, then this prefix can be very useful."
   "The extension for exported HTML files.
 %s will be replaced with the charset of the exported file.
 This may be a string, or an alist with export extensions
-and corresponding declarations."
+and corresponding declarations.
+
+This declaration only applies when exporting to XHTML."
   :group 'org-export-html
   :type '(choice
 	  (string :tag "Single declaration")
@@ -872,8 +897,7 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :type 'coding-system)
 
-(defcustom org-html-doctype
-  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
+(defcustom org-html-doctype "xhtml-strict"
   "Document type definition to use for exported HTML files.
 Can be set with the in-buffer HTML_DOCTYPE property or for
 publishing, with :html-doctype."
@@ -962,7 +986,8 @@ You can also customize this for each buffer, using something like
 		    (const :format "       " mathml) (boolean))))
 
 (defcustom org-html-mathjax-template
-  "<script type=\"text/javascript\" src=\"%PATH\">
+  "<script type=\"text/javascript\" src=\"%PATH\"></script>
+<script type=\"text/javascript\">
 <!--/*--><![CDATA[/*><!--*/
     MathJax.Hub.Config({
         // Only one of the two following lines, depending on user settings
@@ -1035,7 +1060,7 @@ precedence over this variable."
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"creator\">%c</p>
-<p class=\"xhtml-validation\">%v</p>"))
+<p class=\"validation\">%v</p>"))
   "Alist of languages and format strings for the HTML postamble.
 
 The first element of each list is the language code, as used for
@@ -1060,7 +1085,7 @@ like that: \"%%\"."
 		:value-type (string :tag "Format string")))
 
 (defcustom org-html-validation-link
-  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
+  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
   "Link to HTML validation service."
   :group 'org-export-html
   :type 'string)
@@ -1240,6 +1265,18 @@ CSS classes, then this prefix can be very useful."
 \f
 ;;; Internal Functions
 
+(defun org-html-xhtml-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+    (string-match-p "xhtml" dt)))
+
+(defun org-html-html5-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+	(member dt '("html5" "xhtml5" "<!doctype html>"))))
+
+(defun org-html-close-tag (tag attr info)
+  (concat "<" tag (or attr "")
+	  (if (org-html-xhtml-p info) " />" ">")))
+
 (defun org-html--make-attribute-string (attributes)
   "Return a list of attributes, as a string.
 ATTRIBUTES is a plist where values are either strings or nil. An
@@ -1253,7 +1290,7 @@ attributes with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
-(defun org-html-format-inline-image (src &optional
+(defun org-html-format-inline-image (src info &optional
 					 caption label attr standalone-p)
   "Format an inline image from SRC.
 CAPTION, LABEL and ATTR are optional arguments providing the
@@ -1262,6 +1299,7 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
   (let* ((id (if (not label) ""
 	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
 	 (attr (concat attr
+		       (format " src=\"%s\"" src)
 		       (cond
 			((string-match "\\<alt=" (or attr "")) "")
 			((string-match "^ltxpng/" src)
@@ -1273,12 +1311,12 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
 				   (file-name-nondirectory src)))))))
     (cond
      (standalone-p
-      (let ((img (format "<img src=\"%s\" %s/>" src attr)))
+      (let ((img (org-html-close-tag "img" attr info)))
 	(format "\n<div%s class=\"figure\">%s%s\n</div>"
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
 		    (format "\n<p>%s</p>" caption) ""))))
-     (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
+     (t (org-html-close-tag "img" (concat attr id) info)))))
 
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
@@ -1437,7 +1475,11 @@ INFO is a plist used as a communication channel."
 				 (cons 'plain-text org-element-all-objects)
 			       'identity info))))))
 	(description (plist-get info :description))
-	(keywords (plist-get info :keywords)))
+	(keywords (plist-get info :keywords))
+	(charset (or (and org-html-coding-system
+			  (fboundp 'coding-system-get)
+			  (coding-system-get org-html-coding-system 'mime-charset))
+		     "iso-8859-1")))
     (concat
      (format "<title>%s</title>\n" title)
      (format
@@ -1445,21 +1487,24 @@ INFO is a plist used as a communication channel."
 	(format-time-string
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
      (format
-      "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
-      (or (and org-html-coding-system
-	       (fboundp 'coding-system-get)
-	       (coding-system-get org-html-coding-system 'mime-charset))
-	  "iso-8859-1"))
-     (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
+      (if (org-html-html5-p info)
+	  (org-html-close-tag "meta" " charset=\"%s\"" info)
+	(org-html-close-tag
+	 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" info))
+      charset) "\n"
+     (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info) "\n"
      (and (org-string-nw-p author)
-	  (format "<meta name=\"author\" content=\"%s\"/>\n"
-		  (funcall protect-string author)))
+	  (org-html-close-tag "meta" (format " name=\"author\" content=\"%s\""
+					     (funcall protect-string author)) info)
+	  "\n")
      (and (org-string-nw-p description)
-	  (format "<meta name=\"description\" content=\"%s\"/>\n"
-		  (funcall protect-string description)))
+	  (org-html-close-tag "meta" (format " name=\"description\" content=\"%s\"%s\n"
+					     (funcall protect-string description)) info)
+	  "\n")
      (and (org-string-nw-p keywords)
-	  (format "<meta name=\"keywords\" content=\"%s\"/>\n"
-		  (funcall protect-string keywords))))))
+	  (org-html-close-tag "meta" (format " name=\"keywords\" content=\"%s\""
+					     (funcall protect-string keywords)) info)
+	  "\n"))))
 
 (defun org-html--build-head (info)
   "Return information for the <head>..</head> of the HTML output.
@@ -1472,8 +1517,10 @@ INFO is a plist used as a communication channel."
     (org-element-normalize-string (plist-get info :html-head-extra))
     (when (and (plist-get info :html-htmlized-css-url)
 	       (eq org-html-htmlize-output-type 'css))
-      (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
-	      (plist-get info :html-htmlized-css-url)))
+      (org-html-close-tag "link"
+			  (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
+				  (plist-get info :html-htmlized-css-url))
+			  info))
     (when (plist-get info :html-head-include-scripts) org-html-scripts))))
 
 (defun org-html--build-mathjax-config (info)
@@ -1570,7 +1617,7 @@ communication channel."
 		       (format-time-string org-html-metadata-timestamp-format)))
 		    (when (plist-get info :with-creator)
 		      (format "<p class=\"creator\">%s</p>\n" creator))
-		    (format "<p class=\"xhtml-validation\">%s</p>\n"
+		    (format "<p class=\"validation\">%s</p>\n"
 			    validation-link))))
 		(t (format-spec
 		    (or (cadr (assoc
@@ -1612,23 +1659,31 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
   (concat
-   (format
-    (or (and (stringp org-html-xml-declaration)
-	     org-html-xml-declaration)
-	(cdr (assoc (plist-get info :html-extension)
-		    org-html-xml-declaration))
-	(cdr (assoc "html" org-html-xml-declaration))
-
-	"")
-    (or (and org-html-coding-system
-	     (fboundp 'coding-system-get)
-	     (coding-system-get org-html-coding-system 'mime-charset))
-	"iso-8859-1"))
-   "\n"
-   (plist-get info :html-doctype)
+   (when (org-html-xhtml-p info)
+     (format "%s\n"
+	     (format (or (and (stringp org-html-xml-declaration)
+			      org-html-xml-declaration)
+			 (cdr (assoc (plist-get info :html-extension)
+				     org-html-xml-declaration))
+			 (cdr (assoc "html" org-html-xml-declaration))
+
+			 "")
+		     (or (and org-html-coding-system
+			      (fboundp 'coding-system-get)
+			      (coding-system-get org-html-coding-system 'mime-charset))
+			 "iso-8859-1"))))
+   (let* ((dt (plist-get info :html-doctype))
+	  (dt-cons (assoc dt org-html-doctype-alist)))
+     (if dt-cons
+	 (cdr dt-cons)
+       dt))
    "\n"
-   (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
-	   (plist-get info :language) (plist-get info :language))
+   (concat "<html"
+	   (when (org-html-xhtml-p info)
+	     (format
+	      " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
+	      (plist-get info :language) (plist-get info :language)))
+	   ">\n")
    "<head>\n"
    (org-html--build-meta-info info)
    (org-html--build-head info)
@@ -2179,7 +2234,7 @@ holding contextual information."
       ;; Build the real contents of the sub-tree.
       (let* ((type (if numberedp 'ordered 'unordered))
 	     (itemized-body (org-html-format-list-item
-			     contents type nil nil full-text)))
+			     contents type nil info nil full-text)))
 	(concat
 	 (and (org-export-first-sibling-p headline info)
 	      (org-html-begin-plain-list type))
@@ -2239,7 +2294,7 @@ holding contextual information."
 (defun org-html-horizontal-rule (horizontal-rule contents info)
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<hr/>")
+  (org-html-close-tag "hr" nil info))
 
 ;;;; Inline Src Block
 
@@ -2275,8 +2330,9 @@ holding contextual information."
       (org-html-format-headline--wrap
        inlinetask info format-function :contents contents)))
    ;; Otherwise, use a default template.
-   (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
+   (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
 	      (org-html-format-headline--wrap inlinetask info)
+	      (org-html-close-tag "br" nil info)
 	      contents))))
 
 ;;;; Italic
@@ -2296,11 +2352,12 @@ contextual information."
 	(trans "<code>[-]</code>")
 	(t "")))
 
-(defun org-html-format-list-item (contents type checkbox
+(defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     headline)
   "Format a list item into HTML."
-  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
+  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
+	(br (org-html-close-tag "br" nil info)))
     (concat
      (case type
        (ordered
@@ -2308,13 +2365,13 @@ contextual information."
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (unordered
 	(let* ((id term-counter-id)
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (descriptive
 	(let* ((term term-counter-id))
 	  (setq term (or term "(no term)"))
@@ -2340,7 +2397,7 @@ contextual information."
 	 (tag (let ((tag (org-element-property :tag item)))
 		(and tag (org-export-data tag info)))))
     (org-html-format-list-item
-     contents type checkbox (or tag counter))))
+     contents type checkbox info (or tag counter))))
 
 ;;;; Keyword
 
@@ -2399,7 +2456,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(when (and formula-link
 		   (string-match "file:\\([^]]*\\)" formula-link))
 	  (org-html-format-inline-image
-	   (match-string 1 formula-link) caption label attr t))))
+	   (match-string 1 formula-link) info caption label attr t))))
      (t latex-frag))))
 
 ;;;; Latex Fragment
@@ -2418,7 +2475,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 (when (and formula-link
 		    (string-match "file:\\([^]]*\\)" formula-link))
 	   (org-html-format-inline-image
-	    (match-string 1 formula-link)))))
+	    (match-string 1 formula-link) info))))
       (t latex-frag))))
 
 ;;;; Line Break
@@ -2426,7 +2483,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<br/>\n")
+  (concat (org-html-close-tag "br" nil info) "\n"))
 
 ;;;; Link
 
@@ -2451,7 +2508,7 @@ Inline images can have these attributes:
 	 (label (org-element-property :name parent)))
     ;; Return proper string, depending on DISPOSITION.
     (org-html-format-inline-image
-     path caption label
+     path info caption label
      (org-html--make-attribute-string
       (org-export-read-attribute :attr_html parent))
      (org-html-standalone-image-p link info))))
@@ -2769,7 +2826,8 @@ contextual information."
     (when (plist-get info :preserve-breaks)
       (setq output
 	    (replace-regexp-in-string
-	     "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
+	     "\\(\\\\\\\\\\)?[ \t]*\n"
+	     (concat (org-html-close-tag "br" nil info) "\n") output)))
     ;; Return value.
     output))
 
@@ -3044,11 +3102,12 @@ contextual information."
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (attributes
-	     (org-html--make-attribute-string
-	      (org-combine-plists
-	       (and label (list :id (org-export-solidify-link-text label)))
-	       (plist-get info :html-table-attributes)
-	       (org-export-read-attribute :attr_html table))))
+	     (if (org-html-html5-p info) ""
+	       (org-html--make-attribute-string
+		(org-combine-plists
+		 (and label (list :id (org-export-solidify-link-text label)))
+		 (plist-get info :html-table-attributes)
+		 (org-export-read-attribute :attr_html table)))))
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3066,7 +3125,9 @@ contextual information."
 			     table-cell info)
 			"\n<colgroup>")
 		      ;; Add a column.  Also specify it's alignment.
-		      (format "\n<col %s/>" (format alignspec alignment))
+		      (format "\n%s"
+			      (org-html-close-tag
+			       "col" (concat " " (format alignspec alignment)) info))
 		      ;; End a colgroup?
 		      (when (org-export-table-cell-ends-colgroup-p
 			     table-cell info)
@@ -3128,9 +3189,10 @@ contextual information."
   ;; Replace each newline character with line break.  Also replace
   ;; each blank line with a line break.
   (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" "<br/>\n"
+		  "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
 		  (replace-regexp-in-string
-		   "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
+		   "\\(\\\\\\\\\\)?[ \t]*\n"
+		   (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
   ;; Replace each white space at beginning of a line with a
   ;; non-breaking space.
   (while (string-match "^[ \t]+" contents)
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-26 17:14                   ` Eric Abrahamsen
@ 2013-04-26 18:49                     ` Rick Frankel
  2013-04-29  6:02                       ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-04-26 18:49 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

On Fri, Apr 26, 2013 at 10:14:17AM -0700, Eric Abrahamsen wrote:
> Rick Frankel <rick@rickster.com> writes:
> >
> > Therefore, `org-html-close-tag' should check that the doctype is not a
> > flavor of html4 rather than a flavor of xhtml. An alternative would be
> > to add ("xhtml5" . "<!DOCTYPE html>") to the doctype alist, and the
> > appropriate testing for being html5 and xhtml.
> >
> > See the discussions of polyglot markup @
> > http://en.wikipedia.org/wiki/Polyglot_markup
> > and
> > http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#dfn-polyglot-markup
> > for the rationale.
> 
> Ah, those were interesting links, I hadn't considered those issues.
> Luckily, your second option was a three-line change to the existing
> patch: using "xhtml5" now produces the same output as "html5", except
> that self-closing tags are self-closed, and there's a xmlns declaration
> in the <html> element. Best of all worlds, I hope.

Brilliant! I will apply the patch and try it later this weekend...

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-26 18:49                     ` Rick Frankel
@ 2013-04-29  6:02                       ` Eric Abrahamsen
  2013-04-29  7:45                         ` Nicolas Goaziou
                                           ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Eric Abrahamsen @ 2013-04-29  6:02 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2978 bytes --]

Rick Frankel <rick@rickster.com> writes:

> On Fri, Apr 26, 2013 at 10:14:17AM -0700, Eric Abrahamsen wrote:
>> Rick Frankel <rick@rickster.com> writes:
>> >
>> > Therefore, `org-html-close-tag' should check that the doctype is not a
>> > flavor of html4 rather than a flavor of xhtml. An alternative would be
>> > to add ("xhtml5" . "<!DOCTYPE html>") to the doctype alist, and the
>> > appropriate testing for being html5 and xhtml.
>> >
>> > See the discussions of polyglot markup @
>> > http://en.wikipedia.org/wiki/Polyglot_markup
>> > and
>> > http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#dfn-polyglot-markup
>> > for the rationale.
>> 
>> Ah, those were interesting links, I hadn't considered those issues.
>> Luckily, your second option was a three-line change to the existing
>> patch: using "xhtml5" now produces the same output as "html5", except
>> that self-closing tags are self-closed, and there's a xmlns declaration
>> in the <html> element. Best of all worlds, I hope.
>
> Brilliant! I will apply the patch and try it later this weekend...

So here's the fun part -- using the new bits of HTML5. The attached
patch builds on the last one (and corrects a couple of documentation
formatting errors), and touches on the following:

1. There's a new export option, org-html-html5-fancy/HTML_HTML5_FANCY,
which defaults to 'nil, making most of the following opt-in only.

2. The meat of the change is in `org-html-special-block'. If it comes
across a special block #+BEGIN_FOO where "foo" is a member of
`org-html-html5-elements', it will format it as "<foo>" rather than
"<div class="foo">". So #+BEGIN_ASIDE will create an "<aside>" element.

Attributes are now parsed (this change applies to all HTML flavors), so
this:

#+ATTR_HTML :controls controls :width 350
#+BEGIN_VIDEO
#+HTML: <source src="movie.mp4" type="video/mp4">
#+END_VIDEO

becomes:

<video controls="controls" width="350">
  <source src="movie.mp4" type="video/mp4">
</video>

3. Standalone images are formatted as <figure> with <figcaption>.

4. Things like timestamps could be expressed as <time> elements, but I
haven't done that here. The relevant attributes still seem to be up in
the air, and it would be complicated.

5. It's generally accepted that one should use some variety of the
html5shiv[1] to make IE <9 render new HTML5 elements correctly. I've
dropped a note to this effect in the docstring of
`org-html-html5-fancy', but I suppose it's possible we could take a more
interventionist stance, perhaps including hosting a version of the shiv
on orgmode.org, and linking to it automatically. I guess I'm in favor of
leaving it to the user, though.

Tangential coding question: I've noticed that setting HTML_HTML5_FANCY
to nil at the top of the export file results in `(plist-get info
:html-html5-fancy)' returning the string "nil", ie true. Not right,
obviously, and it makes it impossible to set it to 'nil per-file if the
global value is 't. Am I handling this wrong?


E

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0010-ox-html.el-Give-access-to-new-elements-in-HTML5.patch --]
[-- Type: text/x-patch, Size: 7987 bytes --]

From 636720ca8444a4767a44170b6ed29cf471f1aee7 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sun, 28 Apr 2013 23:00:26 -0700
Subject: [PATCH 10/10] ox-html.el:  Give access to new elements in HTML5

* lisp/ox-html.el (org-html-html5-fancy): New variable, determining whether
                                          or not to use new elements.
                  (org-html-html5-elements): New variable, new HTML5 elements.
                  (org-html-special-block): Export special blocks to new HTML5 elements.
                  (org-html-format-inline-image): Use <figure> and <figcaption> for
	     	                                  standalone images.

* doc/org.texi: Document the above.
---
 doc/org.texi    | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 lisp/ox-html.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 114 insertions(+), 11 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 40f5216..ad438f4 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -11007,11 +11007,11 @@ Export to a temporary buffer.  Do not create a file.
 
 Org can export to various (X)HTML flavors.
 
-Setting the variable @var{org-html-doctype} allows you to export to different
-(X)HTML variants. The exported HTML will be adjusted according to the sytax
-requirements of that variant. You can either set this variable to a doctype
+Setting the variable @code{org-html-doctype} allows you to export to different
+(X)HTML variants.  The exported HTML will be adjusted according to the sytax
+requirements of that variant.  You can either set this variable to a doctype
 string directly, in which case the exporter will try to adjust the syntax
-automatically, or you can use a ready-made doctype. The ready-made options
+automatically, or you can use a ready-made doctype.  The ready-made options
 are:
 
 @itemize
@@ -11035,7 +11035,61 @@ are:
 ``xhtml5''
 @end itemize
 
-See the variable @var{org-html-doctype-alist} for details. The default is ``xhtml-strict''.
+See the variable @code{org-html-doctype-alist} for details.  The default is
+``xhtml-strict''.
+
+@subsubheading Fancy HTML5 export
+@vindex org-html-html5-fancy
+@vindex org-html-html5-elements
+
+HTML5 introduces several new element types.  By default, Org will not make
+use of these element types, but you can set @code{org-html-html5-fancy} to
+@code{t} (or use the corresponding @code{HTML_HTML5_FANCY} export option), to
+enable a few new block-level elements.  These are created using arbitrary
+#+BEGIN and #+END blocks. For instance:
+
+@example
+#+BEGIN_ASIDE
+Lorem ipsum
+#+END_ASIDE
+@end example
+
+Will export to:
+
+@example
+<aside>
+  <p>Lorem ipsum</p>
+</aside>
+@end example
+
+While this:
+
+@example
+#+ATTR_HTML: :controls controls :width 350
+#+BEGIN_VIDEO
+#+HTML: <source src="movie.mp4" type="video/mp4">
+#+HTML: <source src="movie.ogg" type="video/ogg">
+Your browser does not support the video tag.
+#+END_VIDEO
+@end example
+
+Becomes:
+
+@example
+<video controls="controls" width="350">
+  <source src="movie.mp4" type="video/mp4">
+  <source src="movie.ogg" type="video/ogg">
+  <p>Your browser does not support the video tag.</p>
+</video>
+@end example
+
+Special blocks that do not correspond to HTML5 elements (see
+@code{org-html-html5-elements}) will revert to the usual behavior,
+i.e. #+BEGIN_LEDERHOSEN will still export to <div class=''lederhosen''>.
+
+Headlines cannot appear within special blocks.  To wrap a headline and its
+contents in e.g. <section> or <article> tags, set the @code{HTML_CONTAINER}
+property on the headline itself.
 
 @node HTML preamble and postamble, Quoting HTML tags, HTML doctypes, HTML export
 @subsection HTML preamble and postamble
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 8223a18..e7cae1a 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -116,6 +116,7 @@
     (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-container "HTML_CONTAINER" nil org-html-container-element)
+    (:html-html5-fancy "HTML_HTML5_FANCY" nil org-html-html5-fancy)
     (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -164,6 +165,17 @@
     ("xhtml5" . "<!DOCTYPE html>"))
   "An alist mapping (x)html flavors to specific doctypes.")
 
+(defconst org-html-html5-elements
+  '("article" "aside" "audio" "canvas" "details" "figcaption"
+    "figure" "footer" "header" "menu" "meter" "nav" "output"
+    "progress" "section" "video")
+  "New elements in html5.
+
+<hgroup> is not included because it's currently impossible to
+wrap special blocks around multiple headlines. For other blocks
+that should contain headlines, use the HTML_CONTAINER property on
+the headline itself.")
+
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
@@ -906,6 +918,21 @@ publishing, with :html-doctype."
   :package-version '(Org . "8.0")
   :type 'string)
 
+(defcustom org-html-html5-fancy nil
+  "When exporting to HTML5, set this to t to use new HTML5
+  elements. This variable is ignored for anything other than
+  HTML5.
+
+For compatibility with Internet Explorer, it's probably a good
+idea to download some form of the html5shiv (for instance
+https://code.google.com/p/html5shiv/) and add it to your
+HTML_HEAD_EXTRA, so that your pages don't break for users of IE
+versions 8 and below."
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type 'boolean)
+
 (defcustom org-html-container-element "div"
   "HTML element to use for wrapping top level sections.
 Can be set with the in-buffer HTML_CONTAINER property or for
@@ -1308,14 +1335,20 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
 				  (org-find-text-property-in-string
 				   'org-latex-src src))))
 			(t (format " alt=\"%s\""
-				   (file-name-nondirectory src)))))))
+				   (file-name-nondirectory src))))))
+	 (html5-fancy (and (org-html-html5-p info)
+			   (plist-get info :html-html5-fancy))))
     (cond
      (standalone-p
       (let ((img (org-html-close-tag "img" attr info)))
-	(format "\n<div%s class=\"figure\">%s%s\n</div>"
+	(format (if html5-fancy
+		    "\n<figure%s>%s%s\n</figure>"
+		  "\n<div%s class=\"figure\">%s%s\n</div>")
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
-		    (format "\n<p>%s</p>" caption) ""))))
+		    (format (if html5-fancy
+				"\n<figcaption>%s</figcaption>"
+			      "\n<p>%s</p>") caption) ""))))
      (t (org-html-close-tag "img" (concat attr id) info)))))
 
 (defun org-html--textarea-block (element)
@@ -2927,9 +2960,25 @@ contextual information."
   "Transcode a SPECIAL-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
-  (format "<div class=\"%s\">\n%s\n</div>"
-	  (downcase (org-element-property :type special-block))
-	  contents))
+  (let* ((block-type (downcase
+		      (org-element-property :type special-block)))
+	 (contents (or contents ""))
+	 (html5-fancy (and (org-html-html5-p info)
+			   (plist-get info :html-html5-fancy)
+			   (member block-type org-html-html5-elements)))
+	 (attributes (org-export-read-attribute :attr_html special-block)))
+    (unless html5-fancy
+      (let ((class (plist-get attributes :class)))
+	(setq attributes (plist-put attributes :class
+				    (if class (concat class " " block-type)
+				      block-type)))))
+    (setq attributes (org-html--make-attribute-string attributes))
+    (when (not (equal attributes ""))
+      (setq attributes (concat " " attributes)))
+    (if html5-fancy
+	(format "<%s%s>\n%s</%s>" block-type attributes
+		contents block-type)
+      (format "<div%s>\n%s\n</div>" attributes contents))))
 
 ;;;; Src Block
 
-- 
1.8.2.2


[-- Attachment #3: Type: text/plain, Size: 45 bytes --]




[1]: https://code.google.com/p/html5shiv/

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-29  6:02                       ` Eric Abrahamsen
@ 2013-04-29  7:45                         ` Nicolas Goaziou
  2013-04-30 14:38                         ` Rick Frankel
  2013-04-30 14:40                         ` Rick Frankel
  2 siblings, 0 replies; 28+ messages in thread
From: Nicolas Goaziou @ 2013-04-29  7:45 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hello,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Tangential coding question: I've noticed that setting HTML_HTML5_FANCY
> to nil at the top of the export file results in `(plist-get info
> :html-html5-fancy)' returning the string "nil", ie true. Not right,
> obviously, and it makes it impossible to set it to 'nil per-file if the
> global value is 't. Am I handling this wrong?

Value for regular keywords is always a string. You can check for the
empty string instead.

You can also add an item in OPTIONS, since those are read and, thus, can
have a symbol as value.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-29  6:02                       ` Eric Abrahamsen
  2013-04-29  7:45                         ` Nicolas Goaziou
@ 2013-04-30 14:38                         ` Rick Frankel
  2013-04-30 14:40                         ` Rick Frankel
  2 siblings, 0 replies; 28+ messages in thread
From: Rick Frankel @ 2013-04-30 14:38 UTC (permalink / raw)
  To: emacs-orgmode

On 29.04.2013 02:02, Eric Abrahamsen wrote:
> Rick Frankel <rick@rickster.com> writes:
>
>> On Fri, Apr 26, 2013 at 10:14:17AM -0700, Eric Abrahamsen wrote:
>>> Rick Frankel <rick@rickster.com> writes:

>>> > See the discussions of polyglot markup @
>>> > http://en.wikipedia.org/wiki/Polyglot_markup
>>> > and
>>> > 
>>> http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#dfn-polyglot-markup
>>> > for the rationale.
>>>
>>> Ah, those were interesting links, I hadn't considered those issues.
>>> Luckily, your second option was a three-line change to the existing
>>> patch: using "xhtml5" now produces the same output as "html5", 
>>> except
>>> that self-closing tags are self-closed, and there's a xmlns 
>>> declaration
>>> in the <html> element. Best of all worlds, I hope.
>>

Overall, works well. A couple of things related to
`org-html-xml-declaration':

    - It should not be added by default for xhtml5
      (from 
http://www.w3.org/TR/2011/WD-html-polyglot-20110405/#PI-and-xml):

	 #+BEGIN_QUOTE
       2. Processing Instructions and the XML Declaration

        Processing Instructions and the XML Declaration are both
        forbidden in polyglot markup.
	 #+END_QUOTE

    - If `org-html-xml-declaration' is set to nil or the empty string,
      a blank first line is placed in the document prior to the DOCTYPE
      declaration. If the above fix is added (so it is not generated
      for xhtml5) that should solve the immediate problem, but i think
      that the formatting code in org-html-html-template should check
      that the inner format (line #1697). A patch is attached to fix
      both issues.

> 1. There's a new export option, 
> org-html-html5-fancy/HTML_HTML5_FANCY,
> which defaults to 'nil, making most of the following opt-in only.

Very nice.

> 5. It's generally accepted that one should use some variety of the
> html5shiv[1] to make IE <9 render new HTML5 elements correctly. I've
> dropped a note to this effect in the docstring of
> `org-html-html5-fancy', but I suppose it's possible we could take a 
> more
> interventionist stance, perhaps including hosting a version of the 
> shiv
> on orgmode.org, and linking to it automatically. I guess I'm in favor 
> of
> leaving it to the user, though.

I agree that we should comment and leave it to the user. I believe
the owner of html5shiv is against CDN hosting the javascript and feels
that it should always be downloaded and included locally.

> Tangential coding question: I've noticed that setting 
> HTML_HTML5_FANCY
> to nil at the top of the export file results in `(plist-get info
> :html-html5-fancy)' returning the string "nil", ie true. Not right,
> obviously, and it makes it impossible to set it to 'nil per-file if 
> the
> global value is 't. Am I handling this wrong?

I believe Nicolas answered the is a previous email, but the solution
is use "'()" and not nil.

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-29  6:02                       ` Eric Abrahamsen
  2013-04-29  7:45                         ` Nicolas Goaziou
  2013-04-30 14:38                         ` Rick Frankel
@ 2013-04-30 14:40                         ` Rick Frankel
  2013-05-01  3:26                           ` Eric Abrahamsen
  2 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-04-30 14:40 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 65 bytes --]

Whoops. Wrong key. Patch actually attached to this email...
rick

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Modify-processing-of-xhtml-declaration.patch --]
[-- Type: text/x-lisp; name=0001-Modify-processing-of-xhtml-declaration.patch, Size: 1788 bytes --]

From d95a365f547fdc681c530c9088f775b30a37d9aa Mon Sep 17 00:00:00 2001
From: Rick Frankel <rick@rickster.com>
Date: Tue, 30 Apr 2013 10:35:14 -0400
Subject: [PATCH] Modify processing of xhtml declaration.

* lisp/ox-html.el (org-html-template): If `org-html-xml-declaration'
  is nil or an empty string, don't output a blank line at the head of
  the document. Also, don't ouput the declaration if the document type
  is xhtml5.
---
 lisp/ox-html.el | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index e7cae1a..05b99bf 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1692,19 +1692,21 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
   (concat
-   (when (org-html-xhtml-p info)
-     (format "%s\n"
-	     (format (or (and (stringp org-html-xml-declaration)
+   (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
+     (let ((decl (or (and (stringp org-html-xml-declaration)
 			      org-html-xml-declaration)
 			 (cdr (assoc (plist-get info :html-extension)
 				     org-html-xml-declaration))
 			 (cdr (assoc "html" org-html-xml-declaration))
 
-			 "")
-		     (or (and org-html-coding-system
-			      (fboundp 'coding-system-get)
-			      (coding-system-get org-html-coding-system 'mime-charset))
-			 "iso-8859-1"))))
+			 "")))
+       (when (not (or (eq nil decl) (string= "" decl)))
+	 (format "%s\n"
+		 (format decl
+		  (or (and org-html-coding-system
+			   (fboundp 'coding-system-get)
+			   (coding-system-get org-html-coding-system 'mime-charset))
+		      "iso-8859-1"))))))
    (let* ((dt (plist-get info :html-doctype))
 	  (dt-cons (assoc dt org-html-doctype-alist)))
      (if dt-cons
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-04-30 14:40                         ` Rick Frankel
@ 2013-05-01  3:26                           ` Eric Abrahamsen
  2013-05-01 11:55                             ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-05-01  3:26 UTC (permalink / raw)
  To: emacs-orgmode

Rick Frankel <rick@rickster.com> writes:

> Whoops. Wrong key. Patch actually attached to this email...
> rick

Great, I'll consolidate all these -- would it be better to mush them
into one big patch, or to keep them separate (I suppose for ease of
rollback, if something goes wrong)?

E

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-01  3:26                           ` Eric Abrahamsen
@ 2013-05-01 11:55                             ` Rick Frankel
  2013-05-02 21:07                               ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Rick Frankel @ 2013-05-01 11:55 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
> Rick Frankel <rick@rickster.com> writes:
> 
> > Whoops. Wrong key. Patch actually attached to this email...
> > rick
> 
> Great, I'll consolidate all these -- would it be better to mush them
> into one big patch, or to keep them separate (I suppose for ease of
> rollback, if something goes wrong)?

Probably squashing them into one patch would be the best. But Carsten
or Bastien might disagree :).

rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-01 11:55                             ` Rick Frankel
@ 2013-05-02 21:07                               ` Eric Abrahamsen
  2013-05-03  7:17                                 ` Carsten Dominik
  2013-05-06  5:49                                 ` Carsten Dominik
  0 siblings, 2 replies; 28+ messages in thread
From: Eric Abrahamsen @ 2013-05-02 21:07 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 895 bytes --]

Rick Frankel <rick@rickster.com> writes:

> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>> Rick Frankel <rick@rickster.com> writes:
>> 
>> > Whoops. Wrong key. Patch actually attached to this email...
>> > rick
>> 
>> Great, I'll consolidate all these -- would it be better to mush them
>> into one big patch, or to keep them separate (I suppose for ease of
>> rollback, if something goes wrong)?
>
> Probably squashing them into one patch would be the best. But Carsten
> or Bastien might disagree :).
>
> rick

Okay, there it is: one big patch (including your xml declaration fix).

I didn't add any more refined handling of the html5-fancy option. As a
second-order option it didn't seem worthy of an #+OPTIONS entry, and I
didn't bother checking for an empty string, either. It can always be
#+BINDed if necessary, and if it ever annoys anyone I can fix it
further.

E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch --]
[-- Type: text/x-patch, Size: 26436 bytes --]

From 9224f289801c7f1193718fe7f2ca351e26d7534b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Thu, 2 May 2013 13:40:58 -0700
Subject: [PATCH] ox-html.el  Export to different (X)HTML flavors, including
 HTML5

* lisp/ox-html.el
(org-html-doctype-alist): New variable holding an alist of (X)HTML
			 doctypes
(org-html-xhtml-p): New function
(org-html-html5-p): New function
(org-html-close-tag): New function
(org-html-html5-fancy): New export option, determining whether or not to
                        use HTML5-specific elements.
(org-html-html5-elements): New variable, new HTML5 elements.
(org-html-special-block): Export special blocks to new HTML5 elements.
(org-html-format-inline-image): Use <figure> and <figcaption> for
	     	                standalone images.
Significant changes to `org-html-format-inline-image',
`org-html--build-meta-info', `org-html--build-head',
`org-html--build-pre/postable', `org-html-template',
`org-html-horizontal-rule', `org-html-format-list-item',
`org-html-line-break', `org-html-table', and `org-html-verse-block'.

doc/org.texi: Document the above
---
 doc/org.texi    |  97 +++++++++++++++++++++-
 lisp/ox-html.el | 251 ++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 277 insertions(+), 71 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 7437451..c294ea6 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -596,6 +596,7 @@ Exporting
 HTML export
 
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10969,6 +10970,7 @@ language, but with additional support for tables.
 
 @menu
 * HTML Export commands::        How to invoke HTML export
+* HTML doctypes::               Org can export to various (X)HTML flavors
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10980,7 +10982,7 @@ language, but with additional support for tables.
 * JavaScript support::          Info and Folding in a web browser
 @end menu
 
-@node HTML Export commands, HTML preamble and postamble, HTML export, HTML export
+@node HTML Export commands, HTML doctypes, HTML export, HTML export
 @subsection HTML export commands
 
 @table @kbd
@@ -11008,7 +11010,98 @@ Export to a temporary buffer.  Do not create a file.
 @c @noindent
 @c creates two levels of headings and does the rest as items.
 
-@node HTML preamble and postamble, Quoting HTML tags, HTML Export commands, HTML export
+@node HTML doctypes, HTML preamble and postamble, HTML Export commands, HTML export
+@subsection HTML doctypes
+@vindex org-html-doctype
+@vindex org-html-doctype-alist
+
+Org can export to various (X)HTML flavors.
+
+Setting the variable @code{org-html-doctype} allows you to export to different
+(X)HTML variants.  The exported HTML will be adjusted according to the sytax
+requirements of that variant.  You can either set this variable to a doctype
+string directly, in which case the exporter will try to adjust the syntax
+automatically, or you can use a ready-made doctype.  The ready-made options
+are:
+
+@itemize
+@item
+``html4-strict''
+@item
+``html4-transitional''
+@item
+``html4-frameset''
+@item
+``xhtml-strict''
+@item
+``xhtml-transitional''
+@item
+``xhtml-frameset''
+@item
+``xhtml-11''
+@item
+``html5''
+@item
+``xhtml5''
+@end itemize
+
+See the variable @code{org-html-doctype-alist} for details.  The default is
+``xhtml-strict''.
+
+@subsubheading Fancy HTML5 export
+@vindex org-html-html5-fancy
+@vindex org-html-html5-elements
+
+HTML5 introduces several new element types.  By default, Org will not make
+use of these element types, but you can set @code{org-html-html5-fancy} to
+@code{t} (or use the corresponding @code{HTML_HTML5_FANCY} export option), to
+enable a few new block-level elements.  These are created using arbitrary
+#+BEGIN and #+END blocks. For instance:
+
+@example
+#+BEGIN_ASIDE
+Lorem ipsum
+#+END_ASIDE
+@end example
+
+Will export to:
+
+@example
+<aside>
+  <p>Lorem ipsum</p>
+</aside>
+@end example
+
+While this:
+
+@example
+#+ATTR_HTML: :controls controls :width 350
+#+BEGIN_VIDEO
+#+HTML: <source src="movie.mp4" type="video/mp4">
+#+HTML: <source src="movie.ogg" type="video/ogg">
+Your browser does not support the video tag.
+#+END_VIDEO
+@end example
+
+Becomes:
+
+@example
+<video controls="controls" width="350">
+  <source src="movie.mp4" type="video/mp4">
+  <source src="movie.ogg" type="video/ogg">
+  <p>Your browser does not support the video tag.</p>
+</video>
+@end example
+
+Special blocks that do not correspond to HTML5 elements (see
+@code{org-html-html5-elements}) will revert to the usual behavior,
+i.e. #+BEGIN_LEDERHOSEN will still export to <div class=''lederhosen''>.
+
+Headlines cannot appear within special blocks.  To wrap a headline and its
+contents in e.g. <section> or <article> tags, set the @code{HTML_CONTAINER}
+property on the headline itself.
+
+@node HTML preamble and postamble, Quoting HTML tags, HTML doctypes, HTML export
 @subsection HTML preamble and postamble
 @vindex org-html-preamble
 @vindex org-html-postamble
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index ef7d15a..05b99bf 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -116,6 +116,7 @@
     (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-container "HTML_CONTAINER" nil org-html-container-element)
+    (:html-html5-fancy "HTML_HTML5_FANCY" nil org-html-html5-fancy)
     (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -143,6 +144,38 @@
 (defvar org-html--pre/postamble-class "status"
   "CSS class used for pre/postamble")
 
+(defconst org-html-doctype-alist
+  '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
+\"http://www.w3.org/TR/html4/strict.dtd\">")
+    ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+\"http://www.w3.org/TR/html4/loose.dtd\">")
+    ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
+\"http://www.w3.org/TR/html4/frameset.dtd\">")
+
+    ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
+    ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
+    ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
+    ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
+\"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
+
+    ("html5" . "<!DOCTYPE html>")
+    ("xhtml5" . "<!DOCTYPE html>"))
+  "An alist mapping (x)html flavors to specific doctypes.")
+
+(defconst org-html-html5-elements
+  '("article" "aside" "audio" "canvas" "details" "figcaption"
+    "figure" "footer" "header" "menu" "meter" "nav" "output"
+    "progress" "section" "video")
+  "New elements in html5.
+
+<hgroup> is not included because it's currently impossible to
+wrap special blocks around multiple headlines. For other blocks
+that should contain headlines, use the HTML_CONTAINER property on
+the headline itself.")
+
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
@@ -748,7 +781,9 @@ in all modes you want.  Then, use the command
   '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
   "Default attributes and values which will be used in table tags.
 This is a plist where attributes are symbols, starting with
-colons, and values are strings."
+colons, and values are strings.
+
+When exporting to HTML5, these values will be disregarded."
   :group 'org-export-html
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -856,7 +891,9 @@ CSS classes, then this prefix can be very useful."
   "The extension for exported HTML files.
 %s will be replaced with the charset of the exported file.
 This may be a string, or an alist with export extensions
-and corresponding declarations."
+and corresponding declarations.
+
+This declaration only applies when exporting to XHTML."
   :group 'org-export-html
   :type '(choice
 	  (string :tag "Single declaration")
@@ -872,8 +909,7 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :type 'coding-system)
 
-(defcustom org-html-doctype
-  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
+(defcustom org-html-doctype "xhtml-strict"
   "Document type definition to use for exported HTML files.
 Can be set with the in-buffer HTML_DOCTYPE property or for
 publishing, with :html-doctype."
@@ -882,6 +918,21 @@ publishing, with :html-doctype."
   :package-version '(Org . "8.0")
   :type 'string)
 
+(defcustom org-html-html5-fancy nil
+  "When exporting to HTML5, set this to t to use new HTML5
+  elements. This variable is ignored for anything other than
+  HTML5.
+
+For compatibility with Internet Explorer, it's probably a good
+idea to download some form of the html5shiv (for instance
+https://code.google.com/p/html5shiv/) and add it to your
+HTML_HEAD_EXTRA, so that your pages don't break for users of IE
+versions 8 and below."
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type 'boolean)
+
 (defcustom org-html-container-element "div"
   "HTML element to use for wrapping top level sections.
 Can be set with the in-buffer HTML_CONTAINER property or for
@@ -962,7 +1013,8 @@ You can also customize this for each buffer, using something like
 		    (const :format "       " mathml) (boolean))))
 
 (defcustom org-html-mathjax-template
-  "<script type=\"text/javascript\" src=\"%PATH\">
+  "<script type=\"text/javascript\" src=\"%PATH\"></script>
+<script type=\"text/javascript\">
 <!--/*--><![CDATA[/*><!--*/
     MathJax.Hub.Config({
         // Only one of the two following lines, depending on user settings
@@ -1035,7 +1087,7 @@ precedence over this variable."
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"creator\">%c</p>
-<p class=\"xhtml-validation\">%v</p>"))
+<p class=\"validation\">%v</p>"))
   "Alist of languages and format strings for the HTML postamble.
 
 The first element of each list is the language code, as used for
@@ -1060,7 +1112,7 @@ like that: \"%%\"."
 		:value-type (string :tag "Format string")))
 
 (defcustom org-html-validation-link
-  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
+  "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
   "Link to HTML validation service."
   :group 'org-export-html
   :type 'string)
@@ -1240,6 +1292,18 @@ CSS classes, then this prefix can be very useful."
 \f
 ;;; Internal Functions
 
+(defun org-html-xhtml-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+    (string-match-p "xhtml" dt)))
+
+(defun org-html-html5-p (info)
+  (let ((dt (downcase (plist-get info :html-doctype))))
+	(member dt '("html5" "xhtml5" "<!doctype html>"))))
+
+(defun org-html-close-tag (tag attr info)
+  (concat "<" tag (or attr "")
+	  (if (org-html-xhtml-p info) " />" ">")))
+
 (defun org-html--make-attribute-string (attributes)
   "Return a list of attributes, as a string.
 ATTRIBUTES is a plist where values are either strings or nil. An
@@ -1253,7 +1317,7 @@ attributes with a nil value will be omitted from the result."
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
 
-(defun org-html-format-inline-image (src &optional
+(defun org-html-format-inline-image (src info &optional
 					 caption label attr standalone-p)
   "Format an inline image from SRC.
 CAPTION, LABEL and ATTR are optional arguments providing the
@@ -1262,6 +1326,7 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
   (let* ((id (if (not label) ""
 	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
 	 (attr (concat attr
+		       (format " src=\"%s\"" src)
 		       (cond
 			((string-match "\\<alt=" (or attr "")) "")
 			((string-match "^ltxpng/" src)
@@ -1270,15 +1335,21 @@ When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
 				  (org-find-text-property-in-string
 				   'org-latex-src src))))
 			(t (format " alt=\"%s\""
-				   (file-name-nondirectory src)))))))
+				   (file-name-nondirectory src))))))
+	 (html5-fancy (and (org-html-html5-p info)
+			   (plist-get info :html-html5-fancy))))
     (cond
      (standalone-p
-      (let ((img (format "<img src=\"%s\" %s/>" src attr)))
-	(format "\n<div%s class=\"figure\">%s%s\n</div>"
+      (let ((img (org-html-close-tag "img" attr info)))
+	(format (if html5-fancy
+		    "\n<figure%s>%s%s\n</figure>"
+		  "\n<div%s class=\"figure\">%s%s\n</div>")
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
-		    (format "\n<p>%s</p>" caption) ""))))
-     (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
+		    (format (if html5-fancy
+				"\n<figcaption>%s</figcaption>"
+			      "\n<p>%s</p>") caption) ""))))
+     (t (org-html-close-tag "img" (concat attr id) info)))))
 
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
@@ -1437,7 +1508,11 @@ INFO is a plist used as a communication channel."
 				 (cons 'plain-text org-element-all-objects)
 			       'identity info))))))
 	(description (plist-get info :description))
-	(keywords (plist-get info :keywords)))
+	(keywords (plist-get info :keywords))
+	(charset (or (and org-html-coding-system
+			  (fboundp 'coding-system-get)
+			  (coding-system-get org-html-coding-system 'mime-charset))
+		     "iso-8859-1")))
     (concat
      (format "<title>%s</title>\n" title)
      (format
@@ -1445,21 +1520,24 @@ INFO is a plist used as a communication channel."
 	(format-time-string
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
      (format
-      "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
-      (or (and org-html-coding-system
-	       (fboundp 'coding-system-get)
-	       (coding-system-get org-html-coding-system 'mime-charset))
-	  "iso-8859-1"))
-     (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
+      (if (org-html-html5-p info)
+	  (org-html-close-tag "meta" " charset=\"%s\"" info)
+	(org-html-close-tag
+	 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" info))
+      charset) "\n"
+     (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info) "\n"
      (and (org-string-nw-p author)
-	  (format "<meta name=\"author\" content=\"%s\"/>\n"
-		  (funcall protect-string author)))
+	  (org-html-close-tag "meta" (format " name=\"author\" content=\"%s\""
+					     (funcall protect-string author)) info)
+	  "\n")
      (and (org-string-nw-p description)
-	  (format "<meta name=\"description\" content=\"%s\"/>\n"
-		  (funcall protect-string description)))
+	  (org-html-close-tag "meta" (format " name=\"description\" content=\"%s\"%s\n"
+					     (funcall protect-string description)) info)
+	  "\n")
      (and (org-string-nw-p keywords)
-	  (format "<meta name=\"keywords\" content=\"%s\"/>\n"
-		  (funcall protect-string keywords))))))
+	  (org-html-close-tag "meta" (format " name=\"keywords\" content=\"%s\""
+					     (funcall protect-string keywords)) info)
+	  "\n"))))
 
 (defun org-html--build-head (info)
   "Return information for the <head>..</head> of the HTML output.
@@ -1472,8 +1550,10 @@ INFO is a plist used as a communication channel."
     (org-element-normalize-string (plist-get info :html-head-extra))
     (when (and (plist-get info :html-htmlized-css-url)
 	       (eq org-html-htmlize-output-type 'css))
-      (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
-	      (plist-get info :html-htmlized-css-url)))
+      (org-html-close-tag "link"
+			  (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
+				  (plist-get info :html-htmlized-css-url))
+			  info))
     (when (plist-get info :html-head-include-scripts) org-html-scripts))))
 
 (defun org-html--build-mathjax-config (info)
@@ -1570,7 +1650,7 @@ communication channel."
 		       (format-time-string org-html-metadata-timestamp-format)))
 		    (when (plist-get info :with-creator)
 		      (format "<p class=\"creator\">%s</p>\n" creator))
-		    (format "<p class=\"xhtml-validation\">%s</p>\n"
+		    (format "<p class=\"validation\">%s</p>\n"
 			    validation-link))))
 		(t (format-spec
 		    (or (cadr (assoc
@@ -1612,23 +1692,33 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
   (concat
-   (format
-    (or (and (stringp org-html-xml-declaration)
-	     org-html-xml-declaration)
-	(cdr (assoc (plist-get info :html-extension)
-		    org-html-xml-declaration))
-	(cdr (assoc "html" org-html-xml-declaration))
-
-	"")
-    (or (and org-html-coding-system
-	     (fboundp 'coding-system-get)
-	     (coding-system-get org-html-coding-system 'mime-charset))
-	"iso-8859-1"))
-   "\n"
-   (plist-get info :html-doctype)
+   (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
+     (let ((decl (or (and (stringp org-html-xml-declaration)
+			      org-html-xml-declaration)
+			 (cdr (assoc (plist-get info :html-extension)
+				     org-html-xml-declaration))
+			 (cdr (assoc "html" org-html-xml-declaration))
+
+			 "")))
+       (when (not (or (eq nil decl) (string= "" decl)))
+	 (format "%s\n"
+		 (format decl
+		  (or (and org-html-coding-system
+			   (fboundp 'coding-system-get)
+			   (coding-system-get org-html-coding-system 'mime-charset))
+		      "iso-8859-1"))))))
+   (let* ((dt (plist-get info :html-doctype))
+	  (dt-cons (assoc dt org-html-doctype-alist)))
+     (if dt-cons
+	 (cdr dt-cons)
+       dt))
    "\n"
-   (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
-	   (plist-get info :language) (plist-get info :language))
+   (concat "<html"
+	   (when (org-html-xhtml-p info)
+	     (format
+	      " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
+	      (plist-get info :language) (plist-get info :language)))
+	   ">\n")
    "<head>\n"
    (org-html--build-meta-info info)
    (org-html--build-head info)
@@ -2179,7 +2269,7 @@ holding contextual information."
       ;; Build the real contents of the sub-tree.
       (let* ((type (if numberedp 'ordered 'unordered))
 	     (itemized-body (org-html-format-list-item
-			     contents type nil nil full-text)))
+			     contents type nil info nil full-text)))
 	(concat
 	 (and (org-export-first-sibling-p headline info)
 	      (org-html-begin-plain-list type))
@@ -2239,7 +2329,7 @@ holding contextual information."
 (defun org-html-horizontal-rule (horizontal-rule contents info)
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<hr/>")
+  (org-html-close-tag "hr" nil info))
 
 ;;;; Inline Src Block
 
@@ -2275,8 +2365,9 @@ holding contextual information."
       (org-html-format-headline--wrap
        inlinetask info format-function :contents contents)))
    ;; Otherwise, use a default template.
-   (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
+   (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
 	      (org-html-format-headline--wrap inlinetask info)
+	      (org-html-close-tag "br" nil info)
 	      contents))))
 
 ;;;; Italic
@@ -2296,11 +2387,12 @@ contextual information."
 	(trans "<code>[-]</code>")
 	(t "")))
 
-(defun org-html-format-list-item (contents type checkbox
+(defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     headline)
   "Format a list item into HTML."
-  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
+  (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
+	(br (org-html-close-tag "br" nil info)))
     (concat
      (case type
        (ordered
@@ -2308,13 +2400,13 @@ contextual information."
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (unordered
 	(let* ((id term-counter-id)
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	  (concat
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (descriptive
 	(let* ((term term-counter-id))
 	  (setq term (or term "(no term)"))
@@ -2340,7 +2432,7 @@ contextual information."
 	 (tag (let ((tag (org-element-property :tag item)))
 		(and tag (org-export-data tag info)))))
     (org-html-format-list-item
-     contents type checkbox (or tag counter))))
+     contents type checkbox info (or tag counter))))
 
 ;;;; Keyword
 
@@ -2399,7 +2491,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(when (and formula-link
 		   (string-match "file:\\([^]]*\\)" formula-link))
 	  (org-html-format-inline-image
-	   (match-string 1 formula-link) caption label attr t))))
+	   (match-string 1 formula-link) info caption label attr t))))
      (t latex-frag))))
 
 ;;;; Latex Fragment
@@ -2418,7 +2510,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 (when (and formula-link
 		    (string-match "file:\\([^]]*\\)" formula-link))
 	   (org-html-format-inline-image
-	    (match-string 1 formula-link)))))
+	    (match-string 1 formula-link) info))))
       (t latex-frag))))
 
 ;;;; Line Break
@@ -2426,7 +2518,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<br/>\n")
+  (concat (org-html-close-tag "br" nil info) "\n"))
 
 ;;;; Link
 
@@ -2451,7 +2543,7 @@ Inline images can have these attributes:
 	 (label (org-element-property :name parent)))
     ;; Return proper string, depending on DISPOSITION.
     (org-html-format-inline-image
-     path caption label
+     path info caption label
      (org-html--make-attribute-string
       (org-export-read-attribute :attr_html parent))
      (org-html-standalone-image-p link info))))
@@ -2769,7 +2861,8 @@ contextual information."
     (when (plist-get info :preserve-breaks)
       (setq output
 	    (replace-regexp-in-string
-	     "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
+	     "\\(\\\\\\\\\\)?[ \t]*\n"
+	     (concat (org-html-close-tag "br" nil info) "\n") output)))
     ;; Return value.
     output))
 
@@ -2869,9 +2962,25 @@ contextual information."
   "Transcode a SPECIAL-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
-  (format "<div class=\"%s\">\n%s\n</div>"
-	  (downcase (org-element-property :type special-block))
-	  contents))
+  (let* ((block-type (downcase
+		      (org-element-property :type special-block)))
+	 (contents (or contents ""))
+	 (html5-fancy (and (org-html-html5-p info)
+			   (plist-get info :html-html5-fancy)
+			   (member block-type org-html-html5-elements)))
+	 (attributes (org-export-read-attribute :attr_html special-block)))
+    (unless html5-fancy
+      (let ((class (plist-get attributes :class)))
+	(setq attributes (plist-put attributes :class
+				    (if class (concat class " " block-type)
+				      block-type)))))
+    (setq attributes (org-html--make-attribute-string attributes))
+    (when (not (equal attributes ""))
+      (setq attributes (concat " " attributes)))
+    (if html5-fancy
+	(format "<%s%s>\n%s</%s>" block-type attributes
+		contents block-type)
+      (format "<div%s>\n%s\n</div>" attributes contents))))
 
 ;;;; Src Block
 
@@ -3044,11 +3153,12 @@ contextual information."
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (attributes
-	     (org-html--make-attribute-string
-	      (org-combine-plists
-	       (and label (list :id (org-export-solidify-link-text label)))
-	       (plist-get info :html-table-attributes)
-	       (org-export-read-attribute :attr_html table))))
+	     (if (org-html-html5-p info) ""
+	       (org-html--make-attribute-string
+		(org-combine-plists
+		 (and label (list :id (org-export-solidify-link-text label)))
+		 (plist-get info :html-table-attributes)
+		 (org-export-read-attribute :attr_html table)))))
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3066,7 +3176,9 @@ contextual information."
 			     table-cell info)
 			"\n<colgroup>")
 		      ;; Add a column.  Also specify it's alignment.
-		      (format "\n<col %s/>" (format alignspec alignment))
+		      (format "\n%s"
+			      (org-html-close-tag
+			       "col" (concat " " (format alignspec alignment)) info))
 		      ;; End a colgroup?
 		      (when (org-export-table-cell-ends-colgroup-p
 			     table-cell info)
@@ -3128,9 +3240,10 @@ contextual information."
   ;; Replace each newline character with line break.  Also replace
   ;; each blank line with a line break.
   (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" "<br/>\n"
+		  "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
 		  (replace-regexp-in-string
-		   "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
+		   "\\(\\\\\\\\\\)?[ \t]*\n"
+		   (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
   ;; Replace each white space at beginning of a line with a
   ;; non-breaking space.
   (while (string-match "^[ \t]+" contents)
-- 
1.8.2.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-02 21:07                               ` Eric Abrahamsen
@ 2013-05-03  7:17                                 ` Carsten Dominik
  2013-05-06  5:49                                 ` Carsten Dominik
  1 sibling, 0 replies; 28+ messages in thread
From: Carsten Dominik @ 2013-05-03  7:17 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Thanks, I will look at this patch next week.

- Carsten

On 2.5.2013, at 23:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> Rick Frankel <rick@rickster.com> writes:
> 
>> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>>> Rick Frankel <rick@rickster.com> writes:
>>> 
>>>> Whoops. Wrong key. Patch actually attached to this email...
>>>> rick
>>> 
>>> Great, I'll consolidate all these -- would it be better to mush them
>>> into one big patch, or to keep them separate (I suppose for ease of
>>> rollback, if something goes wrong)?
>> 
>> Probably squashing them into one patch would be the best. But Carsten
>> or Bastien might disagree :).
>> 
>> rick
> 
> Okay, there it is: one big patch (including your xml declaration fix).
> 
> I didn't add any more refined handling of the html5-fancy option. As a
> second-order option it didn't seem worthy of an #+OPTIONS entry, and I
> didn't bother checking for an empty string, either. It can always be
> #+BINDed if necessary, and if it ever annoys anyone I can fix it
> further.
> 
> E
> 
> <0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-02 21:07                               ` Eric Abrahamsen
  2013-05-03  7:17                                 ` Carsten Dominik
@ 2013-05-06  5:49                                 ` Carsten Dominik
  2013-05-06  7:36                                   ` Eric Abrahamsen
  1 sibling, 1 reply; 28+ messages in thread
From: Carsten Dominik @ 2013-05-06  5:49 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric, Rick, Francois and others,

Nicolas commented to me about this patch that he was wondering if it
would not be better to have a separate backend for html5, i.e.
ox-html5.el that could be derived from ox-html.el and make it easier
in the future to build it out to take full advantage of html5 features.
I think he has a point, and I would like to hear your comments.

Thanks

- Carsten

On 2.5.2013, at 23:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> Rick Frankel <rick@rickster.com> writes:
> 
>> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>>> Rick Frankel <rick@rickster.com> writes:
>>> 
>>>> Whoops. Wrong key. Patch actually attached to this email...
>>>> rick
>>> 
>>> Great, I'll consolidate all these -- would it be better to mush them
>>> into one big patch, or to keep them separate (I suppose for ease of
>>> rollback, if something goes wrong)?
>> 
>> Probably squashing them into one patch would be the best. But Carsten
>> or Bastien might disagree :).
>> 
>> rick
> 
> Okay, there it is: one big patch (including your xml declaration fix).
> 
> I didn't add any more refined handling of the html5-fancy option. As a
> second-order option it didn't seem worthy of an #+OPTIONS entry, and I
> didn't bother checking for an empty string, either. It can always be
> #+BINDed if necessary, and if it ever annoys anyone I can fix it
> further.
> 
> E
> 
> <0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-06  5:49                                 ` Carsten Dominik
@ 2013-05-06  7:36                                   ` Eric Abrahamsen
  2013-05-06  7:48                                     ` Carsten Dominik
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-05-06  7:36 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Eric, Rick, Francois and others,
>
> Nicolas commented to me about this patch that he was wondering if it
> would not be better to have a separate backend for html5, i.e.
> ox-html5.el that could be derived from ox-html.el and make it easier
> in the future to build it out to take full advantage of html5 features.
> I think he has a point, and I would like to hear your comments.

My initial reaction is: yes, eventually, but perhaps not now. A few
reasons:

1. This patch is already done, and it works, modulo bugfixes (not a
great reason, I know).

2. The patch ended up with two predicate functions (org-html-xhtml-p and
org-html-html5-p) because we really are dealing with four distinct
states: X or not, and 5 or not. Splitting off ox-html5 only isolates one
of those predicates: the "X or not" question would still have to be
asked and answered in both ox-html and ox-html5. You could just as well
split it the other way (ox-xhtml and ox-html), and have the X variants
actually build a DOM tree and write xml (I'm not actually advocating
that, but I just read this[1]).

3. The change to org-html-special-block takes care of the large majority
of new html5 features. The change to inline-images is fairly small.
Otherwise, there are many new inline elements that could be used, but in
many cases browser support for these is limited or nonexistent, and even
basic syntax is up in the air. They can wait (or be handled with custom
link types).

More importantly, the html5 version of, for example, the formatting of
timestamps would look very like the (x)html(4) version, except that the
final tag would be a bit different (<time> instead of <span>, with
different attributes). Most of the surrounding logic would be the same.
So ox-html5 would only override a few of ox-html's formatting functions,
and even those few would largely be copy-n-paste from ox-html. I'm not
sure that's worth it. (Unless derived backends could call back to their
parent backends' implementations, a la OO inheritance? But that way lies
madness.)

To be clear, I think *something* more drastic should be done. But my
feeling is: go with this patch for now. Then stop there. The next time
someone feels the need to expand org's html5 capabilities, think about
new backends.

I'm happy to continue with the discussion, and the coding. I think part
of the problem is HTML itself: as Rick's polyglot concerns show, the
formats can be multiple things at once. Another part of the problem is
that org has a certain take on HTML that I guess comes out of the early
days of Unix documentation, when it really was the HyperText Markup
Language: linked sets of static pages, with up/prev/next links, and
headers and footers on each page. `org-html-divs' is a good example of
this, and a perfect example of where html5 would handle things
differently. I would argue that that should no longer be the default
point of view on HTML. If we're going to rethink things, let's rethink
this too.

Eric

[1] http://glyph.twistedmatrix.com/2008/06/data-in-garbage-out.html


> On 2.5.2013, at 23:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> Rick Frankel <rick@rickster.com> writes:
>> 
>>> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>>>> Rick Frankel <rick@rickster.com> writes:
>>>> 
>>>>> Whoops. Wrong key. Patch actually attached to this email...
>>>>> rick
>>>> 
>>>> Great, I'll consolidate all these -- would it be better to mush them
>>>> into one big patch, or to keep them separate (I suppose for ease of
>>>> rollback, if something goes wrong)?
>>> 
>>> Probably squashing them into one patch would be the best. But Carsten
>>> or Bastien might disagree :).
>>> 
>>> rick
>> 
>> Okay, there it is: one big patch (including your xml declaration fix).
>> 
>> I didn't add any more refined handling of the html5-fancy option. As a
>> second-order option it didn't seem worthy of an #+OPTIONS entry, and I
>> didn't bother checking for an empty string, either. It can always be
>> #+BINDed if necessary, and if it ever annoys anyone I can fix it
>> further.
>> 
>> E
>> 
>> <0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-06  7:36                                   ` Eric Abrahamsen
@ 2013-05-06  7:48                                     ` Carsten Dominik
  2013-05-06  9:05                                       ` Eric Abrahamsen
  0 siblings, 1 reply; 28+ messages in thread
From: Carsten Dominik @ 2013-05-06  7:48 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric,

thanks for the reply.  OK, I am going with the patch for now, let's
push more thinking about HTML5 further down the line.

Thanks for working this out!

- Carsten

On 6.5.2013, at 09:36, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> Hi Eric, Rick, Francois and others,
>> 
>> Nicolas commented to me about this patch that he was wondering if it
>> would not be better to have a separate backend for html5, i.e.
>> ox-html5.el that could be derived from ox-html.el and make it easier
>> in the future to build it out to take full advantage of html5 features.
>> I think he has a point, and I would like to hear your comments.
> 
> My initial reaction is: yes, eventually, but perhaps not now. A few
> reasons:
> 
> 1. This patch is already done, and it works, modulo bugfixes (not a
> great reason, I know).
> 
> 2. The patch ended up with two predicate functions (org-html-xhtml-p and
> org-html-html5-p) because we really are dealing with four distinct
> states: X or not, and 5 or not. Splitting off ox-html5 only isolates one
> of those predicates: the "X or not" question would still have to be
> asked and answered in both ox-html and ox-html5. You could just as well
> split it the other way (ox-xhtml and ox-html), and have the X variants
> actually build a DOM tree and write xml (I'm not actually advocating
> that, but I just read this[1]).
> 
> 3. The change to org-html-special-block takes care of the large majority
> of new html5 features. The change to inline-images is fairly small.
> Otherwise, there are many new inline elements that could be used, but in
> many cases browser support for these is limited or nonexistent, and even
> basic syntax is up in the air. They can wait (or be handled with custom
> link types).
> 
> More importantly, the html5 version of, for example, the formatting of
> timestamps would look very like the (x)html(4) version, except that the
> final tag would be a bit different (<time> instead of <span>, with
> different attributes). Most of the surrounding logic would be the same.
> So ox-html5 would only override a few of ox-html's formatting functions,
> and even those few would largely be copy-n-paste from ox-html. I'm not
> sure that's worth it. (Unless derived backends could call back to their
> parent backends' implementations, a la OO inheritance? But that way lies
> madness.)
> 
> To be clear, I think *something* more drastic should be done. But my
> feeling is: go with this patch for now. Then stop there. The next time
> someone feels the need to expand org's html5 capabilities, think about
> new backends.
> 
> I'm happy to continue with the discussion, and the coding. I think part
> of the problem is HTML itself: as Rick's polyglot concerns show, the
> formats can be multiple things at once. Another part of the problem is
> that org has a certain take on HTML that I guess comes out of the early
> days of Unix documentation, when it really was the HyperText Markup
> Language: linked sets of static pages, with up/prev/next links, and
> headers and footers on each page. `org-html-divs' is a good example of
> this, and a perfect example of where html5 would handle things
> differently. I would argue that that should no longer be the default
> point of view on HTML. If we're going to rethink things, let's rethink
> this too.
> 
> Eric
> 
> [1] http://glyph.twistedmatrix.com/2008/06/data-in-garbage-out.html
> 
> 
>> On 2.5.2013, at 23:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>> 
>>> Rick Frankel <rick@rickster.com> writes:
>>> 
>>>> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>>>>> Rick Frankel <rick@rickster.com> writes:
>>>>> 
>>>>>> Whoops. Wrong key. Patch actually attached to this email...
>>>>>> rick
>>>>> 
>>>>> Great, I'll consolidate all these -- would it be better to mush them
>>>>> into one big patch, or to keep them separate (I suppose for ease of
>>>>> rollback, if something goes wrong)?
>>>> 
>>>> Probably squashing them into one patch would be the best. But Carsten
>>>> or Bastien might disagree :).
>>>> 
>>>> rick
>>> 
>>> Okay, there it is: one big patch (including your xml declaration fix).
>>> 
>>> I didn't add any more refined handling of the html5-fancy option. As a
>>> second-order option it didn't seem worthy of an #+OPTIONS entry, and I
>>> didn't bother checking for an empty string, either. It can always be
>>> #+BINDed if necessary, and if it ever annoys anyone I can fix it
>>> further.
>>> 
>>> E
>>> 
>>> <0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch>
> 
> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-06  7:48                                     ` Carsten Dominik
@ 2013-05-06  9:05                                       ` Eric Abrahamsen
  2013-05-06 12:56                                         ` Rick Frankel
  0 siblings, 1 reply; 28+ messages in thread
From: Eric Abrahamsen @ 2013-05-06  9:05 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Hi Eric,
>
> thanks for the reply.  OK, I am going with the patch for now, let's
> push more thinking about HTML5 further down the line.
>
> Thanks for working this out!

My pleasure, I hope I haven't stifled debate...

> On 6.5.2013, at 09:36, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> Carsten Dominik <carsten.dominik@gmail.com> writes:
>> 
>>> Hi Eric, Rick, Francois and others,
>>> 
>>> Nicolas commented to me about this patch that he was wondering if it
>>> would not be better to have a separate backend for html5, i.e.
>>> ox-html5.el that could be derived from ox-html.el and make it easier
>>> in the future to build it out to take full advantage of html5 features.
>>> I think he has a point, and I would like to hear your comments.
>> 
>> My initial reaction is: yes, eventually, but perhaps not now. A few
>> reasons:
>> 
>> 1. This patch is already done, and it works, modulo bugfixes (not a
>> great reason, I know).
>> 
>> 2. The patch ended up with two predicate functions (org-html-xhtml-p and
>> org-html-html5-p) because we really are dealing with four distinct
>> states: X or not, and 5 or not. Splitting off ox-html5 only isolates one
>> of those predicates: the "X or not" question would still have to be
>> asked and answered in both ox-html and ox-html5. You could just as well
>> split it the other way (ox-xhtml and ox-html), and have the X variants
>> actually build a DOM tree and write xml (I'm not actually advocating
>> that, but I just read this[1]).
>> 
>> 3. The change to org-html-special-block takes care of the large majority
>> of new html5 features. The change to inline-images is fairly small.
>> Otherwise, there are many new inline elements that could be used, but in
>> many cases browser support for these is limited or nonexistent, and even
>> basic syntax is up in the air. They can wait (or be handled with custom
>> link types).
>> 
>> More importantly, the html5 version of, for example, the formatting of
>> timestamps would look very like the (x)html(4) version, except that the
>> final tag would be a bit different (<time> instead of <span>, with
>> different attributes). Most of the surrounding logic would be the same.
>> So ox-html5 would only override a few of ox-html's formatting functions,
>> and even those few would largely be copy-n-paste from ox-html. I'm not
>> sure that's worth it. (Unless derived backends could call back to their
>> parent backends' implementations, a la OO inheritance? But that way lies
>> madness.)
>> 
>> To be clear, I think *something* more drastic should be done. But my
>> feeling is: go with this patch for now. Then stop there. The next time
>> someone feels the need to expand org's html5 capabilities, think about
>> new backends.
>> 
>> I'm happy to continue with the discussion, and the coding. I think part
>> of the problem is HTML itself: as Rick's polyglot concerns show, the
>> formats can be multiple things at once. Another part of the problem is
>> that org has a certain take on HTML that I guess comes out of the early
>> days of Unix documentation, when it really was the HyperText Markup
>> Language: linked sets of static pages, with up/prev/next links, and
>> headers and footers on each page. `org-html-divs' is a good example of
>> this, and a perfect example of where html5 would handle things
>> differently. I would argue that that should no longer be the default
>> point of view on HTML. If we're going to rethink things, let's rethink
>> this too.
>> 
>> Eric
>> 
>> [1] http://glyph.twistedmatrix.com/2008/06/data-in-garbage-out.html
>> 
>> 
>>> On 2.5.2013, at 23:07, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>>> 
>>>> Rick Frankel <rick@rickster.com> writes:
>>>> 
>>>>> On Tue, Apr 30, 2013 at 08:26:52PM -0700, Eric Abrahamsen wrote:
>>>>>> Rick Frankel <rick@rickster.com> writes:
>>>>>> 
>>>>>>> Whoops. Wrong key. Patch actually attached to this email...
>>>>>>> rick
>>>>>> 
>>>>>> Great, I'll consolidate all these -- would it be better to mush them
>>>>>> into one big patch, or to keep them separate (I suppose for ease of
>>>>>> rollback, if something goes wrong)?
>>>>> 
>>>>> Probably squashing them into one patch would be the best. But Carsten
>>>>> or Bastien might disagree :).
>>>>> 
>>>>> rick
>>>> 
>>>> Okay, there it is: one big patch (including your xml declaration fix).
>>>> 
>>>> I didn't add any more refined handling of the html5-fancy option. As a
>>>> second-order option it didn't seem worthy of an #+OPTIONS entry, and I
>>>> didn't bother checking for an empty string, either. It can always be
>>>> #+BINDed if necessary, and if it ever annoys anyone I can fix it
>>>> further.
>>>> 
>>>> E
>>>> 
>>>> <0001-ox-html.el-Export-to-different-X-HTML-flavors-includ.patch>
>> 
>> 

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH] export to various flavors of (X)HTML
  2013-05-06  9:05                                       ` Eric Abrahamsen
@ 2013-05-06 12:56                                         ` Rick Frankel
  0 siblings, 0 replies; 28+ messages in thread
From: Rick Frankel @ 2013-05-06 12:56 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

On Mon, May 06, 2013 at 02:05:18AM -0700, Eric Abrahamsen wrote:
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
> > Hi Eric,
> >
> > thanks for the reply.  OK, I am going with the patch for now, let's
> > push more thinking about HTML5 further down the line.
> >
> > Thanks for working this out!
> 
> My pleasure, I hope I haven't stifled debate...

No you haven't. Rather, you have described my position much better than
i could.

+1

My additional 2 cents. For me, xhtml and polyglot html5 (xhtml
masquerading as html5) are my primary output. html4 (with its sgml
derived unclosed tags) is the anomaly. Going forward i could see
something like:

          ox-html-base (incomplete backend)
              |
         ------------
         |          |
      ox-html4    ox-xhtml(5)
                    |
               ox-html5-fancy (with the html5 specific tags)


rick

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2013-05-06 12:56 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-19  9:57 [PATCH] export to various flavors of (X)HTML Eric Abrahamsen
2013-04-19 15:37 ` Rick Frankel
2013-04-20  2:59   ` Eric Abrahamsen
2013-04-23  1:00     ` Rick Frankel
2013-04-23  4:30       ` Eric Abrahamsen
2013-04-23  4:57         ` Samuel Wales
2013-04-23  6:55           ` Carsten Dominik
2013-04-23  7:54             ` Eric Abrahamsen
2013-04-23 12:09         ` François Pinard
2013-04-24  1:17           ` Christian Wittern
2013-04-24 13:10             ` François Pinard
2013-04-25 21:20               ` Eric Abrahamsen
2013-04-26 13:49                 ` Rick Frankel
2013-04-26 17:14                   ` Eric Abrahamsen
2013-04-26 18:49                     ` Rick Frankel
2013-04-29  6:02                       ` Eric Abrahamsen
2013-04-29  7:45                         ` Nicolas Goaziou
2013-04-30 14:38                         ` Rick Frankel
2013-04-30 14:40                         ` Rick Frankel
2013-05-01  3:26                           ` Eric Abrahamsen
2013-05-01 11:55                             ` Rick Frankel
2013-05-02 21:07                               ` Eric Abrahamsen
2013-05-03  7:17                                 ` Carsten Dominik
2013-05-06  5:49                                 ` Carsten Dominik
2013-05-06  7:36                                   ` Eric Abrahamsen
2013-05-06  7:48                                     ` Carsten Dominik
2013-05-06  9:05                                       ` Eric Abrahamsen
2013-05-06 12:56                                         ` Rick Frankel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).