Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:Working with Source Code   [Contents][Index]


16.7 Exporting Code Blocks

It is possible to export thecode of code blocks, theresults ofcode block evaluation,both the code and the results of code blockevaluation, ornone. Org defaults to exportingcode for mostlanguages andresults for inline code blocks. For some languages,such as ditaa, Org defaults toresults both in ordinary sourceblocks and in inline source blocks. To export just the body of codeblocks, seeLiteral Examples. To selectively export subtrees of anOrg document, seeExporting.

The ‘exports’ header argument is to specify if that part of the Orgfile is exported to, say, HTML or LaTeX formats.

code

The default. The body of code is included into the exported file.Example: ‘:exports code’.

results

The results of evaluation of the code is included in the exportedfile. Example: ‘:exports results’.

both

Both the code and results of evaluation are included in the exportedfile. Example: ‘:exports both’.

none

Neither the code nor the results of evaluation is included in theexported file. Whether the code is evaluated at all depends onother options. Example: ‘:exports none’.

If a source block is named using ‘NAME’ keyword, the same name will beassigned to the results of evaluation. This way, fuzzy links pointingto the named source blocks exported using ‘:exports results’ willremain valid and point to the results of evaluation.

Results of evaluation of a named block can also be explicitly namedusing a separate ‘NAME’ keyword. The name value set via ‘NAME’keyword will be preferred over the parent source block.

#+NAME: code name#+BEGIN_SRC emacs-lisp :exports both value(+ 1 2)#+END_SRC#+NAME: results name#+RESULTS: code name3This [[code name][link]] will point to the code block.Another [[results name][link]] will point to the results.

Explicit setting of the result name may be necessary when a named codeblock is exported using ‘:exports both’. Links to such block mayarbitrarily point either to the code block or to its results whenresults do not have a distinct name.

Note that all the links pointing to a source block exported using‘:exports none’ will be broken. This will make export process fail,unless broken links are allowed during export (seeExport Settings).

To stop Org from evaluating code blocks to speed exports, use theheader argument ‘:eval never-export’ (seeEvaluating Code Blocks).To stop Org from evaluating code blocks for greater security, set theorg-export-use-babel variable tonil, but understand that headerarguments will have no effect.

Turning off evaluation comes in handy when batch processing. Forexample, markup languages for wikis, which have a high risk ofuntrusted code. Stopping code block evaluation also stops evaluationof all header arguments of the code block. This may not be desirablein some circumstances. So during export, to allow evaluation of justthe header arguments but not any code evaluation in the source block,set ‘:eval never-export’ (seeEvaluating Code Blocks).

Org never evaluates code blocks in commented subtrees when exporting(seeComment Lines). On the other hand, Org does evaluate codeblocks in subtrees excluded from export (seeExport Settings).


Next:Extracting Source Code, Previous:Results of Evaluation, Up:Working with Source Code   [Contents][Index]


[8]ページ先頭

©2009-2025 Movatter.jp