0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-25 09:32:51 +00:00

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.
This commit is contained in:
Jambunathan K 2011-06-23 21:24:32 +05:30 committed by Carsten Dominik
parent 67da474db5
commit f0177f4a11

View file

@ -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"