On 12/14/10 10:05 PM, Francesco Pizzolante wrote:
Hi Christian,

The following would make the exported HTML link to an external stylesheet.

#+STYLE:<link rel="stylesheet" type="text/css" href="my_style.css"/>

But that 's not what you're after? You want the stylesheet to be /outside/
(linked from) your Org file, but /embedded in/ the exported HTML? Did I get
that right?

Indeed. That would be the ideal solution for me: it would bring all the
advantages I'm looking for:

- separate files for developing separately the style and the content;

- anybody could export the file as no special Emacs configuration is needed;

- the exported file would be self-contained.

Do you think about one way of doing this?

Something roughly along these lines, perhaps (warning: I'm still fairly new to Elisp and this comes with ABSOLUTELY NO WARRANTY):

#+BEGIN_SRC emacs-lisp
  (defun cm/org-export-html-embed-style ()
    (make-local-variable 'org-export-html-style)
    (setq org-export-html-style "")
(let ((re "#\\+STYLE:\\s +<link\\s +rel=[\"']stylesheet[\"']\\s +type=[\"']text/css[\"']\\s +href=[\"']\\(.*\\)[\"']/>")
          (oldbuf (current-buffer))
          stylesheet
          css)
      (goto-char (point-min))
      (while (re-search-forward re (point-max) t)
        (setq stylesheet (match-string 1))
          (with-current-buffer (find-file stylesheet)
(setq css (format "\n<style>\n%s\n</style>\n" (buffer-string)))) (setq org-export-html-style (concat org-export-html-style css)))
      (switch-to-buffer oldbuf)))

  (org-add-hook 'org-export-first-hook 'cm/org-export-html-embed-style)
#+END_SRC

Usage: Link to one or more external stylesheets from your Org file.

: #+STYLE: <link rel='stylesheet' type='text/css' href='test5.css'/>

The contents of the stylesheet(s) will be embedded in the exported HTML between <style> tags.

The function swaps the ontent of the external stylesheets into org-export-html-style. If you're already using that variable, the above might screw things up. I'd prefer to use org-export-html-style-extra, but for some reason that didn't work..

This function doesn't remove the links to the external stylesheets, because it operates on the original document, not on a copy. You could add an org-export-preprocess-hook to remove the links, reusing the regexp from this example. (Running the above function as an org-export-preprocess-hook does not work.)

Hope this helps,
CM



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

Reply via email to