-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-basic-usage.html
More file actions
355 lines (313 loc) · 18.1 KB
/
03-basic-usage.html
File metadata and controls
355 lines (313 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic Usage</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><circle cx='16' cy='16' r='14' fill='%23f57c00' stroke='%23000' stroke-width='1'/><path d='M2 16h28M16 2a14 14 0 0114 14 14 14 0 01-14 14 14 14 0 01-14-14A14 14 0 0116 2zm0 0v28M9 16a7 7 0 0014 0 7 7 0 00-14 0z' fill='none' stroke='%23000' stroke-width='1'/></svg>">
<style>
/* Additional CSS */
/* SquibView CLI Generated Styles */
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
line-height: 1.6;
color: #333;
max-width: 900px;
margin: 0 auto;
padding: 2rem 3rem;
background-color: #fff;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.5em;
margin-bottom: 0.5em;
font-weight: 600;
line-height: 1.25;
}
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.5rem;
}
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }
h5 { font-size: 0.875rem; }
h6 { font-size: 0.85rem; color: #666; }
p { margin-bottom: 1rem; }
a {
color: #0066cc;
text-decoration: none;
}
a:hover {
color: #0066cc;
text-decoration: underline;
}
ul, ol {
margin-bottom: 1rem;
padding-left: 2rem;
}
li {
margin-bottom: 0.25rem;
}
blockquote {
margin: 1rem 0;
padding: 0.5rem 1rem;
border-left: 4px solid #ddd;
background-color: #f9f9f9;
color: #666;
}
code {
background-color: #f5f5f5;
padding: 0.2em 0.4em;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.85em;
}
pre {
background-color: #f8f8f8;
padding: 1rem;
margin-bottom: 1rem;
overflow-x: auto;
border-radius: 4px;
}
pre code {
background-color: transparent;
padding: 0;
border-radius: 0;
}
table {
border-collapse: collapse;
width: 100%;
margin-bottom: 1rem;
}
th, td {
border: 1px solid #ddd;
padding: 0.5rem;
text-align: left;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
img {
max-width: 100%;
height: auto;
margin-bottom: 1rem;
}
hr {
border: none;
border-top: 1px solid #ddd;
margin: 2rem 0;
}
/* Badge images - inline display */
p img {
display: inline;
margin: 0 2px;
vertical-align: middle;
}
/* Math styling */
.MathJax {
overflow-x: auto;
overflow-y: hidden;
}
/* Responsive design */
@media (max-width: 768px) {
body {
padding: 1rem 1.5rem;
}
table {
font-size: 0.875rem;
}
th, td {
padding: 0.25rem;
}
}
/* Print styles */
@media print {
body {
padding: 0;
color: #000;
}
a {
color: #000;
text-decoration: underline;
}
pre, blockquote {
page-break-inside: avoid;
}
h1, h2, h3, h4, h5, h6 {
page-break-after: avoid;
}
}
</style>
<!-- Highlight.js for syntax highlighting -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- Leaflet for GeoJSON/TopoJSON maps -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://unpkg.com/topojson-client@3.1.0/dist/topojson-client.min.js"></script>
<!-- Three.js for STL 3D models -->
<script src="https://unpkg.com/three@0.171.0/build/three.min.js"></script>
<!-- MathJax for math rendering -->
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['\\[', '\\]']],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
svg: {
fontCache: 'global'
}
};
</script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>
<!-- Mermaid for diagram rendering -->
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
</head>
<body>
<div><h1>Basic Usage</h1><p>This guide covers the fundamental concepts and methods for using SquibView in your projects.</p><h2>Creating a SquibView Instance</h2><h3>Basic Setup</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-keyword">const</span> editor = <span class="hljs-keyword">new</span><span class="hljs-title class_">SquibView</span>({
<span class="hljs-attr">element</span>: <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'editor'</span>),
<span class="hljs-attr">content</span>: <span class="hljs-string">'# Hello World\n\nThis is **markdown** content.'</span>
});
</code></pre></div><h3>With Options</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-keyword">const</span> editor = <span class="hljs-keyword">new</span><span class="hljs-title class_">SquibView</span>({
<span class="hljs-attr">element</span>: <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'editor'</span>),
<span class="hljs-attr">content</span>: <span class="hljs-string">'# My Document'</span>,
<span class="hljs-attr">initialView</span>: <span class="hljs-string">'split'</span>, <span class="hljs-comment">// 'src', 'html', or 'split'</span><span class="hljs-attr">showControls</span>: <span class="hljs-literal">true</span>, <span class="hljs-comment">// Show view toggle buttons</span><span class="hljs-attr">titleShow</span>: <span class="hljs-literal">true</span>, <span class="hljs-comment">// Show title bar</span><span class="hljs-attr">titleContent</span>: <span class="hljs-string">'My Editor'</span><span class="hljs-comment">// Title bar text</span>
});
</code></pre></div><h2>Core Methods</h2><h3>Setting Content</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Set markdown content</span>
editor.<span class="hljs-title function_">setContent</span>(<span class="hljs-string">'# New Content\n\nThis is **new** content.'</span>, <span class="hljs-string">'md'</span>);
<span class="hljs-comment">// Set HTML content</span>
editor.<span class="hljs-title function_">setContent</span>(<span class="hljs-string">'<h1>HTML Content</h1><p>Direct HTML</p>'</span>, <span class="hljs-string">'html'</span>);
<span class="hljs-comment">// Set CSV data</span>
editor.<span class="hljs-title function_">setContent</span>(<span class="hljs-string">'name,age\nJohn,25\nJane,30'</span>, <span class="hljs-string">'csv'</span>);
</code></pre></div><h3>Getting Content</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Get current source content</span><span class="hljs-keyword">const</span> source = editor.<span class="hljs-title function_">getContent</span>();
<span class="hljs-comment">// Get rendered HTML</span><span class="hljs-keyword">const</span> html = editor.<span class="hljs-title function_">getHTML</span>();
<span class="hljs-comment">// Check current view mode</span><span class="hljs-keyword">const</span> view = editor.<span class="hljs-title function_">getCurrentView</span>(); <span class="hljs-comment">// 'src', 'html', or 'split'</span></code></pre></div><h3>View Management</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Switch views</span>
editor.<span class="hljs-title function_">setView</span>(<span class="hljs-string">'src'</span>); <span class="hljs-comment">// Source only</span>
editor.<span class="hljs-title function_">setView</span>(<span class="hljs-string">'html'</span>); <span class="hljs-comment">// HTML only </span>
editor.<span class="hljs-title function_">setView</span>(<span class="hljs-string">'split'</span>); <span class="hljs-comment">// Split view</span><span class="hljs-comment">// Toggle between views</span>
editor.<span class="hljs-title function_">toggleView</span>();
</code></pre></div><h2>Content Types</h2><p>SquibView supports multiple content types:</p><table><thead><tr><th>Type</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>md</code></td><td>Markdown (default)</td><td><code># Title\n\n**Bold text**</code></td></tr><tr><td><code>html</code></td><td>Raw HTML</td><td><code><h1>Title</h1><p>Text</p></code></td></tr><tr><td><code>csv</code></td><td>Comma-separated values</td><td><code>name,age\nJohn,25</code></td></tr><tr><td><code>tsv</code></td><td>Tab-separated values</td><td><code>name\tage\nJohn\t25</code></td></tr></tbody></table><h3>Markdown Features</h3><p>SquibView supports GitHub-Flavored Markdown including:</p><ul><li><strong>Headers</strong> (<code># ## ###</code>)</li><li><strong>Emphasis</strong> (<code>**bold**</code>, <code>*italic*</code>)</li><li><strong>Lists</strong> (ordered and unordered)</li><li><strong>Tables</strong> (with alignment)</li><li><strong>Code blocks</strong> (with syntax highlighting)</li><li><strong>Links and images</strong></li><li><strong>Blockquotes</strong></li></ul><h3>Special Content Blocks</h3><h4>Mermaid Diagrams</h4><div data-source-type="markdown"><pre><code class="hljs language-markdown" data-source-type="code" data-lang="markdown"><span class="hljs-code">```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
</span></code></pre></div><h4>Math Equations</h4><div data-source-type="markdown"><pre><code class="hljs language-markdown" data-source-type="code" data-lang="markdown">Inline math: $E = mc^2$
Block math:
$$
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
</code></pre></div><h4>Code with Syntax Highlighting</h4><div data-source-type="markdown"><pre><code class="hljs language-markdown" data-source-type="code" data-lang="markdown"><span class="hljs-code">```javascript
function hello() {
console.log('Hello, World!');
}
</span></code></pre></div><h4>GeoJSON Maps</h4><div data-source-type="markdown"><pre><code class="hljs language-markdown" data-source-type="code" data-lang="markdown"><span class="hljs-code">```geojson
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.0445, 40.6892]
},
"properties": {
"name": "Statue of Liberty"
}
}
</span></code></pre></div><h2>Event Handling</h2><p>SquibView uses an event system for communication:</p><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Listen for content changes</span>
editor.<span class="hljs-title function_">on</span>(<span class="hljs-string">'content-changed'</span>, <span class="hljs-function">(<span class="hljs-params">content, type</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Content updated:'</span>, content);
});
<span class="hljs-comment">// Listen for view changes</span>
editor.<span class="hljs-title function_">on</span>(<span class="hljs-string">'view-changed'</span>, <span class="hljs-function">(<span class="hljs-params">view</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'View changed to:'</span>, view);
});
<span class="hljs-comment">// Listen for selection changes</span>
editor.<span class="hljs-title function_">on</span>(<span class="hljs-string">'selection-changed'</span>, <span class="hljs-function">(<span class="hljs-params">selection</span>) =></span> {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">'Selected text:'</span>, selection.<span class="hljs-property">text</span>);
});
</code></pre></div><h2>Export and Copy</h2><h3>Copy to Clipboard</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Copy HTML to clipboard</span>
editor.<span class="hljs-title function_">copyHTML</span>();
<span class="hljs-comment">// Copy source to clipboard</span>
editor.<span class="hljs-title function_">copySource</span>();
</code></pre></div><h3>Export Content</h3><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// Get clean HTML for export</span><span class="hljs-keyword">const</span> exportHTML = editor.<span class="hljs-title function_">getHTML</span>();
<span class="hljs-comment">// Get current source content</span><span class="hljs-keyword">const</span> exportSource = editor.<span class="hljs-title function_">getContent</span>();
</code></pre></div><h2>Styling and Customization</h2><h3>Custom CSS</h3><div data-source-type="css"><pre><code class="hljs language-css" data-source-type="code" data-lang="css"><span class="hljs-comment">/* Override default styles */</span><span class="hljs-selector-class">.squibview</span> {
<span class="hljs-attribute">font-family</span>: <span class="hljs-string">'Custom Font'</span>, serif;
}
<span class="hljs-selector-class">.squibview</span><span class="hljs-selector-class">.source-panel</span> {
<span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f5f5f5</span>;
}
<span class="hljs-selector-class">.squibview</span><span class="hljs-selector-class">.html-panel</span> {
<span class="hljs-attribute">background-color</span>: white;
}
</code></pre></div><h3>Responsive Design</h3><p>SquibView automatically adapts to different screen sizes:</p><div data-source-type="css"><pre><code class="hljs language-css" data-source-type="code" data-lang="css"><span class="hljs-comment">/* Mobile-first styling */</span><span class="hljs-selector-class">.squibview</span> {
<span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width</span>: <span class="hljs-number">768px</span>) {
<span class="hljs-selector-class">.squibview</span> {
<span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
}
}
</code></pre></div><h2>Best Practices</h2><ol><li><p><strong>Initialize after DOM is ready</strong></p><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-variable language_">document</span>.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">'DOMContentLoaded'</span>, <span class="hljs-function">() =></span> {
<span class="hljs-keyword">const</span> editor = <span class="hljs-keyword">new</span><span class="hljs-title class_">SquibView</span>({ <span class="hljs-comment">/* options */</span> });
});
</code></pre></div></li><li><p><strong>Handle errors gracefully</strong></p><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-keyword">try</span> {
editor.<span class="hljs-title function_">setContent</span>(userContent, contentType);
} <span class="hljs-keyword">catch</span> (error) {
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'Failed to set content:'</span>, error);
}
</code></pre></div></li><li><p><strong>Clean up when done</strong></p><div data-source-type="javascript"><pre><code class="hljs language-javascript" data-source-type="code" data-lang="javascript"><span class="hljs-comment">// If your framework supports cleanup</span>
editor.<span class="hljs-property">destroy</span>?.();
</code></pre></div></li></ol><h2>Next Steps</h2><ul><li><strong><a href="./04-cli-usage.html">CLI Usage</a></strong> - Learn about the command-line interface</li><li><strong><a href="../features/02-graphical-content.html">Graphical Content</a></strong> - Explore visual features</li><li><strong><a href="../api/01-options.html">API Reference</a></strong> - Complete options documentation</li></ul></div>
<script>
// Initialize MathJax after page load
document.addEventListener('DOMContentLoaded', function() {
if (window.MathJax && window.MathJax.typesetPromise) {
window.MathJax.typesetPromise().catch(function(err) {
console.warn('MathJax typesetting failed:', err);
});
}
});
</script>
<script>
// Initialize Mermaid after page load
document.addEventListener('DOMContentLoaded', function() {
if (window.mermaid) {
try {
window.mermaid.initialize({
startOnLoad: false,
theme: 'default',
securityLevel: 'loose',
fontFamily: 'inherit'
});
// Manually render all mermaid diagrams
const mermaidElements = document.querySelectorAll('.mermaid');
mermaidElements.forEach(function(element, index) {
const id = 'mermaid-' + index;
element.id = id;
try {
window.mermaid.render(id + '-svg', element.textContent, function(svgCode) {
element.innerHTML = svgCode;
});
} catch (err) {
console.warn('Mermaid rendering failed for element', index, ':', err);
// Fallback: show the text content
element.innerHTML = '<pre>' + element.textContent + '</pre>';
}
});
} catch (err) {
console.warn('Mermaid initialization failed:', err);
}
}
});
</script>
</body>
</html>