From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: Embedding the style when exporting to HTML Date: Sun, 19 Dec 2010 09:25:37 +0100 Message-ID: <4D0DC181.80406@christianmoe.com> References: <87mxo8mh1i.fsf@mundaneum.com> <4D07C587.9030407@christianmoe.com> Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=56846 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PUEY7-00007Y-NV for emacs-orgmode@gnu.org; Sun, 19 Dec 2010 03:23:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PUEXy-0005rJ-Ga for emacs-orgmode@gnu.org; Sun, 19 Dec 2010 03:23:15 -0500 Received: from mars.hitrost.net ([91.185.211.18]:53868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PUEXy-0005qm-5k for emacs-orgmode@gnu.org; Sun, 19 Dec 2010 03:23:14 -0500 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Francesco Pizzolante Cc: mailing-list-org-mode 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: >> >> 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 +") (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\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: The contents of the stylesheet(s) will be embedded in the exported HTML between