def
code_block
cauldron.display.code_block()

Adds a block of syntax highlighted code to the display from either the supplied code argument, or from the code file specified by the path argument.

Arguments
Required
Optional
code

str

A string containing the code to be added to the display

Default Value: 

None

path

str

A path to a file containing code to be added to the display

Default Value: 

None

language_id

str

The language identifier that indicates what language should be used by the syntax highlighter. Valid values are any of the languages supported by the Pygments highlighter.

Default Value: 

None

title

str

If specified, the code block will include a title bar with the value of this argument

Default Value: 

None

caption

str

If specified, the code block will include a caption box below the code that contains the value of this argument

Default Value: 

None

Basic Usage
You need to specify the language_id argument when you pass in code as a string argument or Cauldron will not highlight the code:
01
02
03
import cauldron as cd cd.display.code_block('print("Hello World!")', language_id='py3')
The language_id argument can often be omitted when specifying a path to a code file as long as the file has a recognizable extension from which the language can be determined automatically:
01
02
03
import cauldron as cd cd.display.code_block(path=__file__)
The language_id argument takes precedence over the file extension. Cauldron will highlight the file as HTML if you specify an 'html' language identifier even if the file extension is for a Python file:
01
02
03
import cauldron as cd cd.display.code_block(path='/path/to/some/file.py', language_id='html')