-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_autoload_custom.html
More file actions
196 lines (171 loc) · 6 KB
/
example_autoload_custom.html
File metadata and controls
196 lines (171 loc) · 6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Autoload Example - SquibView</title>
<link rel="icon" 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>">
<!-- SquibView CSS -->
<link rel="stylesheet" href="../dist/squibview.min.css">
<!-- Base example styles -->
<link rel="stylesheet" href="examples.css">
<!-- Pre-load Highlight.js with GitHub Dark theme -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/rust.min.js"></script>
<style>
/* Page-specific styles */
.demo-section {
margin: 1.5rem 2rem;
}
.demo-title {
font-size: 1.1rem;
font-weight: 600;
color: #212529;
margin-bottom: 0.5rem;
}
.demo-description {
font-size: 0.9rem;
color: #495057;
margin-bottom: 1rem;
}
.demo-code {
background: #f8f9fa;
padding: 1rem;
border-radius: 4px;
margin-bottom: 1rem;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.875rem;
color: #495057;
border: 1px solid #dee2e6;
}
.editor-demo {
margin: 0 2rem 2rem 2rem;
border: 1px solid #dee2e6;
border-radius: 4px;
overflow: hidden;
height: 400px;
}
#editor1, #editor2 {
height: 100%;
}
/* Code blocks with GitHub Dark theme will show in editor */
.hljs {
background: #0d1117 !important;
color: #e6edf3 !important;
}
</style>
</head>
<body>
<div class="example-header">
<h1 class="example-title">SquibView Custom Autoload Example (ESM)</h1>
<div class="example-version" id="version-display"></div>
<p class="example-description">
Demonstrates custom autoload configurations: bring your own libraries, use custom CDNs, disable specific libraries.
</p>
</div>
<div class="demo-section">
<div class="demo-title">Example 1: Pre-loaded Highlight.js with GitHub Dark Theme</div>
<div class="demo-description">
Highlight.js is loaded before SquibView with GitHub Dark theme. The autoloader detects this and uses the existing instance.
</div>
<div class="demo-code">
<!-- Load highlight.js with custom theme before SquibView -->
<link rel="stylesheet" href=".../github-dark.min.css">
<script src=".../highlight.min.js"></script>
// SquibView will detect and use the pre-loaded library
const editor = new SquibView('#editor1', {
autoload_deps: { all: true } // Enable autoloading
});
</div>
</div>
<div class="editor-demo">
<div id="editor1"></div>
</div>
<div class="demo-section">
<div class="demo-title">Example 2: Custom CDN URLs & Disabled Libraries</div>
<div class="demo-description">
Uses jsDelivr CDN for Mermaid instead of default CDN, and disables MathJax autoloading completely.
</div>
<div class="demo-code">
const editor = new SquibView('#editor2', {
autoload_deps: {
mathjax: false, // Disable MathJax
mermaid: 'ondemand', // Use on-demand loading
hljs: 'ondemand',
leaflet: 'ondemand',
three: 'ondemand',
cdnUrls: {
mermaid: {
script: 'https://cdn.jsdelivr.net/npm/mermaid@10/...'
}
}
}
});
</div>
</div>
<div class="editor-demo">
<div id="editor2"></div>
</div>
<!-- Removed autoload status notification -->
<script type="module">
import SquibView from '../dist/squibview.esm.min.js';
// Removed monitoring code - autoloading is now silent
const init = async () => {
try {
// Set version display from the library
if (SquibView.version && SquibView.version.version) {
document.getElementById("version-display").textContent = `Version ${SquibView.version.version}`;
}
} catch (error) {
console.error('Failed to set version:', error);
}
try {
// Load sample content
const response = await fetch('./sample-content.md');
const content = await response.text();
// Editor 1: Will detect and use pre-loaded Highlight.js
const editor1 = new SquibView('#editor1', {
initialView: 'split',
showControls: true,
titleShow: false,
autoload_deps: { all: true } // Will detect pre-loaded hljs
});
editor1.setContent(content, 'md');
// Editor 2: Custom configuration
const editor2 = new SquibView('#editor2', {
initialView: 'split',
showControls: true,
titleShow: false,
autoload_deps: {
// Disable MathJax completely
mathjax: false,
mermaid: 'ondemand',
hljs: 'ondemand',
leaflet: 'ondemand',
three: 'ondemand',
// Use alternative CDN for Mermaid
cdnUrls: {
mermaid: {
script: 'https://cdn.jsdelivr.net/npm/mermaid@10.6.1/dist/mermaid.min.js'
}
// Other libraries use default CDNs
}
}
});
editor2.setContent(content, 'md');
// Make editors available globally
window.editor1 = editor1;
window.editor2 = editor2;
// Custom autoload configuration examples initialized
// Editor 1 uses pre-loaded Highlight.js
// Editor 2 uses custom Mermaid CDN with MathJax disabled
} catch (error) {
console.error('Failed to initialize:', error);
}
};
// Start initialization
init();
</script>
</body>
</html>