On this page ▾
Running code
{monaco-run} is an editor with a Run result below it.
```ts {monaco-run} {autorun:false, showOutputAt:'+1', height:'auto'}
console.log('runs on a click and the result appears')
```
autorunistrue,falseor'once'.showOutputAt:'+1'shows the output after a click.- The code runs in a worker of a sandboxed frame, with no access to the slides, and stops after 5 seconds. A run stuck in an endless loop holds up nothing else, and pressing run again or leaving the slide stops it at once.
consoleworks; the worker has nodocument,parentoralert. - The code runs in strict mode, as in Slidev:
total = 1withoutletorconststops with "ReferenceError: total is not defined".monacoRunUseStrict: falsein the headmatter runs it without"use strict". - The output takes its click in document order: an output at
showOutputAt:'+1'followed by aslide-ng-clickshows first. - TypeScript is turned into JavaScript for you.
console.tableandconsole.groupare shown too.importis not supported.
To run another language, a setup/code-runners.ts file maps a language id to a function. The runner is picked by the language of the code fence, also one Monaco does not know. An editor whose language has no runner says so instead of running it as JavaScript. See Setup hooks.