Browse Source

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
(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.
(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,`org-html-verse-block): Changes to
allow flavored export.

* doc/org.texi: Document export to (X)HTML flavors.
Eric Abrahamsen 12 years ago
parent
commit
9bc55c7d00
2 changed files with 277 additions and 71 deletions
  1. 95 2
      doc/org.texi
  2. 182 69
      lisp/ox-html.el

+ 95 - 2
doc/org.texi

@@ -596,6 +596,7 @@ Exporting
 HTML export
 HTML export
 
 
 * HTML Export commands::        How to invoke 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
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
 * Links in HTML export::        How links will be interpreted and formatted
@@ -10969,6 +10970,7 @@ language, but with additional support for tables.
 
 
 @menu
 @menu
 * HTML Export commands::        How to invoke 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
 * HTML preamble and postamble::  How to insert a preamble and a postamble
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Quoting HTML tags::           Using direct HTML in Org mode
 * Links in HTML export::        How links will be interpreted and formatted
 * 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
 * JavaScript support::          Info and Folding in a web browser
 @end menu
 @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
 @subsection HTML export commands
 
 
 @table @kbd
 @table @kbd
@@ -11008,7 +11010,98 @@ Export to a temporary buffer.  Do not create a file.
 @c @noindent
 @c @noindent
 @c creates two levels of headings and does the rest as items.
 @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
 @subsection HTML preamble and postamble
 @vindex org-html-preamble
 @vindex org-html-preamble
 @vindex org-html-postamble
 @vindex org-html-postamble

+ 182 - 69
lisp/ox-html.el

@@ -116,6 +116,7 @@
     (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
     (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
     (:html-container "HTML_CONTAINER" nil org-html-container-element)
     (: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-home "HTML_LINK_HOME" nil org-html-link-home)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
     (:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -143,6 +144,38 @@
 (defvar org-html--pre/postamble-class "status"
 (defvar org-html--pre/postamble-class "status"
   "CSS class used for pre/postamble")
   "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
 (defconst org-html-special-string-regexps
   '(("\\\\-" . "&#x00ad;")		; shy
   '(("\\\\-" . "&#x00ad;")		; shy
     ("---\\([^-]\\)" . "&#x2014;\\1")	; mdash
     ("---\\([^-]\\)" . "&#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")
   '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
   "Default attributes and values which will be used in table tags.
   "Default attributes and values which will be used in table tags.
 This is a plist where attributes are symbols, starting with
 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
   :group 'org-export-html
   :version "24.4"
   :version "24.4"
   :package-version '(Org . "8.0")
   :package-version '(Org . "8.0")
@@ -856,7 +891,9 @@ CSS classes, then this prefix can be very useful."
   "The extension for exported HTML files.
   "The extension for exported HTML files.
 %s will be replaced with the charset of the exported file.
 %s will be replaced with the charset of the exported file.
 This may be a string, or an alist with export extensions
 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
   :group 'org-export-html
   :type '(choice
   :type '(choice
 	  (string :tag "Single declaration")
 	  (string :tag "Single declaration")
@@ -872,8 +909,7 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :package-version '(Org . "8.0")
   :type 'coding-system)
   :type 'coding-system)
 
 
-(defcustom org-html-doctype
+(defcustom org-html-doctype "xhtml-strict"
-  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
   "Document type definition to use for exported HTML files.
   "Document type definition to use for exported HTML files.
 Can be set with the in-buffer HTML_DOCTYPE property or for
 Can be set with the in-buffer HTML_DOCTYPE property or for
 publishing, with :html-doctype."
 publishing, with :html-doctype."
@@ -882,6 +918,21 @@ publishing, with :html-doctype."
   :package-version '(Org . "8.0")
   :package-version '(Org . "8.0")
   :type 'string)
   :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"
 (defcustom org-html-container-element "div"
   "HTML element to use for wrapping top level sections.
   "HTML element to use for wrapping top level sections.
 Can be set with the in-buffer HTML_CONTAINER property or for
 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))))
 		    (const :format "       " mathml) (boolean))))
 
 
 (defcustom org-html-mathjax-template
 (defcustom org-html-mathjax-template
-  "<script type=\"text/javascript\" src=\"%PATH\">
+  "<script type=\"text/javascript\" src=\"%PATH\"></script>
+<script type=\"text/javascript\">
 <!--/*--><![CDATA[/*><!--*/
 <!--/*--><![CDATA[/*><!--*/
     MathJax.Hub.Config({
     MathJax.Hub.Config({
         // Only one of the two following lines, depending on user settings
         // 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>
   '(("en" "<p class=\"author\">Author: %a (%e)</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"date\">Date: %d</p>
 <p class=\"creator\">%c</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.
   "Alist of languages and format strings for the HTML postamble.
 
 
 The first element of each list is the language code, as used for
 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")))
 		:value-type (string :tag "Format string")))
 
 
 (defcustom org-html-validation-link
 (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."
   "Link to HTML validation service."
   :group 'org-export-html
   :group 'org-export-html
   :type 'string)
   :type 'string)
@@ -1240,6 +1292,18 @@ CSS classes, then this prefix can be very useful."
 
 
 ;;; Internal Functions
 ;;; 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)
 (defun org-html--make-attribute-string (attributes)
   "Return a list of attributes, as a string.
   "Return a list of attributes, as a string.
 ATTRIBUTES is a plist where values are either strings or nil. An
 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))))
                              "\"" "&quot;" (org-html-encode-plain-text item))))
                  (setcar output (format "%s=\"%s\"" key value))))))))
                  (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)
 					 caption label attr standalone-p)
   "Format an inline image from SRC.
   "Format an inline image from SRC.
 CAPTION, LABEL and ATTR are optional arguments providing the
 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) ""
   (let* ((id (if (not label) ""
 	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
 	       (format " id=\"%s\"" (org-export-solidify-link-text label))))
 	 (attr (concat attr
 	 (attr (concat attr
+		       (format " src=\"%s\"" src)
 		       (cond
 		       (cond
 			((string-match "\\<alt=" (or attr "")) "")
 			((string-match "\\<alt=" (or attr "")) "")
 			((string-match "^ltxpng/" src)
 			((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-find-text-property-in-string
 				   'org-latex-src src))))
 				   'org-latex-src src))))
 			(t (format " alt=\"%s\""
 			(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
     (cond
      (standalone-p
      (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>"
+	(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)
 		id (format "\n<p>%s</p>" img)
 		(if (and caption (not (string= caption "")))
 		(if (and caption (not (string= caption "")))
-		    (format "\n<p>%s</p>" caption) ""))))
+		    (format (if html5-fancy
-     (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
+				"\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)
 (defun org-html--textarea-block (element)
   "Transcode ELEMENT into a textarea block.
   "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)
 				 (cons 'plain-text org-element-all-objects)
 			       'identity info))))))
 			       'identity info))))))
 	(description (plist-get info :description))
 	(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
     (concat
      (format "<title>%s</title>\n" title)
      (format "<title>%s</title>\n" title)
      (format
      (format
@@ -1445,21 +1520,24 @@ INFO is a plist used as a communication channel."
 	(format-time-string
 	(format-time-string
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
 	 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
      (format
      (format
-      "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
+      (if (org-html-html5-p info)
-      (or (and org-html-coding-system
+	  (org-html-close-tag "meta" " charset=\"%s\"" info)
-	       (fboundp 'coding-system-get)
+	(org-html-close-tag
-	       (coding-system-get org-html-coding-system 'mime-charset))
+	 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"" info))
-	  "iso-8859-1"))
+      charset) "\n"
-     (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
+     (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info) "\n"
      (and (org-string-nw-p author)
      (and (org-string-nw-p author)
-	  (format "<meta name=\"author\" content=\"%s\"/>\n"
+	  (org-html-close-tag "meta" (format " name=\"author\" content=\"%s\""
-		  (funcall protect-string author)))
+					     (funcall protect-string author)) info)
+	  "\n")
      (and (org-string-nw-p description)
      (and (org-string-nw-p description)
-	  (format "<meta name=\"description\" content=\"%s\"/>\n"
+	  (org-html-close-tag "meta" (format " name=\"description\" content=\"%s\"%s\n"
-		  (funcall protect-string description)))
+					     (funcall protect-string description)) info)
+	  "\n")
      (and (org-string-nw-p keywords)
      (and (org-string-nw-p keywords)
-	  (format "<meta name=\"keywords\" content=\"%s\"/>\n"
+	  (org-html-close-tag "meta" (format " name=\"keywords\" content=\"%s\""
-		  (funcall protect-string keywords))))))
+					     (funcall protect-string keywords)) info)
+	  "\n"))))
 
 
 (defun org-html--build-head (info)
 (defun org-html--build-head (info)
   "Return information for the <head>..</head> of the HTML output.
   "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))
     (org-element-normalize-string (plist-get info :html-head-extra))
     (when (and (plist-get info :html-htmlized-css-url)
     (when (and (plist-get info :html-htmlized-css-url)
 	       (eq org-html-htmlize-output-type 'css))
 	       (eq org-html-htmlize-output-type 'css))
-      (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
+      (org-html-close-tag "link"
-	      (plist-get info :html-htmlized-css-url)))
+			  (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))))
     (when (plist-get info :html-head-include-scripts) org-html-scripts))))
 
 
 (defun org-html--build-mathjax-config (info)
 (defun org-html--build-mathjax-config (info)
@@ -1570,7 +1650,7 @@ communication channel."
 		       (format-time-string org-html-metadata-timestamp-format)))
 		       (format-time-string org-html-metadata-timestamp-format)))
 		    (when (plist-get info :with-creator)
 		    (when (plist-get info :with-creator)
 		      (format "<p class=\"creator\">%s</p>\n" 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))))
 			    validation-link))))
 		(t (format-spec
 		(t (format-spec
 		    (or (cadr (assoc
 		    (or (cadr (assoc
@@ -1612,23 +1692,33 @@ holding export options."
 CONTENTS is the transcoded contents string.  INFO is a plist
 CONTENTS is the transcoded contents string.  INFO is a plist
 holding export options."
 holding export options."
   (concat
   (concat
-   (format
+   (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
-    (or (and (stringp org-html-xml-declaration)
+     (let ((decl (or (and (stringp org-html-xml-declaration)
-	     org-html-xml-declaration)
+			      org-html-xml-declaration)
-	(cdr (assoc (plist-get info :html-extension)
+			 (cdr (assoc (plist-get info :html-extension)
-		    org-html-xml-declaration))
+				     org-html-xml-declaration))
-	(cdr (assoc "html" org-html-xml-declaration))
+			 (cdr (assoc "html" org-html-xml-declaration))
-
+
-	"")
+			 "")))
-    (or (and org-html-coding-system
+       (when (not (or (eq nil decl) (string= "" decl)))
-	     (fboundp 'coding-system-get)
+	 (format "%s\n"
-	     (coding-system-get org-html-coding-system 'mime-charset))
+		 (format decl
-	"iso-8859-1"))
+		  (or (and org-html-coding-system
-   "\n"
+			   (fboundp 'coding-system-get)
-   (plist-get info :html-doctype)
+			   (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"
    "\n"
-   (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
+   (concat "<html"
-	   (plist-get info :language) (plist-get info :language))
+	   (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"
    "<head>\n"
    (org-html--build-meta-info info)
    (org-html--build-meta-info info)
    (org-html--build-head info)
    (org-html--build-head info)
@@ -2179,7 +2269,7 @@ holding contextual information."
       ;; Build the real contents of the sub-tree.
       ;; Build the real contents of the sub-tree.
       (let* ((type (if numberedp 'ordered 'unordered))
       (let* ((type (if numberedp 'ordered 'unordered))
 	     (itemized-body (org-html-format-list-item
 	     (itemized-body (org-html-format-list-item
-			     contents type nil nil full-text)))
+			     contents type nil info nil full-text)))
 	(concat
 	(concat
 	 (and (org-export-first-sibling-p headline info)
 	 (and (org-export-first-sibling-p headline info)
 	      (org-html-begin-plain-list type))
 	      (org-html-begin-plain-list type))
@@ -2239,7 +2329,7 @@ holding contextual information."
 (defun org-html-horizontal-rule (horizontal-rule contents info)
 (defun org-html-horizontal-rule (horizontal-rule contents info)
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
   "Transcode an HORIZONTAL-RULE  object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<hr/>")
+  (org-html-close-tag "hr" nil info))
 
 
 ;;;; Inline Src Block
 ;;;; Inline Src Block
 
 
@@ -2275,8 +2365,9 @@ holding contextual information."
       (org-html-format-headline--wrap
       (org-html-format-headline--wrap
        inlinetask info format-function :contents contents)))
        inlinetask info format-function :contents contents)))
    ;; Otherwise, use a default template.
    ;; 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-format-headline--wrap inlinetask info)
+	      (org-html-close-tag "br" nil info)
 	      contents))))
 	      contents))))
 
 
 ;;;; Italic
 ;;;; Italic
@@ -2296,11 +2387,12 @@ contextual information."
 	(trans "<code>[-]</code>")
 	(trans "<code>[-]</code>")
 	(t "")))
 	(t "")))
 
 
-(defun org-html-format-list-item (contents type checkbox
+(defun org-html-format-list-item (contents type checkbox info
 					     &optional term-counter-id
 					     &optional term-counter-id
 					     headline)
 					     headline)
   "Format a list item into HTML."
   "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
     (concat
      (case type
      (case type
        (ordered
        (ordered
@@ -2308,13 +2400,13 @@ contextual information."
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	       (extra (if counter (format " value=\"%s\"" counter) "")))
 	  (concat
 	  (concat
 	   (format "<li%s>" extra)
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (unordered
        (unordered
 	(let* ((id term-counter-id)
 	(let* ((id term-counter-id)
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	       (extra (if id (format " id=\"%s\"" id) "")))
 	  (concat
 	  (concat
 	   (format "<li%s>" extra)
 	   (format "<li%s>" extra)
-	   (when headline (concat headline "<br/>")))))
+	   (when headline (concat headline br)))))
        (descriptive
        (descriptive
 	(let* ((term term-counter-id))
 	(let* ((term term-counter-id))
 	  (setq term (or term "(no term)"))
 	  (setq term (or term "(no term)"))
@@ -2340,7 +2432,7 @@ contextual information."
 	 (tag (let ((tag (org-element-property :tag item)))
 	 (tag (let ((tag (org-element-property :tag item)))
 		(and tag (org-export-data tag info)))))
 		(and tag (org-export-data tag info)))))
     (org-html-format-list-item
     (org-html-format-list-item
-     contents type checkbox (or tag counter))))
+     contents type checkbox info (or tag counter))))
 
 
 ;;;; Keyword
 ;;;; Keyword
 
 
@@ -2399,7 +2491,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	(when (and formula-link
 	(when (and formula-link
 		   (string-match "file:\\([^]]*\\)" formula-link))
 		   (string-match "file:\\([^]]*\\)" formula-link))
 	  (org-html-format-inline-image
 	  (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))))
      (t latex-frag))))
 
 
 ;;;; Latex Fragment
 ;;;; Latex Fragment
@@ -2418,7 +2510,7 @@ CONTENTS is nil.  INFO is a plist holding contextual information."
 	 (when (and formula-link
 	 (when (and formula-link
 		    (string-match "file:\\([^]]*\\)" formula-link))
 		    (string-match "file:\\([^]]*\\)" formula-link))
 	   (org-html-format-inline-image
 	   (org-html-format-inline-image
-	    (match-string 1 formula-link)))))
+	    (match-string 1 formula-link) info))))
       (t latex-frag))))
       (t latex-frag))))
 
 
 ;;;; Line Break
 ;;;; 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)
 (defun org-html-line-break (line-break contents info)
   "Transcode a LINE-BREAK object from Org to HTML.
   "Transcode a LINE-BREAK object from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual information."
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  "<br/>\n")
+  (concat (org-html-close-tag "br" nil info) "\n"))
 
 
 ;;;; Link
 ;;;; Link
 
 
@@ -2451,7 +2543,7 @@ Inline images can have these attributes:
 	 (label (org-element-property :name parent)))
 	 (label (org-element-property :name parent)))
     ;; Return proper string, depending on DISPOSITION.
     ;; Return proper string, depending on DISPOSITION.
     (org-html-format-inline-image
     (org-html-format-inline-image
-     path caption label
+     path info caption label
      (org-html--make-attribute-string
      (org-html--make-attribute-string
       (org-export-read-attribute :attr_html parent))
       (org-export-read-attribute :attr_html parent))
      (org-html-standalone-image-p link info))))
      (org-html-standalone-image-p link info))))
@@ -2769,7 +2861,8 @@ contextual information."
     (when (plist-get info :preserve-breaks)
     (when (plist-get info :preserve-breaks)
       (setq output
       (setq output
 	    (replace-regexp-in-string
 	    (replace-regexp-in-string
-	     "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
+	     "\\(\\\\\\\\\\)?[ \t]*\n"
+	     (concat (org-html-close-tag "br" nil info) "\n") output)))
     ;; Return value.
     ;; Return value.
     output))
     output))
 
 
@@ -2869,9 +2962,25 @@ contextual information."
   "Transcode a SPECIAL-BLOCK element from Org to HTML.
   "Transcode a SPECIAL-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
 holding contextual information."
-  (format "<div class=\"%s\">\n%s\n</div>"
+  (let* ((block-type (downcase
-	  (downcase (org-element-property :type special-block))
+		      (org-element-property :type special-block)))
-	  contents))
+	 (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
 ;;;; Src Block
 
 
@@ -3044,11 +3153,12 @@ contextual information."
      (let* ((label (org-element-property :name table))
      (let* ((label (org-element-property :name table))
 	    (caption (org-export-get-caption table))
 	    (caption (org-export-get-caption table))
 	    (attributes
 	    (attributes
-	     (org-html--make-attribute-string
+	     (if (org-html-html5-p info) ""
-	      (org-combine-plists
+	       (org-html--make-attribute-string
-	       (and label (list :id (org-export-solidify-link-text label)))
+		(org-combine-plists
-	       (plist-get info :html-table-attributes)
+		 (and label (list :id (org-export-solidify-link-text label)))
-	       (org-export-read-attribute :attr_html table))))
+		 (plist-get info :html-table-attributes)
+		 (org-export-read-attribute :attr_html table)))))
 	    (alignspec
 	    (alignspec
 	     (if (and (boundp 'org-html-format-table-no-css)
 	     (if (and (boundp 'org-html-format-table-no-css)
 		      org-html-format-table-no-css)
 		      org-html-format-table-no-css)
@@ -3066,7 +3176,9 @@ contextual information."
 			     table-cell info)
 			     table-cell info)
 			"\n<colgroup>")
 			"\n<colgroup>")
 		      ;; Add a column.  Also specify it's alignment.
 		      ;; 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?
 		      ;; End a colgroup?
 		      (when (org-export-table-cell-ends-colgroup-p
 		      (when (org-export-table-cell-ends-colgroup-p
 			     table-cell info)
 			     table-cell info)
@@ -3128,9 +3240,10 @@ contextual information."
   ;; Replace each newline character with line break.  Also replace
   ;; Replace each newline character with line break.  Also replace
   ;; each blank line with a line break.
   ;; each blank line with a line break.
   (setq contents (replace-regexp-in-string
   (setq contents (replace-regexp-in-string
-		  "^ *\\\\\\\\$" "<br/>\n"
+		  "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
 		  (replace-regexp-in-string
 		  (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
   ;; Replace each white space at beginning of a line with a
   ;; non-breaking space.
   ;; non-breaking space.
   (while (string-match "^[ \t]+" contents)
   (while (string-match "^[ \t]+" contents)