This guide covers the fundamental concepts and methods for using SquibView in your projects.
const editor = newSquibView({
element: document.getElementById('editor'),
content: '# Hello World\n\nThis is **markdown** content.'
});
const editor = newSquibView({
element: document.getElementById('editor'),
content: '# My Document',
initialView: 'split', // 'src', 'html', or 'split'showControls: true, // Show view toggle buttonstitleShow: true, // Show title bartitleContent: 'My Editor'// Title bar text
});
// Set markdown content
editor.setContent('# New Content\n\nThis is **new** content.', 'md');
// Set HTML content
editor.setContent('<h1>HTML Content</h1><p>Direct HTML</p>', 'html');
// Set CSV data
editor.setContent('name,age\nJohn,25\nJane,30', 'csv');
// Get current source contentconst source = editor.getContent();
// Get rendered HTMLconst html = editor.getHTML();
// Check current view modeconst view = editor.getCurrentView(); // 'src', 'html', or 'split'
// Switch views
editor.setView('src'); // Source only
editor.setView('html'); // HTML only
editor.setView('split'); // Split view// Toggle between views
editor.toggleView();
SquibView supports multiple content types:
Type | Description | Example |
---|---|---|
md | Markdown (default) | # Title\n\n**Bold text** |
html | Raw HTML | <h1>Title</h1><p>Text</p> |
csv | Comma-separated values | name,age\nJohn,25 |
tsv | Tab-separated values | name\tage\nJohn\t25 |
SquibView supports GitHub-Flavored Markdown including:
# ## ###
)**bold**
, *italic*
)```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
Inline math: $E = mc^2$
Block math:
$$
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
```javascript
function hello() {
console.log('Hello, World!');
}
```geojson
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0445, 40.6892]
},
"properties": {
"name": "Statue of Liberty"
}
}
SquibView uses an event system for communication:
// Listen for content changes
editor.on('content-changed', (content, type) => {
console.log('Content updated:', content);
});
// Listen for view changes
editor.on('view-changed', (view) => {
console.log('View changed to:', view);
});
// Listen for selection changes
editor.on('selection-changed', (selection) => {
console.log('Selected text:', selection.text);
});
// Copy HTML to clipboard
editor.copyHTML();
// Copy source to clipboard
editor.copySource();
// Get clean HTML for exportconst exportHTML = editor.getHTML();
// Get current source contentconst exportSource = editor.getContent();
/* Override default styles */.squibview {
font-family: 'Custom Font', serif;
}
.squibview.source-panel {
background-color: #f5f5f5;
}
.squibview.html-panel {
background-color: white;
}
SquibView automatically adapts to different screen sizes:
/* Mobile-first styling */.squibview {
height: 400px;
}
@media (min-width: 768px) {
.squibview {
height: 600px;
}
}
Initialize after DOM is ready
document.addEventListener('DOMContentLoaded', () => {
const editor = newSquibView({ /* options */ });
});
Handle errors gracefully
try {
editor.setContent(userContent, contentType);
} catch (error) {
console.error('Failed to set content:', error);
}
Clean up when done
// If your framework supports cleanup
editor.destroy?.();