From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benjamin Beckwith Subject: Re: How to customize the org-mode's BEGIN_SRC HTML output Date: Tue, 24 Aug 2010 09:39:45 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from [140.186.70.92] (port=50198 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OntjD-0006dX-SO for emacs-orgmode@gnu.org; Tue, 24 Aug 2010 09:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ontj9-0002Pi-4y for emacs-orgmode@gnu.org; Tue, 24 Aug 2010 09:39:51 -0400 Received: from mail-qw0-f41.google.com ([209.85.216.41]:41779) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ontj9-0002PX-2p for emacs-orgmode@gnu.org; Tue, 24 Aug 2010 09:39:47 -0400 Received: by qwi4 with SMTP id 4so132877qwi.0 for ; Tue, 24 Aug 2010 06:39:46 -0700 (PDT) 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: emacs-orgmode@gnu.org Hi, I also was interested in posting these blocks (through org2blog in wordpress). The code I posted below is added to 'org-export-preprocess-hooks' where it looks for BEGIN_SRC blocks as well as ':' blocks of code. In the case of BEGIN_SRC blocks, I add a header option, :syntaxhl where I can pass in additional settings to the syntaxhighlighter code. The code below uses Wordpress shortcodes, but I am sure that you can adapt for your own purposes. ------------------------------------------------------------ (defun bnb/org2blog-src-blocks-to-wp-syntaxhighlighter () "Export #+BEGIN_SRC blocks as Wordpress Syntaxhighlighter tags. There is a special header option, :syntaxhl that contains the options to pass to syntaxhighlighter. This is intended to be added to `org-export-preprocess-hooks'" (interactive) (save-window-excursion (let ((case-fold-search t) (colon-re "^[ \t]*:\\([ \t]\\|$\\)") lang body headers syntaxhl beg) (goto-char (point-min)) (while (re-search-forward colon-re nil t) (replace-match (match-string 1)) (beginning-of-line 1) (insert "[text light=\"true\"]\n") (setq beg (point)) (while (looking-at colon-re) (replace-match (match-string 1)) (end-of-line 1) (or (eobp) (forward-char 1))) (end-of-line 1) (add-text-properties beg (if (bolp) (1- (point)) (point)) '(org-protected t)) (insert "\n[/text]")) (unless (boundp 'org-babel-src-block-regexp) (require 'ob)) (while (re-search-forward (concat "\\(" org-babel-src-block-regexp "\\|" org-babel-inline-src-block-regexp "\\)") nil t) (setq lang (match-string-no-properties 3)) (if (string-match "-" lang) (error "SyntaxHighlighter does not support languages with '-' in the names")) (setq headers (match-string-no-properties 5)) (setq body (match-string-no-properties 6)) (save-match-data (setq syntaxhl (if (string-match ":syntaxhl[ ]+\\([^ ]+\\)" headers) (concat " " (replace-regexp-in-string "\;" " " (match-string 1 headers)))))) (replace-match (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n") nil t)))))