ox: Implement body filter

* lisp/ox.el (org-export-filters-alist): Add body filter.
(org-export-filter-body-functions): New variable.
(org-export-as): Call body filter.

* doc/org.texi (Advanced configuration):
* etc/ORG-NEWS (argument): Document new filter.
This commit is contained in:
Nicolas Goaziou 2014-09-06 10:22:26 +02:00
parent 1f3c6c2f49
commit c235bd83d2
3 changed files with 61 additions and 43 deletions

View File

@ -13424,63 +13424,63 @@ are all named after the same scheme: @code{org-export-filter-TYPE-functions},
where @code{TYPE} is the type targeted by the filter. Valid types are: where @code{TYPE} is the type targeted by the filter. Valid types are:
@multitable @columnfractions .33 .33 .33 @multitable @columnfractions .33 .33 .33
@item bold @item body
@tab bold
@tab babel-call @tab babel-call
@tab center-block @item center-block
@item clock @tab clock
@tab code @tab code
@tab comment @item comment
@item comment-block @tab comment-block
@tab diary-sexp @tab diary-sexp
@tab drawer @item drawer
@item dynamic-block @tab dynamic-block
@tab entity @tab entity
@tab example-block @item example-block
@item export-block @tab export-block
@tab export-snippet @tab export-snippet
@tab final-output @item final-output
@item fixed-width @tab fixed-width
@tab footnote-definition @tab footnote-definition
@tab footnote-reference @item footnote-reference
@item headline @tab headline
@tab horizontal-rule @tab horizontal-rule
@tab inline-babel-call @item inline-babel-call
@item inline-src-block @tab inline-src-block
@tab inlinetask @tab inlinetask
@tab italic @item italic
@item item @tab item
@tab keyword @tab keyword
@tab latex-environment @item latex-environment
@item latex-fragment @tab latex-fragment
@tab line-break @tab line-break
@tab link @item link
@item node-property @tab node-property
@tab options @tab options
@tab paragraph @item paragraph
@item parse-tree @tab parse-tree
@tab plain-list @tab plain-list
@tab plain-text @item plain-text
@item planning @tab planning
@tab property-drawer @tab property-drawer
@tab quote-block @item quote-block
@item quote-section @tab quote-section
@tab radio-target @tab radio-target
@tab section @item section
@item special-block @tab special-block
@tab src-block @tab src-block
@tab statistics-cookie @item statistics-cookie
@item strike-through @tab strike-through
@tab subscript @tab subscript
@tab superscript @item superscript
@item table @tab table
@tab table-cell @tab table-cell
@tab table-row @item table-row
@item target @tab target
@tab timestamp @tab timestamp
@tab underline @item underline
@item verbatim @tab verbatim
@tab verse-block @tab verse-block
@tab
@end multitable @end multitable
For example, the following snippet allows me to use non-breaking spaces in For example, the following snippet allows me to use non-breaking spaces in

View File

@ -111,6 +111,9 @@ in the output, depending on the parameters.
*** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~ *** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~
These functions now support any element or object, not only headlines. These functions now support any element or object, not only headlines.
*** New function: ~org-export-table-row-in-header-p~ *** New function: ~org-export-table-row-in-header-p~
*** New filter: ~org-export-filter-body-functions~
Functions in this filter are applied on the body of the exported
document, befor wrapping it within the template.
** Miscellaneous ** Miscellaneous
*** File names in links accept are now compatible with URI syntax *** File names in links accept are now compatible with URI syntax
Absolute file names can now start with =///= in addition to =/=. E.g., Absolute file names can now start with =///= in addition to =/=. E.g.,

View File

@ -176,7 +176,8 @@ way they are handled must be hard-coded into
`org-export--get-inbuffer-options' function.") `org-export--get-inbuffer-options' function.")
(defconst org-export-filters-alist (defconst org-export-filters-alist
'((:filter-bold . org-export-filter-bold-functions) '((:filter-body . org-export-filter-body-functions)
(:filter-bold . org-export-filter-bold-functions)
(:filter-babel-call . org-export-filter-babel-call-functions) (:filter-babel-call . org-export-filter-babel-call-functions)
(:filter-center-block . org-export-filter-center-block-functions) (:filter-center-block . org-export-filter-center-block-functions)
(:filter-clock . org-export-filter-clock-functions) (:filter-clock . org-export-filter-clock-functions)
@ -2447,9 +2448,13 @@ Any element in `:ignore-list' will be skipped when using
;; tree. Users can set it through ;; tree. Users can set it through
;; `org-export-filter-parse-tree-functions' variable. ;; `org-export-filter-parse-tree-functions' variable.
;; ;;
;; - `:filter-body' applies to the body of the output, before template
;; translator chimes in. Users can set it through
;; `org-export-filter-body-functions' variable.
;;
;; - `:filter-final-output' applies to the final transcoded string. ;; - `:filter-final-output' applies to the final transcoded string.
;; Users can set it with `org-export-filter-final-output-functions' ;; Users can set it with `org-export-filter-final-output-functions'
;; variable ;; variable.
;; ;;
;; - `:filter-plain-text' applies to any string not recognized as Org ;; - `:filter-plain-text' applies to any string not recognized as Org
;; syntax. `org-export-filter-plain-text-functions' allows users to ;; syntax. `org-export-filter-plain-text-functions' allows users to
@ -2457,7 +2462,7 @@ Any element in `:ignore-list' will be skipped when using
;; ;;
;; - `:filter-TYPE' applies on the string returned after an element or ;; - `:filter-TYPE' applies on the string returned after an element or
;; object of type TYPE has been transcoded. A user can modify ;; object of type TYPE has been transcoded. A user can modify
;; `org-export-filter-TYPE-functions' ;; `org-export-filter-TYPE-functions' to install these filters.
;; ;;
;; All filters sets are applied with ;; All filters sets are applied with
;; `org-export-filter-apply-functions' function. Filters in a set are ;; `org-export-filter-apply-functions' function. Filters in a set are
@ -2520,6 +2525,13 @@ contains no Org syntax, the back-end, as a symbol, and the
communication channel, as a plist. It must return a string or communication channel, as a plist. It must return a string or
nil.") nil.")
(defvar org-export-filter-body-functions nil
"List of functions applied to transcoded body.
Each filter is called with three arguments: a string which
contains no Org syntax, the back-end, as a symbol, and the
communication channel, as a plist. It must return a string or
nil.")
(defvar org-export-filter-final-output-functions nil (defvar org-export-filter-final-output-functions nil
"List of functions applied to the transcoded string. "List of functions applied to the transcoded string.
Each filter is called with three arguments: the full transcoded Each filter is called with three arguments: the full transcoded
@ -3142,8 +3154,11 @@ Return code as a string."
(or (org-export-data tree info) ""))) (or (org-export-data tree info) "")))
(inner-template (cdr (assq 'inner-template (inner-template (cdr (assq 'inner-template
(plist-get info :translate-alist)))) (plist-get info :translate-alist))))
(full-body (if (not (functionp inner-template)) body (full-body (org-export-filter-apply-functions
(funcall inner-template body info))) (plist-get info :filter-body)
(if (not (functionp inner-template)) body
(funcall inner-template body info))
info))
(template (cdr (assq 'template (template (cdr (assq 'template
(plist-get info :translate-alist))))) (plist-get info :translate-alist)))))
;; Remove all text properties since they cannot be ;; Remove all text properties since they cannot be