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#
- Units. A unit the editor shows in parentheses is typed like a value and drawn as the label:
pausiere (ms) (100),Temperatur (°C). - Operators take the editor’s glyph or a spelling:
×or*,÷or/,≥or>=,≤or<=,≠or!=. - LED matrix. 25 cells,
#lit and.dark, in any grouping:zeige LEDs [#...#|.#.#.|..#..|.#.#.|#...#]. - Melody editor. Eight notes or rests:
spiele (Melodie [C D E F - - - -] mit Tempo (120) (bpm)) [bis zum Ende v]. - Else.
ansonsten/elseopens the else branch, which gets the editor’s − and + buttons. - Unknown labels are drawn as written with the category from a
::kategoriesuffix:basic,input,music,led,radio,loops,logic,variables,math,functions,arrays,text,game,images,pins,serial,control.
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")