π¨ Beautiful, theme-aware syntax highlighting for Markdown code blocks
Enhance your Markdown preview with intelligent syntax highlighting that automatically matches your VS Code theme. Say goodbye to inconsistent, dull code blocks in your Markdown previews!
- Install the extension
- Open any Markdown file (
.md) - Open preview (
Ctrl+Shift+VorCmd+Shift+V) - Watch your code blocks come alive with theme-aware highlighting! π
Code blocks automatically match your active VS Code theme - no configuration needed! Switch from dark to light theme and watch your code blocks update instantly.
- Smart Caching: LRU cache stores tokenized results for instant reloads
- Lazy Loading: Only visible code blocks are processed initially
- Optimized Rendering: Handles documents with 100+ code blocks smoothly
- Incremental Updates: Theme changes applied without flicker
Supports 50+ programming languages out of the box:
- Web: JavaScript, TypeScript, HTML, CSS, JSX, TSX
- Backend: Python, Java, C#, Go, Rust, PHP, Ruby
- Systems: C, C++, Objective-C, Swift, Kotlin
- Scripting: Bash, PowerShell, Perl, Lua
- Data: JSON, YAML, XML, SQL, GraphQL
- Markup: Markdown, LaTeX, TOML
- And many more...
Fine-tune every aspect:
- Adjust font size and line height
- Configure cache size and behavior
- Set performance thresholds
- Enable detailed performance monitoring
- Maintains semantic HTML structure
- Preserves ARIA attributes
- Works with screen readers
- High contrast theme support
- Open VS Code
- Press
Ctrl+P/Cmd+Pto open Quick Open - Type
ext install markdown-code-block-highlighter - Press Enter
- Clone this repository
- Run
npm installto install dependencies - Run
npm run compileto build the extension - Press
F5to launch the extension in a new VS Code window
- Open any Markdown file in VS Code
- Open the preview pane (
Ctrl+Shift+V/Cmd+Shift+V) - Code blocks will automatically be highlighted with your active theme
- Switch themes to see the highlighting update in real-time
```typescript
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("World"));
```The code block above will be highlighted with proper TypeScript syntax highlighting that matches your current VS Code theme.
You can customize the extension's behavior through VS Code settings:
| Setting | Type | Default | Description |
|---|---|---|---|
markdownCodeBlockHighlighter.enableHighlighting |
boolean | true |
Enable/disable theme-aware syntax highlighting |
markdownCodeBlockHighlighter.fontSize |
number | 0 |
Font size for code blocks in pixels (0 uses VS Code default) |
markdownCodeBlockHighlighter.lineHeight |
number | 1.5 |
Line height multiplier for code blocks |
markdownCodeBlockHighlighter.enableCache |
boolean | true |
Enable caching of tokenized code blocks |
markdownCodeBlockHighlighter.cacheSize |
number | 100 |
Maximum number of cached code blocks |
markdownCodeBlockHighlighter.maxBlockSize |
number | 10000 |
Maximum size in characters for code blocks to highlight |
markdownCodeBlockHighlighter.enablePerfMonitoring |
boolean | false |
Enable performance monitoring (for debugging) |
Add these settings to your settings.json:
{
"markdownCodeBlockHighlighter.enableHighlighting": true,
"markdownCodeBlockHighlighter.fontSize": 14,
"markdownCodeBlockHighlighter.lineHeight": 1.6,
"markdownCodeBlockHighlighter.cacheSize": 200
}The extension supports all languages that VS Code's TextMate tokenization engine supports, including:
- JavaScript / TypeScript
- Python
- Java / C / C++ / C#
- Go / Rust
- Ruby / PHP
- HTML / CSS / SCSS
- JSON / YAML / XML
- Markdown
- Shell scripts (Bash, PowerShell)
- SQL
- And many more...
- Visual Studio Code version 1.80.0 or higher
- A Markdown file to preview
- Very large code blocks (>10,000 characters) may fall back to default highlighting for performance
- Some custom themes may not provide complete token color information
The extension is designed for optimal performance:
- Caching: Tokenized code blocks are cached to avoid redundant processing
- Lazy Rendering: Only visible code blocks are highlighted initially
- Incremental Updates: Theme changes are batched to prevent flicker
- Resource Limits: Configurable limits protect against performance degradation
- Check that the extension is enabled in settings
- Verify that the code block has a language identifier (e.g.,
```javascript) - Check the VS Code console for error messages
- Try disabling other Markdown extensions that might conflict
- Reduce
cacheSizeif memory is a concern - Decrease
maxBlockSizeto skip very large blocks - Enable
enablePerfMonitoringto identify bottlenecks
Some themes may not provide complete token color mappings. The extension will use fallback colors in these cases.
Contributions are welcome! Please feel free to submit issues or pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For detailed information about the extension's architecture and design decisions, see ARCHITECTURE.md.
- Initial release with basic theme-aware syntax highlighting
- Support for 50+ programming languages
- Configurable caching and performance options
- Dynamic theme switching without preview reload
MIT License - see LICENSE file for details
- Built on VS Code's Extension API
- Uses VS Code's TextMate tokenization engine
- Inspired by the need for consistent theme experience across editor and preview
Enjoy enhanced Markdown previews with beautiful, theme-aware code highlighting! π¨β¨