1 #+TITLE: Marking Up Elements to be Exported
2 #+DESCRIPTION: Dummy Filters for Orgmode Exporter
3 #+AUTHOR: Charles C. Berry
8 Copyright (C) 2013 Charles C. Berry
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 For a copy of the GNU General Public License, see
21 <http://www.gnu.org/licenses/>.
25 * Filters in the Exporter
26 The exporter in =ox.el= has more than 50 elements that can be
27 filtered. Developers can write filters for new backends, and users can
28 write filters to customize output to their individual needs.
30 * Understanding Elements and Filters
31 Figuring out how to craft a filter to customize output requires
32 detailed knowledge of what the elements are and how they are rendered
33 by a backend. It can be fairly difficult to sort this out and keep it
34 all in mind by just reading the code.
36 One way to understand an element and the markup applied to it by an
37 export backend is to write a filter that will mark the element.
39 For example, the function
41 #+BEGIN_SRC emacs-lisp
42 (defun ox-mrkup-filter-bold
44 "Markup TEXT as <bold>TEXT</bold>. Ignore BACK-END and INFO."
45 (format "<bold>%s</bold>" text))
48 will show a bold element inside the tags ~<bold>~ and ~</bold>~.
50 Using that filter with the latex backend will render
53 This text should be in *BOLD*.
58 : This text should be in <bold>\textbf{BOLD}</bold>.
60 * A Complete Set of Filter Functions
61 Here is a complete set of filter functions to provide markup tags.
63 #+begin_src emacs-lisp
64 (defun ox-mrkup-filter-body
66 (format "<body>%s</body>" text))
67 (defun ox-mrkup-filter-bold
69 "Markup TEXT as <bold>TEXT</bold>. Ignore BACK-END and INFO."
70 (format "<bold>%s</bold>" text))
71 (defun ox-mrkup-filter-babel-call
73 (format "<bbl>%s</bbl>" text))
74 (defun ox-mrkup-filter-center-block
76 (format "<cnt>%s</cnt>" text))
77 (defun ox-mrkup-filter-clock
79 (format "<clck>%s</clck>" text))
80 (defun ox-mrkup-filter-code
82 (format "<code>%s</code>" text))
83 (defun ox-mrkup-filter-comment
85 (format "<cmmn>%s</cmmn>" text))
86 (defun ox-mrkup-filter-comment-block
88 (format "<cmm>%s</cmm>" text))
89 (defun ox-mrkup-filter-diary-sexp
91 (format "<dry>%s</dry>" text))
92 (defun ox-mrkup-filter-drawer
94 (format "<drwr>%s</drwr>" text))
95 (defun ox-mrkup-filter-dynamic-block
97 (format "<dyn>%s</dyn>" text))
98 (defun ox-mrkup-filter-entity
100 (format "<entt>%s</entt>" text))
101 (defun ox-mrkup-filter-example-block
103 (format "<exm>%s</exm>" text))
104 (defun ox-mrkup-filter-export-block
106 (format "<exprt-b>%s</exprt-b>" text))
107 (defun ox-mrkup-filter-export-snippet
109 (format "<exprt-s>%s</exprt-s>" text))
110 (defun ox-mrkup-filter-final-output
112 (format "<fnl>%s</fnl>" text))
113 (defun ox-mrkup-filter-fixed-width
115 (format "<fxd>%s</fxd>" text))
116 (defun ox-mrkup-filter-footnote-definition
118 (format "<ftnt-d>%s</ftnt-d>" text))
119 (defun ox-mrkup-filter-footnote-reference
121 (format "<ftnt-r>%s</ftnt-r>" text))
122 (defun ox-mrkup-filter-headline
124 (format "<hdln>%s</hdln>" text))
125 (defun ox-mrkup-filter-horizontal-rule
127 (format "<hrz>%s</hrz>" text))
128 (defun ox-mrkup-filter-inline-babel-call
130 (format "<inln-b>%s</inln-b>" text))
131 (defun ox-mrkup-filter-inline-src-block
133 (format "<inln-s>%s</inln-s>" text))
134 (defun ox-mrkup-filter-inlinetask
136 (format "<inln>%s</inln>" text))
137 (defun ox-mrkup-filter-italic
139 (format "<itlc>%s</itlc>" text))
140 (defun ox-mrkup-filter-item
142 (format "<item>%s</item>" text))
143 (defun ox-mrkup-filter-keyword
145 (format "<kywr>%s</kywr>" text))
146 (defun ox-mrkup-filter-latex-environment
148 (format "<ltx-n>%s</ltx-n>" text))
149 (defun ox-mrkup-filter-latex-fragment
151 (format "<ltx-f>%s</ltx-f>" text))
152 (defun ox-mrkup-filter-line-break
154 (format "<ln-b>%s</ln-b>" text))
155 (defun ox-mrkup-filter-link
157 (format "<link>%s</link>" text))
158 (defun ox-mrkup-filter-node-property
160 (format "<nd-p>%s</nd-p>" text))
161 ;; dont (defun ox-mrkup-filter-options ...)
162 (defun ox-mrkup-filter-paragraph
164 (format "<prgr>%s</prgr>" text))
165 ;; dont (defun ox-mrkup-filter-parse-tree ...)
166 (defun ox-mrkup-filter-plain-list
168 (format "<pln-l>%s</pln-l>" text))
169 (defun ox-mrkup-filter-plain-text
171 (format "<pln-t>%s</pln-t>" text))
172 (defun ox-mrkup-filter-planning
174 (format "<plnn>%s</plnn>" text))
175 (defun ox-mrkup-filter-property-drawer
177 (format "<prp>%s</prp>" text))
178 (defun ox-mrkup-filter-quote-block
180 (format "<qt-b>%s</qt-b>" text))
181 (defun ox-mrkup-filter-radio-target
183 (format "<rd-t>%s</rd-t>" text))
184 (defun ox-mrkup-filter-section
186 (format "<sctn>%s</sctn>" text))
187 (defun ox-mrkup-filter-special-block
189 (format "<spc>%s</spc>" text))
190 (defun ox-mrkup-filter-src-block
192 (format "<src>%s</src>" text))
193 (defun ox-mrkup-filter-statistics-cookie
195 (format "<stt>%s</stt>" text))
196 (defun ox-mrkup-filter-strike-through
198 (format "<str>%s</str>" text))
199 (defun ox-mrkup-filter-subscript
201 (format "<sbsc>%s</sbsc>" text))
202 (defun ox-mrkup-filter-superscript
204 (format "<sprs>%s</sprs>" text))
205 (defun ox-mrkup-filter-table
207 (format "<tabl>%s</tabl>" text))
208 (defun ox-mrkup-filter-table-cell
210 (format "<tbl-c>%s</tbl-c>" text))
211 (defun ox-mrkup-filter-table-row
213 (format "<tbl-r>%s</tbl-r>" text))
214 (defun ox-mrkup-filter-target
216 (format "<trgt>%s</trgt>" text))
217 (defun ox-mrkup-filter-timestamp
219 (format "<tmst>%s</tmst>" text))
220 (defun ox-mrkup-filter-underline
222 (format "<undr>%s</undr>" text))
223 (defun ox-mrkup-filter-verbatim
225 (format "<vrbt>%s</vrbt>" text))
226 (defun ox-mrkup-filter-verse-block
228 (format "<vrs>%s</vrs>" text))
231 * A LaTeX Backend Example
232 Here is a derived backend that will use those tags. This backend takes
233 ~latex~ as its parent, but other backends could be used as well.
234 It is called ~latex2~ and can be used like this:
236 : M-: (org-export-to-buffer 'latex2 "latex-buffer-marked")
240 : M-: (org-export-to-file 'latex2 "latex-file-marked.tex")
243 For many purposes only a subset of these might be needed. So the code
244 could be edited to leave only those filters that are wanted.
246 #+begin_src emacs-lisp
248 (org-export-define-derived-backend 'latex2 'latex
250 '((:filter-body . ox-mrkup-filter-body)
251 (:filter-bold . ox-mrkup-filter-bold)
252 (:filter-babel-call . ox-mrkup-filter-babel-call)
253 (:filter-center-block . ox-mrkup-filter-center-block)
254 (:filter-clock . ox-mrkup-filter-clock)
255 (:filter-code . ox-mrkup-filter-code)
256 (:filter-comment . ox-mrkup-filter-comment)
257 (:filter-comment-block . ox-mrkup-filter-comment-block)
258 (:filter-diary-sexp . ox-mrkup-filter-diary-sexp)
259 (:filter-drawer . ox-mrkup-filter-drawer)
260 (:filter-dynamic-block . ox-mrkup-filter-dynamic-block)
261 (:filter-entity . ox-mrkup-filter-entity)
262 (:filter-example-block . ox-mrkup-filter-example-block)
263 (:filter-export-block . ox-mrkup-filter-export-block)
264 (:filter-export-snippet . ox-mrkup-filter-export-snippet)
265 (:filter-final-output . ox-mrkup-filter-final-output)
266 (:filter-fixed-width . ox-mrkup-filter-fixed-width)
267 (:filter-footnote-definition . ox-mrkup-filter-footnote-definition)
268 (:filter-footnote-reference . ox-mrkup-filter-footnote-reference)
269 (:filter-headline . ox-mrkup-filter-headline)
270 (:filter-horizontal-rule . ox-mrkup-filter-horizontal-rule)
271 (:filter-inline-babel-call . ox-mrkup-filter-inline-babel-call)
272 (:filter-inline-src-block . ox-mrkup-filter-inline-src-block)
273 (:filter-inlinetask . ox-mrkup-filter-inlinetask)
274 (:filter-italic . ox-mrkup-filter-italic)
275 (:filter-item . ox-mrkup-filter-item)
276 (:filter-keyword . ox-mrkup-filter-keyword)
277 (:filter-latex-environment . ox-mrkup-filter-latex-environment)
278 (:filter-latex-fragment . ox-mrkup-filter-latex-fragment)
279 (:filter-line-break . ox-mrkup-filter-line-break)
280 (:filter-link . ox-mrkup-filter-link)
281 (:filter-node-property . ox-mrkup-filter-node-property)
282 ;; omit filter with different args
283 ;; (:filter-options . ox-mrkup-filter-options)
284 (:filter-paragraph . ox-mrkup-filter-paragraph)
285 ;; omit filter with different args
286 ;; (:filter-parse-tree . ox-mrkup-filter-parse-tree)
287 (:filter-plain-list . ox-mrkup-filter-plain-list)
288 (:filter-plain-text . ox-mrkup-filter-plain-text)
289 (:filter-planning . ox-mrkup-filter-planning)
290 (:filter-property-drawer . ox-mrkup-filter-property-drawer)
291 (:filter-quote-block . ox-mrkup-filter-quote-block)
292 (:filter-radio-target . ox-mrkup-filter-radio-target)
293 (:filter-section . ox-mrkup-filter-section)
294 (:filter-special-block . ox-mrkup-filter-special-block)
295 (:filter-src-block . ox-mrkup-filter-src-block)
296 (:filter-statistics-cookie . ox-mrkup-filter-statistics-cookie)
297 (:filter-strike-through . ox-mrkup-filter-strike-through)
298 (:filter-subscript . ox-mrkup-filter-subscript)
299 (:filter-superscript . ox-mrkup-filter-superscript)
300 (:filter-table . ox-mrkup-filter-table)
301 (:filter-table-cell . ox-mrkup-filter-table-cell)
302 (:filter-table-row . ox-mrkup-filter-table-row)
303 (:filter-target . ox-mrkup-filter-target)
304 (:filter-timestamp . ox-mrkup-filter-timestamp)
305 (:filter-underline . ox-mrkup-filter-underline)
306 (:filter-verbatim . ox-mrkup-filter-verbatim)
307 (:filter-verse-block . ox-mrkup-filter-verse-block)))
310 * Options for Adding Filters
311 Users can add filter functions to the lists in ~org-export-filters-alist~
312 and subsequent exports will apply those functions accordingly.
314 Alternatively, writing a derived backend in which the ~:filters-alist~
315 contains an entry such as:
317 : (:filter-bold . ox-mrkup-filter-bold)
319 will result in bold elements being filterd through that function.
321 The advantage of using a derived backend to experiment with filters is
322 that ~org-export-filters-alist~ is not filled with functions that will
323 need to be removed once the experiments have ended.