Browse Source

Support custom formatters for marking up source or example blocks

PATCH-3/5 org-odt compatibility patch

From a7881b8d146ddb27452b00ff19c345899d356536 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Thu, 23 Jun 2011 11:24:32 +0530
Subject: [PATCH 3/5] Support custom formatters for marking up source or example blocks.

* lisp/org-exp.el (org-export-format-source-code-or-example):
Add support for:
- custom formatters for existing backends
- seamless plugging in of new backends.
Jambunathan K 14 năm trước cách đây
mục cha
commit
f0177f4a11
1 tập tin đã thay đổi với 22 bổ sung1 xóa
  1. 22 1
      lisp/org-exp.el

+ 22 - 1
lisp/org-exp.el

@@ -2473,6 +2473,16 @@ in the list) and remove property and value from the list in LISTVAR."
 (defun org-export-format-source-code-or-example
   (lang code &optional opts indent caption)
   "Format CODE from language LANG and return it formatted for export.
+The CODE is marked up in `org-export-current-backend' format.
+
+Check if a function by name
+\"org-<backend>-format-source-code-or-example\" is bound. If yes,
+use it as the custom formatter. Otherwise, use the default
+formatter. Default formatters are provided for docbook, html,
+latex and ascii backends. For example, use
+`org-html-format-source-code-or-example' to provide a custom
+formatter for export to \"html\".
+
 If LANG is nil, do not add any fontification.
 OPTS contains formatting options, like `-n' for triggering numbering lines,
 and `+n' for continuing previous numbering.
@@ -2480,7 +2490,15 @@ Code formatting according to language currently only works for HTML.
 Numbering lines works for all three major backends (html, latex, and ascii).
 INDENT was the original indentation of the block."
   (save-match-data
-    (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
+    (let* ((backend-name (symbol-name org-export-current-backend))
+	   (backend-formatter
+	    (intern (format "org-%s-format-source-code-or-example"
+			    backend-name)))
+	   (backend-feature (intern (concat "org-" backend-name)))
+	   (backend-formatter
+	    (and (require (intern (concat "org-" backend-name)) nil)
+		 (fboundp backend-formatter) backend-formatter))
+	   num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
       (setq opts (or opts "")
 	    num (string-match "[-+]n\\>" opts)
 	    cont (string-match "\\+n\\>" opts)
@@ -2517,6 +2535,9 @@ INDENT was the original indentation of the block."
       ;; Now backend-specific coding
       (setq rtn
 	    (cond
+	     (backend-formatter
+	      (funcall backend-formatter lang caption textareap cols rows num
+		       cont rpllbl fmt))
 	     ((eq org-export-current-backend 'docbook)
 	      (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
 	      (concat "\n#+BEGIN_DOCBOOK\n"