Blocks reference¶
Blocks are YMPrint’s special content types for things plain YAML prose can’t express — images, admonitions, code, figures, and more. Some mirror markdown (images, code blocks); others extend it (admonitions, styled horizontal rules, executable Python).
Block syntax¶
A block is a key that begins with an underscore, e.g. _img or _spacer. Its value is
a block-specific data structure — sometimes a scalar, sometimes a mapping of parameters.
Blocks appear wherever content is allowed, typically as list items:
Report:
- Photos:
_img:
src: photo.png
caption: "Figure 1"
- _info: A short informational note.
- _pagebreak:
Some block codes accept a suffix after the underscore code, e.g. _hrule_red and
_hrule_blue are both handled by the _hrule block — the suffix simply keeps the YAML keys
unique when you use several in one list.
Block catalogue¶
Block |
Purpose |
|---|---|
Embed an image with a caption. |
|
Embed a matplotlib figure object. |
|
Callout boxes. |
|
A quotation with attribution. |
|
A non-executable, syntax-highlighted code block. |
|
Execute Python and optionally show the source. |
|
Load variables from a JSON file. |
|
Force a page break. |
|
A configurable horizontal rule. |
|
Insert vertical whitespace. |
_img — Images¶
Embed a raster image (PNG, JPEG, …) with a caption. Paths are relative to the report file (or absolute).
_img:
src: catpuccin.png
caption: "Figure 1: The catpuccin cat"
scale_ratio: 0.3
Parameter |
Required |
Default |
Meaning |
|---|---|---|---|
|
✅ |
— |
Path to the image, relative to the |
|
✅ |
— |
Caption text shown below the image. |
|
|
Scale factor relative to the available content width. The image is automatically shrunk to fit the frame if it would overflow. |
_matplotfig — Matplotlib figures¶
Embed a matplotlib Figure object that you built in a _py block.
Pass the figure through the $var syntax.
Report:
- _py:
echo: false
source: |
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
- _matplotfig:
fig: $fig
caption: "Figure 1: A computed plot"
scale_ratio: 0.8
Parameter |
Required |
Default |
Meaning |
|---|---|---|---|
|
✅ |
— |
A matplotlib |
|
|
Caption text shown below the figure. |
|
|
|
Scale factor relative to the available content width. |
Note
matplotlib is an optional dependency — install it in the same environment as YMPrint to
use this block.
Admonitions¶
Callout boxes for drawing attention. Five variants are available, each taking the callout text as its value:
Report:
- _info: Here is an "info" admonition.
- _warning: Here is a "warning" admonition.
- _danger: Here is a danger admonition.
- _tip: Here is a helpful tip.
- _note: This is useful when you want to give a note.
Block |
Use for |
|---|---|
|
General information. |
|
Something the reader should be careful about. |
|
A serious caution. |
|
A helpful suggestion. |
|
An aside worth remembering. |
_blockquote — Block quotes¶
A quotation with an attribution line.
_blockquote:
quote: “What you do makes a difference, and you have to decide what kind of difference you want to make.”
attribution: Jane Goodall
Parameter |
Required |
Meaning |
|---|---|---|
|
✅ |
The quotation text. |
|
Who said it. |
_code — Preformatted code¶
A non-executable, syntax-highlighted code block. Use this to display code or config verbatim.
_code:
source: |
yaml_data: is being shown
you can put: any yaml data together
more examples:
- - cell-padding
- cell_size
Parameter |
Required |
Meaning |
|---|---|---|
|
✅ |
The literal text to display. Use a YAML block scalar (` |
To run code instead of just showing it, use _py.
_py — Executable Python¶
Execute Python with exec(). The document’s variable dictionary is the global scope, so
any _vars you defined are available to the code, and any variables the code creates become
available to the rest of the document (and to blocks via $var).
_py:
echo: true
line_numbers: true
namespace: py1
caption: >
Once this executes, the variables are accessible under the py1 namespace.
source: |
import math
a = 3
b = 4
c = math.sin(a / b)
Parameter |
Required |
Default |
Meaning |
|---|---|---|---|
|
✅ |
— |
Python source to execute. |
|
|
Whether to render the source as a highlighted code block. Set |
|
|
— |
Show line numbers alongside the rendered source. |
|
|
— |
Caption shown with the rendered code. |
|
|
— |
Nest the created variables under this name (access as |
|
|
|
Width of the rendered code block relative to the content width. |
Warning
_py runs exec() in the same Python environment as YMPrint. External subprocess
isolation is not currently implemented — only run documents you trust.
After execution the variables are usable everywhere:
- - a = {{py1.a}}
- b = {{py1.b}}
- c = {{py1.c}}
See Variables → Computing variables in Python.
_loadjson — Load JSON variables¶
Read a JSON file into your variable context at render time, optionally under a namespace.
_loadjson:
path: extra_vars.json
namespace: extra_vars
Parameter |
Required |
Meaning |
|---|---|---|
|
✅ |
Path to the JSON file, relative to the report file. |
|
Nest the loaded values under this name (access as |
- - bn = {{extra_vars.bn}}
- dx = {{extra_vars.dx}}
_pagebreak — Page breaks¶
Force a page break. Takes null as its value (an empty block).
Report:
- >
This content ends the page.
- _pagebreak:
- >
This content starts a new page.
_hrule — Horizontal rules¶
Unlike a markdown rule, _hrule is configurable — width, thickness, colour, and line cap.
Use suffixes to keep multiple rules unique in one list.
- _hrule_default: null
- _hrule_red:
width_ratio: 0.8
thickness: 2
color: "#bb3322"
- _hrule_blue:
width_ratio: 0.6
thickness: 3
color: "#4422dd"
cap: round
Parameter |
Default |
Meaning |
|---|---|---|
|
|
Rule width as a fraction of the content width. |
|
|
Line thickness in points. |
|
|
Rule colour. |
|
|
Line-cap style: |
Passing null (as with _hrule_default: null) draws a rule with all defaults.
_spacer — Vertical space¶
Insert an arbitrary amount of vertical whitespace, measured in points, to nudge content positioning by hand.
Report:
- _spacer: 5
- There is a 5 pt spacer above.
- _spacer: 20
- There is a 20 pt spacer above.
The value is the height of the space in points. A _spacer: 0 is a handy trick to stop a
paragraph being misinterpreted as a bullet when it’s immediately followed by a list.