Creating a Polyglot Notebook extension
We’ll start by creating a simple extension that offers a #!flip-coin
magic command. This magic command will simulate a coin flip and print either Heads
or Tails
below the cell when it is invoked.
Does this really need a magic command?
A simple coin flip isn’t usually the type of thing you’d need a magic command for. Instead, defining a CoinFlip
method that you could then call in a cell would be fine. Normally, I’d consider making a magic command if something needs to interact directly with the kernel in some way, as we’ll see with our Mermaid example later. However, we need to start somewhere, so let’s begin with a simple example and work our way up from there.
We’ll start by defining KernelActionDirective
for our new #!flip-coin
magic command. This object will contain the magic command text we wish to reserve, as well as a description of the command, as shown here:
using Microsoft.DotNet...