From 296bbf0f74d0c3d49259e146597a174e7c14fda9 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sat, 13 Apr 2013 13:22:14 +0800 Subject: [PATCH] First stab at exporting to various flavors of HTML. --- lisp/ox-html.el | 151 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 55 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 0ad3dc3..af80707 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -142,6 +142,15 @@ (defvar org-html--pre/postamble-class "status" "CSS class used for pre/postamble") +(defconst org-html-doctype-alist + '(("html4" . "") + ("html4-strict" . " +\"http://www.w3.org/TR/html4/strict.dtd\"") + ("xhtml" . "") + ("html5" . "")) + "An alist mapping (x)html flavors to specific doctypes.") + (defconst org-html-special-string-regexps '(("\\\\-" . "­") ; shy ("---\\([^-]\\)" . "—\\1") ; mdash @@ -747,7 +756,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") @@ -855,7 +866,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") @@ -871,15 +884,14 @@ Use utf-8 as the default value." :package-version '(Org . "8.0") :type 'coding-system) -(defcustom org-html-doctype - "" +(defcustom org-html-doctype "xhtml" "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." :group 'org-export-html :version "24.4" :package-version '(Org . "8.0") - :type 'string) + :type 'string) (defcustom org-html-container-element "div" "HTML element to use for wrapping top level sections. @@ -1034,7 +1046,7 @@ precedence over this variable." '(("en" "

Author: %a (%e)

Date: %d

%c

-

%v

")) +

%v

")) "Alist of languages and format strings for the HTML postamble. The first element of each list is the language code, as used for @@ -1059,7 +1071,7 @@ like that: \"%%\"." :value-type (string :tag "Format string"))) (defcustom org-html-validation-link - "Validate XHTML 1.0" + "Validate" "Link to HTML validation service." :group 'org-export-html :type 'string) @@ -1239,6 +1251,19 @@ CSS classes, then this prefix can be very useful." ;;; 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" "")))) + +(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 @@ -1252,7 +1277,7 @@ attributes with a nil value will be omitted from the result." "\"" """ (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 @@ -1272,12 +1297,14 @@ When STANDALONE-P is t, wrap the into a
...
." (file-name-nondirectory src))))))) (cond (standalone-p - (let ((img (format "" src attr))) + (let ((img (format "%s%s\n" id (format "\n

%s

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

%s

" caption) "")))) - (t (format "" src (concat attr id)))))) + (t (format "%s\n" title) (format @@ -1434,17 +1462,18 @@ INFO is a plist used as a communication channel." (format-time-string (concat "\n")))) (format - "\n" + "\n") - (and author (format "\n" author)) + "iso-8859-1") close) + (format "\n" description)) + (format "\n" keywords))))) + (format ".. of the HTML output. @@ -1457,8 +1486,8 @@ 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 "\n" - (plist-get info :html-htmlized-css-url))) + (format "\n" + (plist-get info :html-htmlized-css-url) (org-html-close-tag info))) (when (plist-get info :html-head-include-scripts) org-html-scripts)))) (defun org-html--build-mathjax-config (info) @@ -1555,7 +1584,7 @@ communication channel." (format-time-string org-html-metadata-timestamp-format))) (when (plist-get info :with-creator) (format "

%s

\n" creator)) - (format "

%s

\n" + (format "

%s

\n" validation-link)))) (t (format-spec (or (cadr (assoc @@ -1597,23 +1626,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 "\n" - (plist-get info :language) (plist-get info :language)) + (concat "\n") "\n" (org-html--build-meta-info info) (org-html--build-head info) @@ -2164,7 +2201,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)) @@ -2222,7 +2259,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." - "
") + (format "[-]") (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 "" extra) - (when headline (concat headline "
"))))) + (when headline (concat headline br))))) (unordered (let* ((id term-counter-id) (extra (if id (format " id=\"%s\"" id) ""))) (concat (format "" extra) - (when headline (concat headline "
"))))) + (when headline (concat headline br))))) (descriptive (let* ((term term-counter-id)) (setq term (or term "(no term)")) @@ -2323,7 +2361,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 @@ -2382,7 +2420,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 @@ -2401,7 +2439,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 @@ -2409,7 +2447,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." - "
\n") + (format "\n" output))) + "\\(\\\\\\\\\\)?[ \t]*\n" + (format "\n" + "^ *\\\\\\\\$" (format "\n" contents))) + "\\(\\\\\\\\\\)?[ \t]*\n" + (format "