* Patch: HTML body onload/onunload attribute support for new exporter
@ 2012-10-17 13:20 Robert Klein
2012-10-17 13:50 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: Robert Klein @ 2012-10-17 13:20 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 323 bytes --]
Hallo,
I created a patch for the new exporter, so I can adding onload and
onunload attributes to the body tag in HTML export.
I'm rather new to emacs lisp, please check if this is to be included in
org-mode.
Best regards
Robert
--
Robert Klein - Max Planck-Institut für Polymerforschung
Ackermannweg 10
55128 Mainz
[-- Attachment #2: html-e-body-onload.diff --]
[-- Type: text/x-patch, Size: 2276 bytes --]
diff --git a/contrib/lisp/org-e-html.el b/contrib/lisp/org-e-html.el
index fcdf006..78582a5 100644
--- a/contrib/lisp/org-e-html.el
+++ b/contrib/lisp/org-e-html.el
@@ -132,7 +132,9 @@
(:html-table-tag nil nil org-e-html-table-tag)
(:xml-declaration nil nil org-e-html-xml-declaration)
(:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)
- (:mathjax "MATHJAX" nil "" space)))
+ (:mathjax "MATHJAX" nil "" space)
+ (:html-body-onload nil nil org-e-html-body-onload)
+ (:html-body-onunload nil nil org-e-html-body-onunload)))
\f
@@ -996,6 +998,33 @@ CSS classes, then this prefix can be very useful."
:type 'string)
+;;;; Template :: body-onload
+
+(defcustom org-e-html-body-onload nil
+ "Additional onload attribute for HTML body tags.
+The value of this variable is inserted in a onload attribute of
+the body tag in the HTML buffer. Use this variable to include
+script code to be executed after loading the HTML page."
+ :group 'org-export-e-html
+ :type '(choice
+ (const :tag "No preamble" nil)
+ ((string ) :tag "Custom string")))
+
+
+;;;; Template :: body-onunload
+
+(defcustom org-e-html-body-onunload nil
+ "Additional onunload attribute for HTML body tags.
+The value of this variable is inserted in a onunload attribute of
+the body tag in the HTML buffer. Use this variable to include
+script code to be executed when leaving the HTML page."
+ :group 'org-export-e-html
+ :type '(choice
+ (const :tag "No preamble" nil)
+ ((string ) :tag "Custom string")))
+
+
+
\f
;;; Internal Functions
@@ -1422,7 +1451,16 @@ holding export options."
(org-e-html--build-style info)
(org-e-html--build-mathjax-config info)
"</head>\n"
- "<body>\n"
+ "<body"
+ (let ((body-onload (plist-get info :html-body-onload)))
+ (when body-onload
+ (if (stringp body-onload)
+ (format " onload=\"%s\"" body-onload))))
+ (let ((body-onunload (plist-get info :html-body-onunload)))
+ (when body-onunload
+ (if (stringp body-onunload)
+ (format " onunload=\"%s\"" body-onunload))))
+ ">\n"
(let ((link-up (org-trim (plist-get info :link-up)))
(link-home (org-trim (plist-get info :link-home))))
(unless (and (string= link-up "") (string= link-up ""))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Patch: HTML body onload/onunload attribute support for new exporter
2012-10-17 13:20 Patch: HTML body onload/onunload attribute support for new exporter Robert Klein
@ 2012-10-17 13:50 ` Nicolas Goaziou
2012-10-18 9:42 ` Robert Klein
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2012-10-17 13:50 UTC (permalink / raw)
To: Robert Klein; +Cc: emacs-orgmode
Hello,
Robert Klein <kleinrob@mpip-mainz.mpg.de> writes:
> I created a patch for the new exporter, so I can adding onload and
> onunload attributes to the body tag in HTML export.
>
>
> I'm rather new to emacs lisp, please check if this is to be included
> in org-mode.
Before reviewing the patch, I'd like to know if the onload and onunload
attributes are common enough to justify the creation of a variable.
Indeed, it's already quite easy to achieve the same using personal
filters. I.e.:
#+begin_src emacs-lisp
(defun my-html-body-onload-filter (output backend info)
"Add my onload attribute to <body> tag, if any."
(when (and (eq backend 'e-html)
(string-match "<body>\n" output))
(replace-match "<body onLoad=\"anything\">\n" nil nil output)))
(add-to-list 'org-export-filter-final-output-functions
'my-html-body-onload-filter)
#+end_src
If you think it's still worth adding variables in order to make it a tad
bit easier, I'll review the patch.
Thanks for your work.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Patch: HTML body onload/onunload attribute support for new exporter
2012-10-17 13:50 ` Nicolas Goaziou
@ 2012-10-18 9:42 ` Robert Klein
0 siblings, 0 replies; 3+ messages in thread
From: Robert Klein @ 2012-10-18 9:42 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Hallo,
On 10/17/2012 03:50 PM, Nicolas Goaziou wrote:
> Hello,
>
> Robert Klein<kleinrob@mpip-mainz.mpg.de> writes:
>
>> I created a patch for the new exporter, so I can adding onload and
>> onunload attributes to the body tag in HTML export.
>>
>>
>> I'm rather new to emacs lisp, please check if this is to be included
>> in org-mode.
>
> Before reviewing the patch, I'd like to know if the onload and onunload
> attributes are common enough to justify the creation of a variable.
> Indeed, it's already quite easy to achieve the same using personal
> filters. I.e.:
>
> #+begin_src emacs-lisp
> (defun my-html-body-onload-filter (output backend info)
> "Add my onload attribute to<body> tag, if any."
> (when (and (eq backend 'e-html)
> (string-match "<body>\n" output))
> (replace-match "<body onLoad=\"anything\">\n" nil nil output)))
>
> (add-to-list 'org-export-filter-final-output-functions
> 'my-html-body-onload-filter)
> #+end_src
>
> If you think it's still worth adding variables in order to make it a tad
> bit easier, I'll review the patch.
>
> Thanks for your work.
>
The onload/onunload attributes probably aren't that much used. If
you're doing a lot of javascript on a web page they are useful.
Better not to include this in org-mode. I'll investigate the use of a
filter for myself.
Thanks and best regards
Robert
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-18 9:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-17 13:20 Patch: HTML body onload/onunload attribute support for new exporter Robert Klein
2012-10-17 13:50 ` Nicolas Goaziou
2012-10-18 9:42 ` Robert Klein
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).