From c235bd83d2aa7071e643d25735026638ca0d7973 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 6 Sep 2014 10:22:26 +0200 Subject: [PATCH] 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. --- doc/org.texi | 76 ++++++++++++++++++++++++++-------------------------- etc/ORG-NEWS | 3 +++ lisp/ox.el | 25 +++++++++++++---- 3 files changed, 61 insertions(+), 43 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index fafa93b36..7a3ce4e6f 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -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: @multitable @columnfractions .33 .33 .33 -@item bold +@item body +@tab bold @tab babel-call -@tab center-block -@item clock +@item center-block +@tab clock @tab code -@tab comment -@item comment-block +@item comment +@tab comment-block @tab diary-sexp -@tab drawer -@item dynamic-block +@item drawer +@tab dynamic-block @tab entity -@tab example-block -@item export-block +@item example-block +@tab export-block @tab export-snippet -@tab final-output -@item fixed-width +@item final-output +@tab fixed-width @tab footnote-definition -@tab footnote-reference -@item headline +@item footnote-reference +@tab headline @tab horizontal-rule -@tab inline-babel-call -@item inline-src-block +@item inline-babel-call +@tab inline-src-block @tab inlinetask -@tab italic -@item item +@item italic +@tab item @tab keyword -@tab latex-environment -@item latex-fragment +@item latex-environment +@tab latex-fragment @tab line-break -@tab link -@item node-property +@item link +@tab node-property @tab options -@tab paragraph -@item parse-tree +@item paragraph +@tab parse-tree @tab plain-list -@tab plain-text -@item planning +@item plain-text +@tab planning @tab property-drawer -@tab quote-block -@item quote-section +@item quote-block +@tab quote-section @tab radio-target -@tab section -@item special-block +@item section +@tab special-block @tab src-block -@tab statistics-cookie -@item strike-through +@item statistics-cookie +@tab strike-through @tab subscript -@tab superscript -@item table +@item superscript +@tab table @tab table-cell -@tab table-row -@item target +@item table-row +@tab target @tab timestamp -@tab underline -@item verbatim +@item underline +@tab verbatim @tab verse-block -@tab @end multitable For example, the following snippet allows me to use non-breaking spaces in diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 2b11b428a..a17979895 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -111,6 +111,9 @@ in the output, depending on the parameters. *** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~ These functions now support any element or object, not only headlines. *** 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 *** File names in links accept are now compatible with URI syntax Absolute file names can now start with =///= in addition to =/=. E.g., diff --git a/lisp/ox.el b/lisp/ox.el index 0c0b275ef..235b0abac 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -176,7 +176,8 @@ way they are handled must be hard-coded into `org-export--get-inbuffer-options' function.") (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-center-block . org-export-filter-center-block-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 ;; `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. ;; Users can set it with `org-export-filter-final-output-functions' -;; variable +;; variable. ;; ;; - `:filter-plain-text' applies to any string not recognized as Org ;; 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 ;; 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 ;; `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 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 "List of functions applied to the transcoded string. 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) ""))) (inner-template (cdr (assq 'inner-template (plist-get info :translate-alist)))) - (full-body (if (not (functionp inner-template)) body - (funcall inner-template body info))) + (full-body (org-export-filter-apply-functions + (plist-get info :filter-body) + (if (not (functionp inner-template)) body + (funcall inner-template body info)) + info)) (template (cdr (assq 'template (plist-get info :translate-alist))))) ;; Remove all text properties since they cannot be