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)))))
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
[email protected]
http://lists.gnu.org/mailman/listinfo/emacs-orgmode