Hello, I would like to inline a css when exporting a file to html, but I don't know how to tell org-mode to set the variable org-html-head from within the file. Here is what I tried: I added the following block at the beginning of my file: --8<---------------cut here---------------start------------->8--- #+BEGIN_SRC emacs-lisp :exports none (set (make-local-variable 'org-html-head) (concat "<style type=\"text/css\">\n" "<!--/*--><![CDATA[/*><!--*/\n" (with-temp-buffer (insert-file-contents "style.css") (buffer-string)) "/*]]>*/-->\n" "</style>\n")) #+END_SRC --8<---------------cut here---------------end--------------->8--- It does not seem to be evaluated, however. Is there a way to have arbitrary code stored in the file being exported being evaluated before an export? Thanks, Alan
Hi Alan,
Alan Schmitt writes:
> Is there a way to have arbitrary code stored in the file being exported
> being evaluated before an export?
I think you can use org-export-before-processing-hook for this.
"""
12.13 Advanced configuration
============================
Hooks
-----
Two hooks are run during the first steps of the export process. The
first one, 'org-export-before-processing-hook' is called before
expanding macros, Babel code and include keywords in the buffer. The
second one, 'org-export-before-parsing-hook', as its name suggests,
happens just before parsing the buffer. Their main use is for heavy
duties, that is duties involving structural modifications of the
document. For example, one may want to remove every headline in the
buffer during export.
"""
Myles
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> I would like to inline a css when exporting a file to html, but I don't
> know how to tell org-mode to set the variable org-html-head from within
> the file.
>
> Here is what I tried: I added the following block at the beginning of my
> file:
>
> #+BEGIN_SRC emacs-lisp :exports none
> (set (make-local-variable 'org-html-head) (concat
> "<style type=\"text/css\">\n"
> "<!--/*--><![CDATA[/*><!--*/\n"
> (with-temp-buffer
> (insert-file-contents "style.css")
> (buffer-string))
> "/*]]>*/-->\n"
> "</style>\n"))
> #+END_SRC
>
> It does not seem to be evaluated, however.
>
> Is there a way to have arbitrary code stored in the file being exported
> being evaluated before an export?
I think this has to do with ":exports none", which means that code will
not be evaluated during export. You may want to try setting the
attribute to some other value, and put the block in a :noexport: entry.
Regards,
--
Nicolas Goaziou
mylesenglish@gmail.com writes:
> Hi Alan,
>
> Alan Schmitt writes:
>
>> Is there a way to have arbitrary code stored in the file being exported
>> being evaluated before an export?
>
> I think you can use org-export-before-processing-hook for this.
Thank you for the suggestion. My question would then be: how do I set
the hook from within the file being exported? (And the answer is: apply
Nicolas's suggestion, it worked.)
Alan
n.goaziou@gmail.com writes:
> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I would like to inline a css when exporting a file to html, but I don't
>> know how to tell org-mode to set the variable org-html-head from within
>> the file.
>>
>> Here is what I tried: I added the following block at the beginning of my
>> file:
>>
>> #+BEGIN_SRC emacs-lisp :exports none
>> (set (make-local-variable 'org-html-head) (concat
>> "<style type=\"text/css\">\n"
>> "<!--/*--><![CDATA[/*><!--*/\n"
>> (with-temp-buffer
>> (insert-file-contents "style.css")
>> (buffer-string))
>> "/*]]>*/-->\n"
>> "</style>\n"))
>> #+END_SRC
>>
>> It does not seem to be evaluated, however.
>>
>> Is there a way to have arbitrary code stored in the file being exported
>> being evaluated before an export?
>
> I think this has to do with ":exports none", which means that code will
> not be evaluated during export. You may want to try setting the
> attribute to some other value, and put the block in a :noexport: entry.
Thanks a lot, this was it.
Alan
Alan Schmitt <alan.schmitt@polytechnique.org> writes: > n.goaziou@gmail.com writes: > >> Hello, >> >> Alan Schmitt <alan.schmitt@polytechnique.org> writes: >> >>> I would like to inline a css when exporting a file to html, but I don't >>> know how to tell org-mode to set the variable org-html-head from within >>> the file. >>> >>> Here is what I tried: I added the following block at the beginning of my >>> file: >>> >>> #+BEGIN_SRC emacs-lisp :exports none >>> (set (make-local-variable 'org-html-head) (concat >>> "<style type=\"text/css\">\n" >>> "<!--/*--><![CDATA[/*><!--*/\n" >>> (with-temp-buffer >>> (insert-file-contents "style.css") >>> (buffer-string)) >>> "/*]]>*/-->\n" >>> "</style>\n")) >>> #+END_SRC >>> >>> It does not seem to be evaluated, however. >>> >>> Is there a way to have arbitrary code stored in the file being exported >>> being evaluated before an export? >> >> I think this has to do with ":exports none", which means that code will >> not be evaluated during export. You may want to try setting the >> attribute to some other value, and put the block in a :noexport: entry. > > Thanks a lot, this was it. > Just for completeness, another option may be the following set of header arguments. #+begin_src emacs-lisp :exports results :results none ;; code executed for side effects #+end_src Cheers, -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D