Overview
Live Preview hides markdown syntax and displays formatted elements as you type. When you place your cursor inside an element, the syntax reappears so you can edit it. Features:- Bold (
**text**) and italic (*text*) formatting - Headings with styled appearance and hidden markers
- Clickable links with hidden URL syntax
- Inline code with hidden backticks
- Lists with styled markers
- Blockquotes with hidden
>markers - Images rendered inline
- Tables with clean borders
- Code blocks with syntax highlighting
- Callouts with icons and styling
- Selection-aware rendering (shows syntax when cursor is inside)
- Viewport-based optimization for performance
packages/plugins/src/live-preview/LivePreviewPlugin.ts:4-21
Installation
The Live Preview plugin is built-in and enabled by default. To toggle it:- Open Settings → Plugins
- Find “Live Preview”
- Toggle the enable switch
How It Works
Architecture
The Live Preview plugin uses CodeMirror decorations to transform markdown syntax:packages/plugins/src/live-preview/livePreviewExtension.ts:36-143
Decoration Types
The plugin implements decorations for:| Element | Source File | What It Does |
|---|---|---|
| Bold | decorations/bold.ts | Hides ** markers, applies bold styling |
| Italic | decorations/italic.ts | Hides * or _ markers, applies italic styling |
| Headings | decorations/heading.ts | Hides # markers, applies heading colors and sizes |
| Links | decorations/link.ts | Creates clickable widgets, hides URL syntax |
| Images | decorations/image.ts | Renders images inline, hides syntax |
| Code | decorations/code.ts | Hides backticks, styles inline code |
| Code Blocks | decorations/codeblock.ts | Adds background, syntax highlighting |
| Lists | decorations/list.ts | Styles bullets/numbers |
| Blockquotes | decorations/quote.ts | Hides > markers, adds border |
| Strikethrough | decorations/strikethrough.ts | Hides ~~ markers, adds strikethrough |
| Highlight | decorations/highlight.ts | Hides == markers, adds highlight background |
| Horizontal Rules | decorations/hr.ts | Renders visual line |
| Tables | decorations/table.ts | Formats table with borders |
| Callouts | decorations/callout.ts | Adds icons, colored borders |
packages/plugins/src/live-preview/decorations/
Selection-Aware Rendering
When you place your cursor inside an element, the syntax becomes visible:Performance Optimization
Live Preview only processes visible content:packages/plugins/src/live-preview/livePreviewExtension.ts:69-73
Examples
Bold Text
Input:**bold text**
Rendered: Shows as bold text with hidden ** markers
When cursor is inside: Shows **bold text** with markers visible
Headings
Input:# symbols hidden
Links
Input:[Click here](https://example.com)
Rendered: Clickable “Click here” link, URL syntax hidden
Ctrl+Click: Opens URL in browser
Code Blocks
Input:- Background color from theme
- Syntax highlighting for JavaScript
- Copy button widget
- Language badge
- Hidden fence markers when not editing
Images
Input:
Rendered: Actual image displayed inline, syntax hidden
Callouts
Input:- Colored border (based on type)
- Icon widget
- Formatted title
- Styled content area
Code Block Features
Syntax Highlighting
Code blocks use the theme’s syntax highlighting colors:--code-bg: Background color--code-keyword: Keywords (const, function)--code-string: String literals--code-comment: Comments--code-function: Function names--code-number: Numbers
Copy Button Widget
Code blocks include a copy button in the top-right corner:packages/plugins/src/live-preview/widgets/CopyButton.ts
Language Badge Widget
Shows the language name in the top-left:packages/plugins/src/live-preview/widgets/LanguageBadge.ts
Container System
The plugin uses a container registry to handle nested structures:- Nested lists
- Callouts with formatted content
- Blockquotes with inline formatting
packages/plugins/src/live-preview/context/DecorationContext.ts
CSS Styling
The plugin includes CSS for visual effects:Code Block Styling
packages/plugins/src/live-preview/styles/codeblock.css
List Styling
packages/plugins/src/live-preview/styles/list.css
Callout Styling
packages/plugins/src/live-preview/styles/callout.css
Configuration
The Live Preview plugin currently has no user-configurable settings. It’s either enabled or disabled.Future Configuration Options
Potential future settings:- Toggle specific features (e.g., disable image preview)
- Configure keyboard modifiers for link clicks
- Adjust decoration behavior
Integration with Editor
The plugin is integrated directly into the Editor component:LivePreviewPlugin.ts:19-20
Performance Characteristics
Time Complexity
- Per-line processing: O(n) where n is the number of visible lines
- Decoration updates: Only on document changes, viewport changes, or selection changes
- Memory usage: Minimal, decorations are reused
Optimization Strategies
- Viewport-based rendering: Only visible content is decorated
- Incremental updates: Only changed lines are reprocessed
- Decoration caching: Reuses unchanged decorations
- Syntax tree parsing: Uses CodeMirror’s efficient syntax tree
Troubleshooting
Links aren’t clickable
Solution: Ensure the Live Preview plugin is enabled in Settings → Plugins.Syntax keeps appearing/disappearing
Cause: Cursor is near decoration boundaries. Solution: This is intentional behavior - syntax shows when you’re editing it.Images not loading
Causes:- File path is incorrect
- Image file doesn’t exist
- No read permissions
Performance issues with large documents
Cause: Too many decorations being applied. Solution: Live Preview only decorates visible content, but very complex documents may still be slow. Consider:- Breaking document into smaller files
- Temporarily disabling Live Preview
- Closing other tabs to reduce memory usage
API Reference
Plugin Class
packages/plugins/src/live-preview/LivePreviewPlugin.ts:22-35
Extension Function
app: The Inkdown app instancefilePath: Optional path to current file (for resolving image paths)
Extension that applies live preview decorations
Source: packages/plugins/src/live-preview/livePreviewExtension.ts:181-202
See Also
Emoji Plugin
Convert emoji codes to emoji characters
Theme System
Customize live preview colors
Editor API
CodeMirror editor integration
