English | 中文
This is a Typora plugin based on typora-community-plugin. Inspired by Obsidian Code Runner.
Run bash / c / cpp / csharp / crystal / dart / go / haskell / html / java / js / javascript / julia / kotlin / lua / node / php / powershell / python / r / rust / swift / ts / v / zig code blocks directly in your notes: hover over a code block and click ▶, the output will be displayed inline below the code with ANSI colors preserved. Output is cached by code content.
| Action | Method |
|---|---|
| Run a code block | Hover over the code block and click ▶ |
| Cancel running state | Click ⏹ while running (see "Known Limitations") |
| Clear output of a single block | Click the clear button at the top of the output area |
| Run the code block containing the cursor | Alt+Ctrl+R, or F1 → "Run Code Block at Cursor" |
| Clear all code block outputs | F1 → "Clear All Code Block Outputs" |
| Language | Aliases | Runtime | OS | Notes |
|---|---|---|---|---|
| Bash | bash, sh |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| C | c |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| C++ | cpp, cc |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| C# | csharp, cs |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Crystal | crystal, cr |
Crystal Playground (Remote) | All platforms | Sent to Crystal Playground, requires internet. |
| Dart | dart |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Go | go, golang |
Go Playground (Remote) | Windows / Linux | Sent to Go Playground, requires internet. |
| Haskell | hs, haskell |
Haskell Playground (Remote) | All platforms | Sent to Haskell Playground, requires internet. |
| HTML | html |
Browser (Local) | All platforms | Execution mode selectable in settings: Browser (Local) renders in closed Shadow DOM (inline <script> tags won't execute), iframe (Local) renders in a sandboxed iframe where scripts will execute. |
| Java | java |
Java Playground (Remote) | Windows / Linux | Sent to Java Playground. Supports top-level statements, imports, and class definitions (Java 27 + preview features). Requires internet. |
| JavaScript | js, javascript |
Browser (Local) / OneCompiler (Remote) | All platforms (local) / Windows / Linux (OneCompiler) | Execution mode selectable in settings: Browser (Local) executes within an async function context (await is available); OneCompiler (Remote) sends code to OneCompiler. |
| Julia | julia, jl |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Kotlin | kotlin, kt |
Kotlin Playground (Remote) | Windows / Linux | Sent to Kotlin Playground, requires internet. |
| Lua | lua |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Node.js | node, nodejs |
Node.js VM (Local) / OneCompiler (Remote) | Windows / Linux | Execution mode selectable in settings: Node.js VM (Local) compiles and executes using Node's vm; OneCompiler (Remote) sends code to OneCompiler. Remote execution requires internet. |
| PHP | php |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| PowerShell | powershell, ps1, pwsh |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Python | python, py |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Python 2 | python2, py2 |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| R | r |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| Rust | rust, rs |
Rust Playground (Remote) | All platforms | Sent to Rust Playground, requires internet. |
| Swift | swift |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
| TypeScript | ts, typescript |
Browser (Local) / OneCompiler (Remote) | All platforms (local) / Windows / Linux (OneCompiler) | Execution mode selectable in settings: Browser (Local) is transpiled by Sucrase then executed as JavaScript; OneCompiler (Remote) sends code to OneCompiler. |
| V | v, vlang |
V Playground (Remote) | Windows / Linux | Sent to V Playground, requires internet. |
| Zig | zig |
OneCompiler (Remote) | Windows / Linux | Sent to OneCompiler, requires internet. |
Open "Settings → Plugins → Codeblock Runner".
| Setting | Values | Default | Notes |
|---|---|---|---|
| Language toggles | On / Off (per language) | Local: On, Remote: Off | Toggle each language on/off individually. Remote languages are disabled by default and must be manually enabled; running a disabled language will show a prompt in the output area. See the "Supported Languages" table for details. |
| HTML execution mode | Browser (Local) / iframe (Local) | Browser (Local) | Dropdown option on the HTML row. See the "Supported Languages" table for details. |
| JavaScript execution mode | Browser (Local) / OneCompiler (Remote) | Browser (Local) | Dropdown option on the JS row. See the "Supported Languages" table for details. |
| TypeScript execution mode | Browser (Local) / OneCompiler (Remote) | Browser (Local) | Dropdown option on the TS row. See the "Supported Languages" table for details. |
| Node.js execution mode | Node.js VM (Local) / OneCompiler (Remote) | Node.js VM (Local) | Dropdown option on the Node row. See the "Supported Languages" table for details. |
- First install typora-community-plugin
- Open "Settings → Plugin Marketplace", search for "Codeblock Runner" and install.
- In
js/tscode blocks, BOM/DOM/network and Typora-related globals (window,document,fetch,reqnode,editor, etc.) are masked asundefined. This is a guardrail against accidental misuse, not a security sandbox: constructor chains, indirecteval, and dynamicimport()can still access real globals, andevalcannot be masked in strict mode. js/ts/nodecode blocks have a 5-second timeout: loop bodies with curly braces will throwLoop Timeoutafter the timeout expires; pendingawaits are caught by an outer overall timeout. Single-statement loop bodies without curly braces won't inject checks, so infinite loops may still freeze Typora.- TypeScript transpilation performs no type checking; type errors will not interrupt execution.
|
nodecode blocks: Node.js built-in module names work, but relative paths are not resolved relative to the note's directory. nodecode blocks only run on Windows and Linux. Typora does not expose Node on macOS (reqnode), so it will error directly on that platform.- Inline
<script>tags inhtmlcode blocks do not execute under Browser (Local) mode (closed Shadow DOM); switch HTML execution mode to iframe (Local) for scripts to run. rust/kotlin/hs/crystal/v/go/javacode blocks run on their respective online playgrounds, require internet, and are unavailable offline. On Windows / Linux requests are made via Node (no CORS issues); on macOS it falls back tofetch, which may be rejected if the playground doesn't allow cross-origin requests.- On macOS, the settings for
kotlin/v/go/javawill be hidden and cannot be enabled: these playgrounds don't return CORS headers, so the render processfetchfallback will be rejected. - ⏹ can only cancel the UI's running state, not interrupt code that is already executing.
- "Clear All Code Block Outputs" will clear the output cache for every code block, including those in notes that are currently closed.
