Next: , Previous: , Up: Working with source code   [Contents][Index]

14.3 Exporting code blocks

Org can flexibly export just the code from the code blocks, just the results of evaluation of the code block, both the code and the results of the code block evaluation, or none. Org defaults to exporting code for most languages. For some languages, such as ditaa, Org defaults to results. To export just the body of code blocks, see Literal examples. To selectively export sub-trees of an Org document, see Exporting.

The :exports header arguments control exporting code blocks only and not inline code:

Header arguments:

:exports code

This is the default for most languages where the body of the code block is exported. See Literal examples for more.

:exports results

On export, Org includes only the results and not the code block. After each evaluation, Org inserts the results after the end of code block in the Org buffer. By default, Org replaces any previous results. Org can also append results.

:exports both

Org exports both the code block and the results.

:exports none

Org does not export the code block nor the results.

To stop Org from evaluating code blocks to speed exports, use the header argument :eval never-export (see eval). To stop Org from evaluating code blocks for greater security, set the org-export-use-babel variable to nil, but understand that header arguments will have no effect.

Turning off evaluation comes in handy when batch processing. For example, markup languages for wikis, which have a high risk of untrusted code. Stopping code block evaluation also stops evaluation of all header arguments of the code block. This may not be desirable in some circumstances. So during export, to allow evaluation of just the header arguments but not any code evaluation in the source block, set :eval never-export (see eval).

Org never evaluates code blocks in commented sub-trees when exporting (see Comment lines). On the other hand, Org does evaluate code blocks in sub-trees excluded from export (see Export settings).

Next: , Previous: , Up: Working with source code   [Contents][Index]