emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: How to customize the org-mode's BEGIN_SRC HTML output


From: Benjamin Beckwith
Subject: [Orgmode] Re: How to customize the org-mode's BEGIN_SRC HTML output
Date: Tue, 24 Aug 2010 09:39:45 -0400

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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]