From 636720ca8444a4767a44170b6ed29cf471f1aee7 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen 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
and
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 + +@end example + +While this: + +@example +#+ATTR_HTML: :controls controls :width 350 +#+BEGIN_VIDEO +#+HTML: +#+HTML: +Your browser does not support the video tag. +#+END_VIDEO +@end example + +Becomes: + +@example + +@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
. + +Headlines cannot appear within special blocks. To wrap a headline and its +contents in e.g.
or
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" . "")) "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. + +
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 '(("\\\\-" . "­") ; shy ("---\\([^-]\\)" . "—\\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 into a
...
." (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%s%s\n
" + (format (if html5-fancy + "\n%s%s\n
" + "\n%s%s\n") id (format "\n

%s

" img) (if (and caption (not (string= caption ""))) - (format "\n

%s

" caption) "")))) + (format (if html5-fancy + "\n
%s
" + "\n

%s

") 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 "
\n%s\n
" - (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" block-type attributes + contents block-type) + (format "\n%s\n" attributes contents)))) ;;;; Src Block -- 1.8.2.2