HTML Snippet Previewer
A VS Code extension that allows you to preview HTML code snippets from any file type in real-time.
Features
- Preview HTML code snippets from any file type (Python, JavaScript, Modelica, etc.)
- Multiple ways to trigger preview:
- Command palette
- Keyboard shortcuts
- Right-click context menu
- Real-time preview updates when selection changes
- Support for inline CSS and JavaScript
- Error handling for invalid HTML
- Responsive preview window with resize capability
- Open preview in external browser
Installation
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "HTML Snippet Previewer"
- Click Install
Usage
- Open any file containing HTML code snippets
- Select the HTML code you want to preview
- Use one of the following methods to open the preview:
- Press
Ctrl+Shift+H (Windows/Linux) or Cmd+Shift+H (Mac)
- Right-click and select "Preview HTML Snippet" or "Preview HTML Snippet to Side"
- Open Command Palette (Ctrl+Shift+P) and search for "HTML Snippet Previewer"
- The HTML preview will open in a new panel showing the rendered HTML
Settings
You can configure the extension through VS Code settings:
htmlSnippetViewer.enableAutoRefresh: Enable automatic refresh when selection changes (default: true)
htmlSnippetViewer.previewPosition: Default position for the preview panel - "beside" or "active" (default: "beside")
Keyboard Shortcuts
Ctrl+Shift+H: Preview HTML Snippet
Ctrl+Shift+Alt+H: Preview HTML Snippet to Side
Examples
The extension comes with example files in the examples directory:
python_example.py: Python code with embedded HTML strings
model_example.mo: Modelica file with HTML documentation
js_example.js: JavaScript code with HTML template literals
Development
This extension is built with TypeScript and follows VS Code extension development best practices.
Building
- Clone the repository
- Install dependencies:
npm install
- Compile TypeScript:
npm run compile
- Run tests:
npm test
Debugging
- Open the project in VS Code
- Press F5 to launch a new VS Code instance with the extension loaded
- Test the extension in the new instance
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License
Issues
If you encounter any issues or have suggestions, please report them on the GitHub repository.
| |