PDF

blockstblockst0.4.0

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

Blockly and jwinf#

blockly() — Render Blockly Blocks#

blockly() renders Blockly blocks from the shared notation, drawn with Blockly’s shapes — notch, puzzle tab, boxed fields, the mutator gear on an if block, the warning sign on a loop-control block outside a loop.

#blockly(
  text,
  profile: auto,      // "blockly", "blockly-klassisch", "jwinf", "jwinf-turtle"
  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,
)

Profiles#

A profile chooses look and vocabulary. set-blockst(profile: …) sets the default for blockly().

ProfileLookVocabulary
"blockly" (default)today’s flat Blockly (thrasos)Blockly’s standard blocks
"blockly-klassisch"Blockly before 2019, with the bevel highlightsame
"jwinf"jwinf.de — the classic geometry measured on the site, the palette of the robot training tasksrobot and turtle world blocks, plus the standard blocks in the old wording
"jwinf-turtle"the same, with the colours of the Freie Turtle-Umgebungsame
#blockly("
Roboter-Programm
wiederhole (4) mal:
  gehe nach rechts
  falls <auf Kiste>
    hebe Murmel auf ::aktionen
  ende
ende
", profile: "jwinf")

Writing jwinf tasks#

On jwinf the same block reads differently from task to task — „hebe Murmel auf„, „nimm Fisch“, „Holzstapel einsammeln„ — so there is no fixed vocabulary to match against. Write the label as it appears and name the category with a :: suffix: aktionen, schildkroete, sensoren, schleifen, logik, mathe, variablen, funktionen, text, listen, ausgeben, einlesen. Blocks the profile knows — loops, conditions, variables, the robot and turtle commands — are recognised without a suffix.

ende closes a C-block, sonst opens its else branch, and <…> equals (…): Blockly has no hexagonal boolean. Where a task’s colours deviate from both profiles, colors lays the document’s own over the palette (see Colours).

Languages#

The standard blocks come in 24 languages, from Blockly’s own message files: language: "de" (the default), "en", "fr" (répéter (10) fois), "ja" ((10) 回繰り返す), and ar, ca, cs, el, es, fa, he, hi, hr, hu, id, it, nb, nl, pl, pt, ro, ru, sl, tr. The jwinf world blocks exist in German only. Each language closes a C-block with the marker its Scratch locale uses (ende, end, fin, …) and opens the else branch with Blockly’s word (sonst, else, sinon, …); ende, end and else work in every language.

Code fences and parsing#

raw-blockly() renders blockly fences with the default profile, jwinf fences with the jwinf profile and jwinf-turtle fences with the turtle colours, whatever the arguments say. blockly-parse() returns the AST.

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

Themes apply as for Scratch, with grayscale derived from the profile’s palette.