Home

Code Chunk

This is an executable code block used in Stencila Schema, analogous to notebook code cells and executable code fences in other authoring systems.

It extends CodeExecutable to support execution outputs, captions, automatic labeling, and optional SVG overlays for figures and tables derived from code. This makes code chunks central to literate programming and executable document workflows in Stencila.

Key properties include outputs, caption, labelType, label, overlay, and inherited execution properties from CodeExecutable.

Analogues

The following external types, elements, or nodes are similar to a CodeChunk:

  • Jupyter notebook code cell: Closest executable-authoring analogue for a code cell with outputs, though Stencila additionally supports captions, labels, and overlays.

  • MyST directive code-cell: Close MyST analogue for executable code blocks in document authoring.

Properties

The CodeChunk type has these properties:

NameDescriptionTypeInherited from
labelTypeThe type of the label for the chunk.LabelType-
labelA short label for the chunk.String-
labelAutomaticallyWhether the label should be automatically updated.Boolean-
captionA caption for the chunk.Block*-
overlayAn optional SVG overlay rendered on top of the chunk's visual content. The SVG is positioned absolutely over the content area and scales proportionally using the SVG viewBox. Used for annotations such as arrows, callouts, bounding boxes, and labels.String-
overlayCompiledThe compiled SVG overlay with all custom elements expanded to standard SVG. Generated during compilation from the overlay source. When present, renderers use this instead of overlay.String-
overlayCompilationDigestA digest of the overlay property.CompilationDigest-
overlayCompilationMessagesMessages generated while compiling the overlay.CompilationMessage*-
outputsOutputs from executing the chunk.Node*-
isEchoedWhether the code should be displayed to the reader.Boolean-
isHiddenWhether the outputs should be hidden from the reader.Boolean-
executionPureWhether the code should be treated as side-effect free when executed.Boolean-
codeThe code.CordCodeExecutable
programmingLanguageThe programming language of the code.StringCodeExecutable
executionBoundsThe environment in which code should be executed.ExecutionBoundsCodeExecutable
executionBoundedThe execution bounds, if any, on the last execution.ExecutionBoundsCodeExecutable
authorsThe authors of the executable code.Author*CodeExecutable
provenanceA summary of the provenance of the code.ProvenanceCount*CodeExecutable
executionModeUnder which circumstances the node should be executed.ExecutionModeExecutable
compilationDigestA digest of the content, semantics and dependencies of the node.CompilationDigestExecutable
compilationMessagesMessages generated while compiling the code.CompilationMessage*Executable
executionDigestThe compilationDigest of the node when it was last executed.CompilationDigestExecutable
executionDependenciesThe upstream dependencies of this node.ExecutionDependency*Executable
executionDependantsThe downstream dependants of this node.ExecutionDependant*Executable
executionTagsTags in the code which affect its execution.ExecutionTag*Executable
executionCountA count of the number of times that the node has been executed.IntegerExecutable
executionRequiredWhether, and why, the code requires execution or re-execution.ExecutionRequiredExecutable
executionStatusStatus of the most recent, including any current, execution.ExecutionStatusExecutable
executionInstanceThe id of the kernel instance that performed the last execution.StringExecutable
executionEndedThe timestamp when the last execution ended.TimestampExecutable
executionDurationDuration of the last execution.DurationExecutable
executionMessagesMessages emitted while executing the node.ExecutionMessage*Executable
idThe identifier for this item.StringEntity

Related

The CodeChunk type is related to these types:

Bindings

The CodeChunk type is represented in:

Testing

During property-based (a.k.a generative) testing, the properties of the CodeChunk type are generated using the following strategies.

PropertyComplexityDescriptionStrategy
codeMin+Generate a simple fixed string of code.Cord::from("code")
Low+Generate a random string of up to 10 alphanumeric characters (excludes whitespace whichcan be problematic in Markdown).r"[a-zA-Z0-9]{1,10}".prop_map(Cord::from)
High+Generate a random string of up to 100 characters (excluding control characters).r"[^\p{C}]{1,100}".prop_map(Cord::from)
MaxGenerate an arbitrary string.String::arbitrary().prop_map(Cord::from)
programmingLanguageMin+Generate a simple fixed string.Some(String::from("lang"))
Low+Generate one of the well known programming language short names.option::of(r"(cpp)|(js)|(py)|(r)|(ts)")
High+Generate a random string of up to 10 alphanumeric characters.option::of(r"[a-zA-Z0-9]{1,10}")
MaxGenerate an arbitrary string.option::of(String::arbitrary())
labelTypeMin+No label typeNone
Low+Generate either FigureLabel or TableLabeloption::of(prop_oneof![Just(LabelType::FigureLabel), Just(LabelType::TableLabel)])
labelMin+No labelNone
Low+Generate a simple labeloption::of(r"[a-zA-Z0-9]+")
MaxGenerate an arbitrary stringoption::of(String::arbitrary())
captionMin+No captionNone
Low+Generate up to two arbitrary paragraphs.option::of(vec_paragraphs(2))

This documentation was generated from CodeChunk.yaml by docs_types.rs.

© 2026 Stencila