emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rick Frankel <rick@rickster.com>
To: emacs-orgmode@gnu.org
Subject: Re: [New Exporter] Parameterized wrapper elements
Date: Sat, 9 Mar 2013 11:39:08 -0500	[thread overview]
Message-ID: <20130309163908.GA25341@BigDog.local> (raw)
In-Reply-To: <871ubo3omc.fsf@bzg.ath.cx>

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

On Sat, Mar 09, 2013 at 10:32:11AM +0100, Bastien wrote:
> Hi Rick,

> One thing you may double-check in the meantime is: is it
> compatible with the org-info.js utility?  The default should
> be "yes", even if users can replace "div" by something else
> (e.g. for the needs of specific backends.)

Yes. Checked the code and tested the script. It works on element ids
and not element types, so changing the element type from `div' has no
effect.

The things that will break infojs are changing the following ids:

    - content
    - postamble
    - footnotes
    - table-of-contents
    - text-table-of-content
    - text-{slidenum}
              
Note that the current implementation of `org-html-divs' will
potentially break infojs as well.

Attached is a revised patch with the fixes Nicolas found for the
doc-string and the missing closing element.

rick

[-- Attachment #2: 0001-Parameterize-some-html-content-containers.patch --]
[-- Type: text/plain, Size: 6590 bytes --]

From d539863475c4c1432b2b5de175d587f57b317453 Mon Sep 17 00:00:00 2001
From: Rick Frankel <rick@rickster.com>
Date: Fri, 8 Mar 2013 19:00:21 -0500
Subject: [PATCH] Parameterize some html content containers

* lisp/ox-html.el: (define-backend): Add :html-doctype and
:html-container parameters.
(org-html-doctype): New customization variable for doctype
declaration.
(org-html-container-elemnt): New customization variable for specifying
wrapper container element.
(org-html-div): Change to list of pairs id, element type to allow
setting container element.
(org-html--build-preamble): Modified to use new org-html-div settings.
(org-html--build-postamble): Modified to use new org-html-div settings.
(org-html-template): Modified to use doctype and container-element
settings.
---
 lisp/ox-html.el | 77 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 58 insertions(+), 19 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 829fe28..b1638e6 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -113,6 +113,8 @@
 	       (org-open-file (org-html-export-to-html nil s v b)))))))
   :options-alist
   ((:html-extension nil nil org-html-extension)
+   (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
+   (:html-container "HTML_CONTAINER" nil org-html-container-element)
    (: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)
@@ -859,19 +861,44 @@ Use utf-8 as the default value."
   :package-version '(Org . "8.0")
   :type 'coding-system)
 
-(defcustom org-html-divs '("preamble" "content" "postamble")
-  "The name of the main divs for HTML export.
-This is a list of three strings, the first one for the preamble
-DIV, the second one for the content DIV and the third one for the
-postamble DIV."
+(defcustom org-html-doctype
+  "<!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.
+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 '(list
-	  (string :tag " Div for the preamble:")
-	  (string :tag "  Div for the content:")
-	  (string :tag "Div for the postamble:")))
+  :type 'string)
+
+(defcustom org-html-container-element "div"
+  "Container class to use for wrapping top level sections.
+Can be set with the in-buffer HTML_CONTAINER property or for
+publishing, with :html-container."
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type 'string)
 
+(defcustom org-html-divs
+  '(("preamble"  "div")
+    ("content"   "div")
+    ("postamble" "div"))
+  "Alist of the main divs for HTML export.
+This is a list of three pairs, ID and ELEMENT, the first one
+for the preamble, the second one for the content and the
+third one for the postamble."
+  :group 'org-export-html
+  :version "24.4"
+  :package-version '(Org . "8.0")
+  :type '(list
+	  (list :tag "Preamble"
+		(string :tag "     id") (string :tag "element"))
+	  (list :tag "Content"
+		(string :tag "     id") (string :tag "element"))
+	  (list :tag "Postamble"
+		(string :tag "     id") (string :tag "element"))))
 
 ;;;; Template :: Mathjax
 
@@ -1482,9 +1509,11 @@ INFO is a plist used as a communication channel."
 		    `((?t . ,title) (?a . ,author)
 		      (?d . ,date) (?e . ,email))))))))
 	(when (org-string-nw-p preamble-contents)
-	  (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
+	  (concat (format "<%s id=\"%s\">\n"
+			  (nth 1 (nth 0 org-html-divs))
+			  (nth 0 (nth 0 org-html-divs)))
 		  (org-element-normalize-string preamble-contents)
-		  "</div>\n"))))))
+		  (format "</%s>\n" (nth 1 (nth 0 org-html-divs)))))))))
 
 (defun org-html--build-postamble (info)
   "Return document postamble as a string, or nil.
@@ -1534,9 +1563,11 @@ INFO is a plist used as a communication channel."
 			     (?v . ,html-validation-link)))))))))
 	(when (org-string-nw-p postamble-contents)
 	  (concat
-	   (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
+	   (format "<%s id=\"%s\">\n"
+		   (nth 1 (nth 2 org-html-divs))
+		   (nth 0 (nth 2 org-html-divs)))
 	   (org-element-normalize-string postamble-contents)
-	   "</div>\n"))))))
+	   (format "</%s>\n" (nth 1 (nth 2 org-html-divs)))))))))
 
 (defun org-html-inner-template (contents info)
   "Return body of document string after HTML conversion.
@@ -1571,8 +1602,8 @@ holding export options."
 	     (coding-system-get org-html-coding-system 'mime-charset))
 	"iso-8859-1"))
    "\n"
-   "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
-	       \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
+   (plist-get info :html-doctype)
+   "\n"
    (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
 	   (plist-get info :language) (plist-get info :language))
    "<head>\n"
@@ -1590,12 +1621,14 @@ holding export options."
    ;; Preamble.
    (org-html--build-preamble info)
    ;; Document contents.
-   (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
+   (format "<%s id=\"%s\">\n"
+	   (nth 1 (nth 1 org-html-divs))
+	   (nth 0 (nth 1 org-html-divs)))
    ;; Document title.
    (let ((title (plist-get info :title)))
      (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
    contents
-   "</div>\n"
+   (format "</%s>\n" (nth 1 (nth 1 org-html-divs)))
    ;; Postamble.
    (org-html--build-postamble info)
    ;; Closing document.
@@ -2157,7 +2190,10 @@ holding contextual information."
 	     (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
 	     (level1 (+ level (1- org-html-toplevel-hlevel)))
 	     (first-content (car (org-element-contents headline))))
-	(format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
+	(format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
+		(if (= 1 (org-export-get-relative-level headline info))
+		    (plist-get info :html-container)
+		  "div")
 		(format "outline-container-%s"
 			(or (org-element-property :CUSTOM_ID headline)
 			    section-number))
@@ -2181,7 +2217,10 @@ holding contextual information."
 		(if (not (eq (org-element-type first-content) 'section))
 		    (concat (org-html-section first-content "" info)
 			    contents)
-		  contents)))))))
+		  contents)
+		(if (= 1 (org-export-get-relative-level headline info))
+		    (plist-get info :html-container)
+		  "div")))))))
 
 
 ;;;; Horizontal Rule
-- 
1.8.1.5


  reply	other threads:[~2013-03-09 16:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09  0:17 [New Exporter] Parameterized wrapper elements Rick Frankel
2013-03-09  0:46 ` Nicolas Goaziou
2013-03-09 16:07   ` Rick Frankel
2013-03-09  2:33 ` Jambunathan K
2013-03-09  9:32 ` Bastien
2013-03-09 16:39   ` Rick Frankel [this message]
2013-03-09 17:15     ` Jambunathan K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130309163908.GA25341@BigDog.local \
    --to=rick@rickster.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).