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 23:32:01 -0400

Rafael,

I had my shortcodes setup to accept the language directly. Your change
should work as you indicated.  I have an additional fix to my code that
should behave better for you.  I add a property, org-protected, that
prevents processing of the text.

I tried it on your code blocks by calling org-export directly (C-c C-e)
and then choosing 'H' to see the html in a buffer.  This really helps
with debug.

Fixed code follows
----------------------------------------------------
(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 block
          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))))))
        (setq block (concat "\n\n[" lang syntaxhl "]\n" body "[/" lang "]\n"))
        (add-text-properties 0 (length block) '(org-protected t) block)
        (replace-match
         block
         nil t)))))
----------------------------------

I also remembered that I made the following setting as well, but I do
not know if I still need it.

(setq org-export-preprocess-hook
      (list
       'bnb/org2blog-src-blocks-to-wp-syntaxhighlighter
       'org-export-blocks-preprocess))



reply via email to

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