emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Custom XHTML layouts
@ 2009-03-03  9:48 Sebastian Rose
  2009-03-03 10:53 ` Carsten Dominik
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Rose @ 2009-03-03  9:48 UTC (permalink / raw)
  To: emacs-orgmode Org-Mode

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


The appended patch allows for custom layouts of the exported XHTML. As
the custom elements are added literally, PHP code could be added too.

Everyone who's informed about my elisp skills will read this with
appropriate scepticism :)

It's merely a proof of conncept, a suggestion.
Maybe we could find a more `template' based solution to make this easier
on non-lispers.

I didn't implement all the containers mentioned in the docstring of
`org-exp-custom-html-function' yet, but it's just adding two lines per
block.

If you add this patch, you'll be able to do the following:

1.) Define a function that add custom HTML elements.

    This example will produce a table layout with the TOC on the left,
    contents on the right. Title and postamble will span both columns.

    (defun sr-org-export-custom-html(which &optional element-start)
      "See the docs of org-exp-custom-html-function"
      (cond
       ((string= which "body")
        (if element-start
            "<div id=\"wrap\">"
          "</div><!-- end of wrap -->"))
       ((string= which "title")
        (if element-start
            "<table width=\"100%\"><tr><td colspan=\"2\">"
          "</td></tr><tr><td>"))
       ((string= which "toc")
        (if element-start
            ""
          "</td><td>"))
       ((string= which "postamble")
        (if element-start
            "</td></tr><tr><td colspan=\"2\">"
          "</td></tr></table>"))
       ))

2.) Add a line to your `org-publish-project-alist'.


        ("org-notes"
         ;; ....
         :publishing-directory "~/develop/htdocs/org-notes/"
         ;; Tell org-exp.el to use a custom function:
         :publishing-function org-publish-org-to-html
         ;; ....

3.) Apply this patch to the current head:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch to allow for custom elements on export --]
[-- Type: text/x-diff, Size: 3509 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 95b9ad8..239d387 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -3266,6 +3266,18 @@ in a window.  A non-interactive call will only return the buffer."
 
 (defvar html-table-tag nil) ; dynamically scoped into this.
 (defvar org-par-open nil)
+(defun  org-exp-custom-html-function (which &optional before)
+  "If before is non nil, we're about to start which. which is one of:
+        - 'head'
+        - 'body'
+        - 'title'
+        - 'toc'
+        - 'contents'
+        - 'lot'
+        - 'postamble'
+While 'head' and 'body' are called directly after the the starttags and directly before the endtags
+are added, all the others wrap the element/block they are called for."
+  "")
 ;;;###autoload
 (defun org-export-as-html (arg &optional hidden ext-plist
 			       to-buffer body-only pub-dir)
@@ -3311,6 +3323,8 @@ PUB-DIR is set, use this as the publishing directory."
 			"\n" org-export-html-scripts))
 	 (html-extension (plist-get opt-plist :html-extension))
 	 (link-validate (plist-get opt-plist :link-validation-function))
+	 (html-extension (plist-get opt-plist :html-extension))
+	 (custom-html-function (or (plist-get opt-plist :custom-html-function) 'org-exp-custom-html-function))
 	 valid thetoc have-headings first-heading-pos
 	 (odd org-odd-levels-only)
 	 (region-p (org-region-active-p))
@@ -3494,12 +3508,14 @@ lang=\"%s\" xml:lang=\"%s\">
 "
 		 language language (org-html-expand title)
 		 (or charset "iso-8859-1") date author style))
-
+    (insert (funcall custom-html-function "body" t))
 	(insert (or (plist-get opt-plist :preamble) ""))
 
 	(when (plist-get opt-plist :auto-preamble)
-	  (if title (insert (format org-export-html-title-format
-				    (org-html-expand title))))))
+	  (if title (insert (concat
+                         (funcall custom-html-function "title" t)
+                         (format org-export-html-title-format (org-html-expand title))
+                         (funcall custom-html-function "title"))))))
 
       (if (and org-export-with-toc (not body-only))
 	  (progn
@@ -4047,6 +4063,7 @@ lang=\"%s\" xml:lang=\"%s\">
 		"\n"))
       (unless body-only
 	(when (plist-get opt-plist :auto-postamble)
+      (insert (funcall custom-html-function "postamble" t))
 	  (insert "<div id=\"postamble\">")
 	  (when (and org-export-author-info author)
 	    (insert "<p class=\"author\"> "
@@ -4067,11 +4084,13 @@ lang=\"%s\" xml:lang=\"%s\">
 	  (when org-export-creator-info
 	    (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
 			    org-version emacs-major-version)))
-	  (insert "</div>"))
+	  (insert "</div>")
+      (insert (funcall custom-html-function "postamble")))
 
 	(if org-export-html-with-timestamp
 	    (insert org-export-html-html-helper-timestamp))
 	(insert (or (plist-get opt-plist :postamble) ""))
+    (insert (funcall custom-html-function "body"))
 	(insert "</body>\n</html>\n"))
 
       (unless (plist-get opt-plist :buffer-will-be-killed)
@@ -4092,9 +4111,11 @@ lang=\"%s\" xml:lang=\"%s\">
 	  (when (looking-at "\\s-*</p>")
 	    (goto-char (match-end 0))
 	    (insert "\n")))
