3

I have the following code within an org file:

#+BEGIN_SRC emacs-lisp :exports both :results none :eval export
(defun my-html-body-onload-filter (output backend info)
  "Add my onload attribute to<body>  tag, if any."
  (when (and (eq backend 'html)
             (string-match "<body>\n" output))
    (replace-match "<body onLoad=\"setUp();\">\n" nil nil output)))

(add-to-list 'org-export-filter-final-output-functions
           'my-html-body-onload-filter)
#+END_SRC

The problem with this setup is that it permanently adds this function to the list, so that every org-mode file that I export goes through the same filters.

How can I make these filters file local? I tried using the following too, but it didn't work, i.e., the export was not filtered:

# Local variables:
# eval: (add-to-list 'org-export-filter-final-output-functions 'my-html-body-onload-filter)
# End:
3

Add (make-variable-buffer-local 'org-export-filter-final-output-functions) to your source block. This will make changes to the variable local to the current buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.