From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: Attributes on HTML tables? Date: Sat, 13 Apr 2013 13:31:17 +0800 Message-ID: <8738uvq9ne.fsf@ericabrahamsen.net> References: <86bo9rnj6q.fsf@iro.umontreal.ca> <87ppy66eke.fsf@bzg.ath.cx> <878v4uxjp6.fsf@gmail.com> <87mwtavzgv.fsf@gmail.com> <86fvyy1dsp.fsf@iro.umontreal.ca> <87ehegtsde.fsf@ericabrahamsen.net> <87a9p4e24e.fsf@bzg.ath.cx> <87li8os2w9.fsf@ericabrahamsen.net> <87wqs8b0g7.fsf@bzg.ath.cx> <8661zr7r5a.fsf@iro.umontreal.ca> <877gk7qev2.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:59107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQsxo-0006dC-3c for emacs-orgmode@gnu.org; Sat, 13 Apr 2013 01:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQsxl-0003Rt-Kw for emacs-orgmode@gnu.org; Sat, 13 Apr 2013 01:25:24 -0400 Received: from plane.gmane.org ([80.91.229.3]:44317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQsxl-0003Qf-5S for emacs-orgmode@gnu.org; Sat, 13 Apr 2013 01:25:21 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UQsxk-0001S6-3L for emacs-orgmode@gnu.org; Sat, 13 Apr 2013 07:25:20 +0200 Received: from 114.250.135.240 ([114.250.135.240]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Apr 2013 07:25:20 +0200 Received: from eric by 114.250.135.240 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Apr 2013 07:25:20 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Eric Abrahamsen writes: > François Pinard writes: > >> Bastien writes: >> >>> Eric Abrahamsen writes: >> >>>> The first step is probably to research the differences between xhtml and >>>> html 5. >> >>> Well, I would even skip this step and just hack something usable. I sort of fudged on the below. The upside is that it should be pretty forgiving now: you can set all kinds of strings as your :html-doctype, and it will do a reasonably good job of guessing how to handle it. Barring actual bugs or poor design decisions, what's left to do is: 1. Make sure that inlined script and style chunks are escaped correctly, I seem to remember reading that the commenting/escaping syntax for these chunks varies according to html flavor. 2. I'd like to add the possibility to put an arbitrary :html-container attribute on HTML elements, so that things that would have been wrapped in "div"s can be wrapped in "article", "section", "nav", and so on and so forth. Rick Frankel kindly provided a test file for this, which I've modified below: #+BEGIN_SRC emacs-lisp #+TITLE: HTML 5 Test #+DATE: {{{modification-time(%Y-%m-%d)}}} #+HTML_DOCTYPE: html5 #+BIND: org-html-divs ((preamble "header" "preamble") (content "section" "content") (postamble "footer" "postamble")) * Org HTML5 Test ok? This should be a paragraph with a \\ line break in it. I think * How about a table | col1 | col2 | |------+------| | a | 1 | | b | 2 | Tables can't have attributes in HTML5. * And a list - a - b - c * And an image [[file:1356810947473.jpg]] * A definiton list #+ATTR_HTML: :options html-container article - a :: foo - b :: bar #+END_SRC Please break! I'll provide a properly-written patch when we've sorted it out. E --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-First-stab-at-exporting-to-various-flavors-of-HTML.patch >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 " Okay, I've got a nearly-working patch for this, but I'm falling down > hard on the defcustom. Here's what I thought to do: > > #+BEGIN_SRC emacs-lisp > (defconst org-html-doctype-alist > '((html4 . "") > (html4-strict . " > \"http://www.w3.org/TR/html4/strict.dtd\"") > (xhtml . " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">") > (html5 . "")) > "An alist mapping (x)html flavors to specific doctypes.") > > (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 'i-dont-know-how-to-work-this) > #+END_SRC > > The end result I'm after is: the user can either set org-html-doctype to > a symbol from among the cars org-html-doctype-alist, or he/she can set > it directly to the doctype string. I don't know how to represent that in > a defcustom. > > And of course, if anyone has any better approaches, then speak now or... > speak later. > > Eric --=-=-=--