A Visual Studio Code extension that allows you to run shell scripts and Python code directly from markdown code blocks.
Features
Run shell scripts and Python code from markdown code blocks with a simple run button or right-click
Supports shell, bash, sh, zsh, python, and py code blocks
Execute shell commands in dedicated terminals or view output in the output channel
Python code is executed and output is displayed in a dedicated WebView panel or output channel
Each markdown file gets its own terminal for running shell commands
Configurable supported languages
Commands are executed from the directory of the markdown file
Usage
Using the Run Button
Open a markdown file in VS Code
Look for the "▶ Run" or "▶ Run Python" button that appears above code blocks:
Click the run button to execute the code block
Shell commands will run in a dedicated terminal named "Markdown Shell Runner (index)"
Python code will run and display output in the "Python Runner" WebView panel or the "Markdown Python Runner" output channel, depending on your settings
Using the Context Menu
Open a markdown file in VS Code
Place your cursor inside a code block like:
```bash
echo "Hello, World!"
ls -la
```
Or for Python:
```python
print("Hello, World!")
for i in range(5):
print(f"Number: {i}")
```
Right-click and select "Run Shell Code Block" from the context menu
Shell commands will run in a dedicated terminal, while Python code will display output in the WebView panel or output channel
Python WebView Panel
When running Python code with the WebView panel enabled:
A dedicated "Python Runner" panel will open showing:
The Python code that was executed
The output of the code execution
The working directory where the code was run
You can click the "Run Again" button in the panel to re-execute the same code without going back to the markdown file
The panel will show any errors that occur during execution
Terminal Management
Each markdown file gets its own dedicated terminal for shell commands
Terminals are named "Markdown Shell Runner (index)" where index starts from 0
When you run commands from the same file, they will reuse the same terminal
When you run commands from a different file, a new terminal will be created with an incremented index
Python code runs in a WebView panel or output channel, depending on your settings
Extension Settings
This extension contributes the following settings:
markdownShellRunner.enabledLanguages: Array of languages that can be executed from markdown code blocks (default: ["shell", "bash", "sh", "zsh", "python", "py"])
markdownShellRunner.enableCodeLens: Enable or disable the run button above code blocks (default: true)
markdownShellRunner.useTerminal: Run shell commands in a terminal instead of the output channel (default: true)
markdownShellRunner.usePythonWebView: Run Python code in a WebView panel instead of the output channel (default: true)
Requirements
Visual Studio Code 1.85.0 or higher
Development
Building the Extension
Clone the repository
Run npm install to install dependencies
Run npm run compile to compile the TypeScript code
Run npm run package to create a VSIX file
Testing
The extension includes unit tests for the core functionality. To run the tests:
npm test
See the test README for more information about the tests.
Known Issues
Commands that require interactive input are not supported
Long-running commands may timeout
Release Notes
For detailed release notes, see the CHANGELOG.md file.
Security Considerations
This extension executes shell commands on your system. Only run code that you trust and understand.