PDF

blockstblockst0.4.0

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

Introduction#

About blockst#

blockst renders block-based programs in Typst documents, each drawn the way its editor draws it:

All four share one text notation: a block per line, (…) for a value, [… v] for a dropdown, <…> for a condition, indentation and an end marker for the body of a loop. Typst hands the text to a bundled WASM plugin, the plugin parses it and returns SVG, Typst embeds the SVG. Nothing has to be installed beyond the package.

Core Design
  • Fully text-based: write blocks as plain text, get rendered blocks. The same notation for every editor.
  • Each editor’s own geometry, palette and vocabulary — jwinf’s classic Blockly measured on jwinf.de, MakeCode’s zelos renderer as the editors run it.
  • Localized: Scratch’s official translations, Blockly’s message files, the MakeCode editors’ own strings.
  • Themes for print (print, grayscale, high-contrast) and the document’s own category colours over any palette.
  • Line numbers and line labels for worksheets that talk about single lines.
Breaking Change since 0.2.0
The old pre-0.2.0 native-Typst renderer syntax is removed. From 0.2.0 onward, blockst uses only the text-to-WASM pipeline. Documents that still rely on the previous syntax must be migrated.

Quick start#

#import "@preview/blockst:0.4.0": scratch, blockly, makecode, nepo

#scratch("
when green flag clicked
move (10) steps
turn cw (15) degrees
")

The same document can hold the other editors’ blocks. A jwinf task:

#blockly("
Roboter-Programm
wiederhole (4) mal:
  gehe nach rechts
  falls <auf Kiste>
    hebe Murmel auf ::aktionen
  ende
ende
", profile: "jwinf")

A micro:bit program:

#makecode("
beim Start
  zeige Symbol [Herz v]
ende
wenn Knopf [A v] geklickt
  zeige Zahl ((1) + (2))
  pausiere (ms) (100)
ende
")

Which function for which editor#

EditorFunctionProfilesDefault languageCode fences
Scratch 3scratch()"en", 26 languagesscratch via raw-scratch()
Blockly, jwinfblockly()blockly (default), blockly-klassisch, jwinf, jwinf-turtle"de", 24 languagesblockly, jwinf, jwinf-turtle via raw-blockly()
MakeCodemakecode()makecode (micro:bit, default), makecode-calliope"de", 36 languagesmakecode, microbit, calliope via raw-makecode()
Open Robertanepo()platforms calliope (default), calliopev3, microbit"de"nepo via raw-nepo()

Every function takes the same rendering options — theme, scale, font, line numbers, colours — and all of them read the defaults set with set-blockst(). The chapters Scratch, Blockly and jwinf, MakeCode and NEPO describe what is particular to each editor.

Package information#