PDF

blockstblockst0.4.0

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

MakeCode#

makecode() — Render MakeCode Blocks#

makecode() renders the blocks of the MakeCode editors for the micro:bit and the Calliope mini. The look is Blockly’s zelos renderer as the editors run it — pills and hexagons as tall as their block, white literal pills, the − and + buttons of an if block, MakeCode’s monospace labels — and the block texts are the editors’ own.

#makecode(
  text,
  profile: auto,      // "makecode" (micro:bit), "makecode-calliope"
  language: auto,     // "de" by default
  theme: auto,
  scale: auto,
  font: auto,
  colors: auto,
  line-numbers: auto,
  line-number-start: auto,
  line-number-gutter: auto,
  inset-scale: auto,
)
#makecode("
beim Start
  zeige Symbol [Herz v]
ende
wenn Knopf [A v] geklickt
  zeige Zahl ((1) + (2))
  pausiere (ms) (100)
ende
")

Profiles#

"makecode" (the default) is the micro:bit editor, "makecode-calliope" the Calliope mini’s: the same blocks plus the Calliope’s own (motors, the RGB LED), in the Calliope palette. set-blockst(profile: "makecode-calliope") sets the default for makecode(); colors: overrides single categories.

Writing MakeCode programs#

Languages#

The block texts are the editors’ own in every language the editors offer: German (language: "de", the default) and English read off the running editors, the other 34 — "fr", "es", "ja", "zh-cn", … — from the translation service the editors load at run time (approved strings only; an untranslated block keeps its English text, as in the editor). A bare code picks the regional variant the editor ships ("es" → es-ES, "pt" → pt-BR). The end and else markers follow the language (fin/sinon, 終わり/でなければ, …); ende, end and else work everywhere.

Code fences and parsing#

raw-makecode() renders makecode and microbit fences with the micro:bit profile and calliope fences with the Calliope mini profile. makecode-parse() returns the AST.

#show: raw-makecode()
#makecode-parse(text, language: "de", profile: "makecode")