PDF

blockstblockst0.4.0

Render Scratch, Blockly, MakeCode and Open Roberta blocks for educational documents.

API Reference#

The reference is generated from the /// comments in the source. It covers the public rendering API in libs/scratch/api.typ, which lib.typ and package.typ re-export unchanged.

blockly#

blockly(
  text,
  profile: auto,
  language: auto,
  theme: auto,
  scale: auto,
  font: auto,
  line-numbering: auto,
  line-numbers: auto,
  line-number-start: auto,
  line-number-first-block: auto,
  line-number-gutter: auto,
  inset-scale: auto,
  colors: auto,
)

Render Blockly blocks from text. Same notation as scratch(), drawn with Blockly’s shapes — notch, puzzle tab, boxed fields — and the vocabulary, categories and colours of a profile:

  • "blockly" (the default): today’s flat look, Blockly’s German wording
  • "blockly-klassisch": the pre-2019 look
  • "jwinf": jwinf.de — classic geometry, the robot and turtle world blocks, and the palette of the robot training tasks
  • "jwinf-turtle": the same with the colours of the Freie Turtle-Umgebung

colors: (logik: "#73cc47") overrides single categories of any profile.

Labels that no profile knows are drawn as written, with the category taken from a ::kategorie suffix — on jwinf the normal case, because the same block reads differently from task to task.

#blockly("wiederhole (4) mal:\n  gehe nach rechts\nende", profile: "jwinf")
NameVorgabe
text
profileauto
languageauto
themeauto
scaleauto
fontauto
line-numberingauto
line-numbersauto
line-number-startauto
line-number-first-blockauto
line-number-gutterauto
inset-scaleauto
colorsauto

blockly-parse#

blockly-parse(text, language: "de", profile: "blockly")
Parse Blockly text to AST (for programmatic use).
NameVorgabe
text
language"de"
profile"blockly"

blockst#

blockst(
  theme: auto,
  scale: auto,
  font: auto,
  line-numbering: auto,
  line-numbers: auto,
  line-number-start: auto,
  line-number-first-block: auto,
  line-number-gutter: auto,
  inset-scale: auto,
  language: auto,
  colors: auto,
  spacing: 1.5em,
  body,
)
Optional container for grouped blocks with theme/scale override. Only needed when a specific group should differ from global settings.
NameVorgabe
themeauto
scaleauto
fontauto
line-numberingauto
line-numbersauto
line-number-startauto
line-number-first-blockauto
line-number-gutterauto
inset-scaleauto
languageauto
colorsauto
spacing1.5em
body

blockst-labels#

blockst-labels(name)
Read globally collected line labels from all previously rendered scratch() blocks. With a name: #blockst-labels("start", default: "?"). Without a name: returns the full label-to-line dictionary.

blockst-register-labels#

blockst-register-labels(text, language: "en")
Register labels globally without rendering blocks. Useful when labels are needed before the first #scratch() output appears.
NameVorgabe
text
language"en"

makecode#

makecode(
  text,
  profile: auto,
  language: auto,
  theme: auto,
  scale: auto,
  font: auto,
  line-numbering: auto,
  line-numbers: auto,
  line-number-start: auto,
  line-number-first-block: auto,
  line-number-gutter: auto,
  inset-scale: auto,
  colors: auto,
)

Render MakeCode blocks from text — the micro:bit and Calliope mini editors’ look: Blockly’s zelos renderer with MakeCode’s monospace labels. Same notation as scratch(); (…) is a value, [… v] a dropdown, <…> a boolean, ende/end closes a C-block and sonst/else opens the else branch. The profile picks the target: "makecode" (micro:bit, the default) or "makecode-calliope"; the language is any of the editors’ 36 ("de" by default, "en", "fr", "es", "zh-cn", …), with the block texts the editors show in that language. The end marker follows the language (ende, end, fin, …); end and ende work in every language.

#makecode("beim Start\n  zeige Zahl (0)\nende")
NameVorgabe
text
profileauto
languageauto
themeauto
scaleauto
fontauto
line-numberingauto
line-numbersauto
line-number-startauto
line-number-first-blockauto
line-number-gutterauto
inset-scaleauto
colorsauto

makecode-parse#

makecode-parse(text, language: "de", profile: "makecode")
Parse MakeCode text to AST (for programmatic use).
NameVorgabe
text
language"de"
profile"makecode"

raw-blockly#

raw-blockly(..args)

Enable Blockly code blocks in raw text:

#show: raw-blockly()
```blockly
wiederhole (4) mal:
ende
```

A jwinf fence uses the jwinf profile whatever the arguments say, a jwinf-turtle fence the turtle sandbox’s colours.

raw-makecode#

raw-makecode(..args)

Enable MakeCode code blocks in raw text:

#show: raw-makecode()
```makecode
beim Start
  zeige Zahl (0)
ende
```

A microbit fence is the same; a calliope fence uses the Calliope mini profile whatever the arguments say.

raw-scratch#

raw-scratch(..args)

Enable scratch code blocks in raw text:

#show: raw-scratch()

With language: #show: raw-scratch(language: "de").

scratch#

scratch(
  text,
  language: auto,
  theme: auto,
  scale: auto,
  font: auto,
  line-numbering: auto,
  line-numbers: auto,
  line-number-start: auto,
  line-number-first-block: auto,
  line-number-gutter: auto,
  inset-scale: auto,
  colors: auto,
)
Render scratch blocks from text. Works standalone or inside #blockst[...]. Supports 26 languages: en, de, fr, es, it, pt, nl, pl, ru, ja, …
NameVorgabe
text
languageauto
themeauto
scaleauto
fontauto
line-numberingauto
line-numbersauto
line-number-startauto
line-number-first-blockauto
line-number-gutterauto
inset-scaleauto
colorsauto

scratch-execute#

scratch-execute(text, language: "en")
Execute scratch text, producing scratch-run commands.
NameVorgabe
text
language"en"

scratch-labels#

scratch-labels(text, language: "en")
Parse scratch text and return a dictionary mapping #labels to rendered line numbers.
NameVorgabe
text
language"en"

scratch-parse#

scratch-parse(text, language: "en")
Parse scratch text to AST (for programmatic use).
NameVorgabe
text
language"en"

set-blockst#

set-blockst(
  theme: none,
  profile: none,
  colors: none,
  scale: none,
  stroke-width: none,
  font: none,
  line-numbering: none,
  line-numbers: none,
  line-number-start: none,
  line-number-first-block: none,
  line-number-gutter: none,
  inset-scale: none,
  language: none,
)

Global settings applied to all scratch() and sb3 calls.

colors lays the document’s own category colours over the profile’s palette: set-blockst(colors: (logik: "#73cc47")) — a hex string or a Typst colour per category. The shades a theme derives (bevel, stroke, high-contrast, grayscale) follow the new fill.

NameVorgabe
themenone
profilenone
colorsnone
scalenone
stroke-widthnone
fontnone
line-numberingnone
line-numbersnone
line-number-startnone
line-number-first-blocknone
line-number-gutternone
inset-scalenone
languagenone