HTMLens — Universal Template & HTML PreviewerLive preview for HTML, Django/Jinja/Nunjucks templates, and React/JSX components — directly in VS Code. HTMLens provides instant, intelligent previews for a wide range of web and template files without leaving your editor. Perfect for frontend developers, Django engineers, and anyone working with component-based UIs. Links: Changelog | Development Guide | Contributing | Report an Issue ✨ Features
📸 ScreenshotsRepresentative screenshots (as SVGs) and ready-to-use demo files are provided in the
Try the demos yourself:
Demo Files (
|
| File Type | Extension(s) | Preview Behavior |
|---|---|---|
| HTML | .html, .htm |
Standard live preview with automatic rewriting of relative asset paths (<img>, <link>, <script>) to work within the webview sandbox. |
| Django/Jinja/Nunjucks | .django, .jinja, .jinja2, .j2, .njk |
Mock rendering engine: • Variables rendered as placeholders or mock values • Conditional logic ( {% if %}/{% else %}) with toggle support• Loops ( {% for %}) rendered once with annotation• Full template inheritance ( {% extends %} + {% block %}) and recursive includes resolved from workspace files• Unhandled tags preserved as visible HTML comments |
| React | .jsx, .tsx |
In-browser transpilation & render using Babel Standalone (with React preset) + React 18 (via CDN). JSX is automatically transformed; local imports are stripped with a warning banner. Ideal for quick single-component previews. |
Engine detection is automatic based on file extension and content patterns.
⌨️ Commands
Access via Command Palette (Ctrl+Shift+P / Cmd+Shift+P) or editor title bar icon:
- HTMLens: Open Preview — Open preview in a new tab.
- HTMLens: Open Preview to the Side — Split view (recommended).
- HTMLens: Refresh Preview — Force refresh the current preview.
- HTMLens: Toggle {% if %}/{% else %} Branch — Switch rendered conditional branch.
A preview icon appears automatically in the editor title bar for supported files.
⚙️ Configuration
Search for "htmlens" in VS Code Settings (Ctrl+,):
| Setting | Type | Default | Description |
|---|---|---|---|
htmlens.mockVariableStyle |
string |
"highlight" |
How to render template variables: "highlight" (styled placeholder) or "value" (plausible sample data based on variable name). |
htmlens.includeMaxDepth |
number |
5 |
Maximum recursion depth for resolving {% extends %} and {% include %} to prevent infinite loops. |
🔍 How It Works
- Template Processor: Detects engine, resolves inheritance/includes, mocks control structures and variables while preserving structure.
- React Renderer: Strips React/local imports, transpiles JSX via Babel Standalone (React preset), and mounts the default-exported component in a sandboxed React 18 environment.
- Preview Panel: Singleton Webview with proper security (CSP + nonce), asset URI mapping via
asWebviewUri, and live update listeners. - Extension Core: Registers commands, handles document change/save events with debouncing for performance.
See DEVELOPMENT.md for full architecture details, debugging instructions, and guidance on adding new features (e.g., additional template tags or React hook support).
⚠️ Known Limitations
- React Preview: Not a full bundler. Multi-file components, local CSS modules, or complex npm dependencies may not resolve. Designed for quick single-component validation.
- Template Tags: Unhandled or custom tags/filters appear as visible
<!-- HTMLens: unhandled tag {% foo %} -->comments (better transparency than silent failure). - File Resolution:
{% extends %}and{% include %}search only within the open workspace (skippingnode_modules). Custom template loaders with external paths may require manual adjustment. - Performance: Deeply nested includes or very large templates may hit configured depth limits.
These are intentional design choices to keep the extension lightweight and focused on fast previews.
🛠️ Development & Contributing
See:
- DEVELOPMENT.md — Architecture, setup, building, extending the mock renderer.
- CONTRIBUTING.md — Guidelines, code standards, PR process.
Quick Development Setup:
git clone https://github.com/AnandShah10/HTMLens.git
cd HTMLens
npm install
# Press F5 in VS Code to start debugging
Build Commands:
npm run compile # TypeScript → JavaScript
npm run package # Create .vsix package
We welcome contributions! Please follow conventional commits and update documentation/CHANGELOG as needed.
📄 License
This project is licensed under the MIT License — feel free to use, modify, and distribute.
Made with ❤️ for the developer community. Questions or feedback? Open an issue on GitHub.
Keywords: django preview, jinja2 preview, nunjucks live preview, react jsx preview, html live preview, template mocking, vs code extension