Home

Code Block

This is a block representation used in Stencila Schema for non-executable code.

It extends CodeStatic for code that should be displayed and preserved as document content without normal execution semantics. Stencila also adds optional demo compilation behavior so some static code blocks can render derived content while remaining distinct from executable code chunks.

Key properties are inherited from CodeStatic, with Stencila Schema behavior centered on isDemo, content, and the associated compilation properties.

Analogues

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

Properties

The CodeBlock type has these properties:

NameDescriptionTypeInherited from
isDemoWhether the code block is a demo that should also be rendered.Boolean-
compilationDigestA digest of the code and programmingLanguage.CompilationDigest-
compilationMessagesMessages generated while compiling the demo content.CompilationMessage*-
contentThe content rendered from the code when isDemo is true.Block*-
codeThe code.CordCodeStatic
programmingLanguageThe programming language of the code.StringCodeStatic
authorsThe authors of the code.Author*CodeStatic
provenanceA summary of the provenance of the code.ProvenanceCount*CodeStatic
idThe identifier for this item.StringEntity

Related

The CodeBlock type is related to these types:

Bindings

The CodeBlock type is represented in:

Testing

During property-based (a.k.a generative) testing, the properties of the CodeBlock 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 (exclude 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+Do not generate a programming language.None
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())

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

© 2026 Stencila