+    (insert (funcall custom-html-function "toc" t))
 	(insert "<div id=\"table-of-contents\">\n")
 	(mapc 'insert thetoc)
 	(insert "</div>\n"))
+    (insert (funcall custom-html-function "toc"))
       ;; remove empty paragraphs and lists
       (goto-char (point-min))
       (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)

[-- Attachment #3: Type: text/plain, Size: 208 bytes --]




Regards,

--
Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449 Hannover
Tel.:  +49 (0)511 - 36 58 472
Fax:   +49 (0)1805 - 233633 - 11044
mobil: +49 (0)173 - 83 93 417
Http:  www.emma-stil.de

[-- Attachment #4: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Custom XHTML layouts
  2009-03-03  9:48 Custom XHTML layouts Sebastian Rose
@ 2009-03-03 10:53 ` Carsten Dominik
  2009-03-03 11:58   ` Sebastian Rose
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Dominik @ 2009-03-03 10:53 UTC (permalink / raw)
  To: Sebastian Rose; +Cc: emacs-orgmode Org-Mode

This looks interesting.  Do you have application examples?

A more template-like structure would be an alist, with contexts as keys,
and then two string values for the code to be inserted.  Using  
customize, this
could be set up by non-lispers.

- Carsten

On Mar 3, 2009, at 10:48 AM, Sebastian Rose wrote:

>
> The appended patch allows for custom layouts of the exported XHTML. As
> the custom elements are added literally, PHP code could be added too.
>
> Everyone who's informed about my elisp skills will read this with
> appropriate scepticism :)
>
> It's merely a proof of conncept, a suggestion.
> Maybe we could find a more `template' based solution to make this  
> easier
> on non-lispers.
>
> I didn't implement all the containers mentioned in the docstring of
> `org-exp-custom-html-function' yet, but it's just adding two lines per
> block.
>
> If you add this patch, you'll be able to do the following:
>
> 1.) Define a function that add custom HTML elements.
>
>    This example will produce a table layout with the TOC on the left,
>    contents on the right. Title and postamble will span both columns.
>
>    (defun sr-org-export-custom-html(which &optional element-start)
>      "See the docs of org-exp-custom-html-function"
>      (cond
>       ((string= which "body")
>        (if element-start
>            "<div id=\"wrap\">"
>          "</div><!-- end of wrap -->"))
>       ((string= which "title")
>        (if element-start
>            "<table width=\"100%\"><tr><td colspan=\"2\">"
>          "</td></tr><tr><td>"))
>       ((string= which "toc")
>        (if element-start
>            ""
>          "</td><td>"))
>       ((string= which "postamble")
>        (if element-start
>            "</td></tr><tr><td colspan=\"2\">"
>          "</td></tr></table>"))
>       ))
>
> 2.) Add a line to your `org-publish-project-alist'.
>
>
>        ("org-notes"
>         ;; ....
>         :publishing-directory "~/develop/htdocs/org-notes/"
>         ;; Tell org-exp.el to use a custom function:
>         :publishing-function org-publish-org-to-html
>         ;; ....
>
> 3.) Apply this patch to the current head:
>
> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
> index 95b9ad8..239d387 100644
> --- a/lisp/org-exp.el
> +++ b/lisp/org-exp.el
> @@ -3266,6 +3266,18 @@ in a window.  A non-interactive call will  
> only return the buffer."
>
> (defvar html-table-tag nil) ; dynamically scoped into this.
> (defvar org-par-open nil)
> +(defun  org-exp-custom-html-function (which &optional before)
> +  "If before is non nil, we're about to start which. which is one of:
> +        - 'head'
> +        - 'body'
> +        - 'title'
> +        - 'toc'
> +        - 'contents'
> +        - 'lot'
> +        - 'postamble'
> +While 'head' and 'body' are called directly after the the starttags  
> and directly before the endtags
> +are added, all the others wrap the element/block they are called  
> for."
> +  "")
> ;;;###autoload
> (defun org-export-as-html (arg &optional hidden ext-plist
> 			       to-buffer body-only pub-dir)
> @@ -3311,6 +3323,8 @@ PUB-DIR is set, use this as the publishing  
> directory."
> 			"\n" org-export-html-scripts))
> 	 (html-extension (plist-get opt-plist :html-extension))
> 	 (link-validate (plist-get opt-plist :link-validation-function))
> +	 (html-extension (plist-get opt-plist :html-extension))
> +	 (custom-html-function (or (plist-get opt-plist :custom-html- 
> function) 'org-exp-custom-html-function))
> 	 valid thetoc have-headings first-heading-pos
> 	 (odd org-odd-levels-only)
> 	 (region-p (org-region-active-p))
> @@ -3494,12 +3508,14 @@ lang=\"%s\" xml:lang=\"%s\">
> "
> 		 language language (org-html-expand title)
> 		 (or charset "iso-8859-1") date author style))
> -
> +    (insert (funcall custom-html-function "body" t))
> 	(insert (or (plist-get opt-plist :preamble) ""))
>
> 	(when (plist-get opt-plist :auto-preamble)
> -	  (if title (insert (format org-export-html-title-format
> -				    (org-html-expand title))))))
> +	  (if title (insert (concat
> +                         (funcall custom-html-function "title" t)
> +                         (format org-export-html-title-format (org- 
> html-expand title))
> +                         (funcall custom-html-function "title"))))))
>
>       (if (and org-export-with-toc (not body-only))
> 	  (progn
> @@ -4047,6 +4063,7 @@ lang=\"%s\" xml:lang=\"%s\">
> 		"\n"))
>       (unless body-only
> 	(when (plist-get opt-plist :auto-postamble)
> +      (insert (funcall custom-html-function "postamble" t))
> 	  (insert "<div id=\"postamble\">")
> 	  (when (and org-export-author-info author)
> 	    (insert "<p class=\"author\"> "
> @@ -4067,11 +4084,13 @@ lang=\"%s\" xml:lang=\"%s\">
> 	  (when org-export-creator-info
> 	    (insert (format "<p class=\"creator\">HTML generated by org- 
> mode %s in emacs %s</p>\n"
> 			    org-version emacs-major-version)))
> -	  (insert "</div>"))
> +	  (insert "</div>")
> +      (insert (funcall custom-html-function "postamble")))
>
> 	(if org-export-html-with-timestamp
> 	    (insert org-export-html-html-helper-timestamp))
> 	(insert (or (plist-get opt-plist :postamble) ""))
> +    (insert (funcall custom-html-function "body"))
> 	(insert "</body>\n</html>\n"))
>
>       (unless (plist-get opt-plist :buffer-will-be-killed)
> @@ -4092,9 +4111,11 @@ lang=\"%s\" xml:lang=\"%s\">
> 	  (when (looking-at "\\s-*</p>")
> 	    (goto-char (match-end 0))
> 	    (insert "\n")))
> +    (insert (funcall custom-html-function "toc" t))
> 	(insert "<div id=\"table-of-contents\">\n")
> 	(mapc 'insert thetoc)
> 	(insert "</div>\n"))
> +    (insert (funcall custom-html-function "toc"))
>       ;; remove empty paragraphs and lists
>       (goto-char (point-min))
>       (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
>
>
>
> Regards,
>
> --
> Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449  
> Hannover
> Tel.:  +49 (0)511 - 36 58 472
> Fax:   +49 (0)1805 - 233633 - 11044
> mobil: +49 (0)173 - 83 93 417
> Http:  www.emma-stil.de
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Custom XHTML layouts
  2009-03-03 10:53 ` Carsten Dominik
