Code with try playground

Create interactive code examples with a "Try" button that allows users to execute code in a playground environment. This feature is ideal for API demonstrations, tutorials, and hands-on examples where users can experiment with code directly.

Syntax

Use the following data attributes after the language identifier:

```javascript-data-playground-session-id="sessionName"-data-playground-mode="playground"-data-playground-session="new"-data-playground-execution-mode="script"-data-playground-url="https://example.com"
// your code here
```

Parameters

Example

const insertionParent = editor.context.insertionParent; // get node to insert content into

const rectangle = editor.createRectangle();
rectangle.width = 100;
rectangle.height = 100;
rectangle.translation = { x: 100, y: 200 };
console.log(rectangle); // for debugging purpose

const [red, green, blue, alpha] = [0.4, 0.6, 0.2, 0.4];
// Note: alpha param is optional
const aColor = colorUtils.fromRGB(red, green, blue, alpha);
const rectangleFill = editor.makeColorFill(aColor);
rectangle.fill = rectangleFill;

insertionParent.children.append(rectangle);