@ 2009-03-03 11:58   ` Sebastian Rose
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Rose @ 2009-03-03 11:58 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode Org-Mode

Carsten Dominik <dominik@science.uva.nl> writes:

> This looks interesting.  Do you have application examples?

Only the one I mentioned in the original message so far. It just wraps
the hole page into a table like this:


  +--------------------+
  | Title              |
  +-----+--------------+
  | toc | sections..   |
  |     |              |
  |     |              |
  +-----+--------------+
  |     postamble      |
  +--------------------+



But I can think of hundreds of applications:

  * It would be easy to add a logo to the title bar,
  * or some debug information to footer for local testing.
  * But no such debug info for the public export to the internet.
  * you're google search on orgmode.org
  * some PHP-functions one might want to execute, e.g. to include
     + a tag cloud
     + additional navigations
     + count visitors
     + track the movement of visitors
     + include a shop system  - just kidding :-D
     ...
  * Clean view of the *.org files. No more
       #+begin_html
         ...
       #+end_html
    or
       @<ul class="external-menu"....
    to include standard stuff, common for all pages.
  * TODO: add the 94 missing applications here


Maybe the settings could be augmented/overwritten on per file basis too?




Regards,

--
Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449 Hannover
Tel.:  +49 (0)511 - 36 58 472
Fax:   +49 (0)1805 - 233633 - 11044
mobil: +49 (0)173 - 83 93 417
Http:  www.emma-stil.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-03 11:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-03  9:48 Custom XHTML layouts Sebastian Rose
2009-03-03 10:53 ` Carsten Dominik
2009-03-03 11:58   ` Sebastian Rose

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).