-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview-code-blocks.html
More file actions
337 lines (295 loc) · 10.6 KB
/
preview-code-blocks.html
File metadata and controls
337 lines (295 loc) · 10.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MainWP.dev Code Block Preview</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Our custom Highlight.js theme -->
<link href="dox-theme/assets/css/highlightjs-mainwp-dark.css" rel="stylesheet" />
<style>
:root {
--color-primary: #7fb100;
--color-secondary: #446200;
--color-text: #f2f3f2;
--color-text-muted: #aaa;
--color-background: #1c1d1b;
--color-border: #2d2e2c;
--color-code-background: #2a2b29;
--color-code-header-bg: #252624;
--dox-border-radius: 4px;
--font-family-code: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
line-height: 1.6;
color: var(--color-text);
background-color: var(--color-background);
padding: 2rem;
margin: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
}
/* Code block styles from _code.scss */
.code-block {
position: relative;
margin: 1.5rem 0;
border-radius: var(--dox-border-radius);
overflow: hidden;
background-color: var(--color-code-background);
border: 1px solid var(--color-border);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 1rem;
background-color: var(--color-code-header-bg);
border-bottom: 1px solid var(--color-border);
font-size: 0.875rem;
}
.language-label {
font-family: var(--font-family-code);
color: var(--color-text-muted);
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.copy-button {
background: transparent;
border: 1px solid var(--color-border);
border-radius: 3px;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
cursor: pointer;
color: var(--color-text-muted);
transition: all 0.2s ease;
}
.copy-button:hover {
background-color: var(--color-primary);
border-color: var(--color-primary);
color: white;
}
.copy-button.copied {
background-color: var(--color-secondary);
border-color: var(--color-secondary);
color: white;
}
/* Override specific hljs styles for our demo page */
pre {
margin: 0;
padding: 1rem !important;
padding-left: 2rem !important;
}
code {
padding: 0 !important;
}
/* Keep mobile adjustments for container/header */
@media (max-width: 768px) {
.code-block {
margin: 1rem 0;
border-radius: 3px;
}
.code-header {
padding: 0.375rem 0.75rem;
}
}
</style>
</head>
<body>
<div class="container">
<h1>MainWP.dev Code Block Preview</h1>
<p>This page shows how code blocks will appear on GitHub Pages. Now using Highlight.js for syntax highlighting.</p>
<h2>PHP Example</h2>
<div class="code-block">
<div class="code-header">
<span class="language-label">PHP</span>
<button class="copy-button">Copy</button>
</div>
<pre><code class="language-php">namespace MainWP\Dashboard;
class MainWP_Extensions_Handler {
public function __construct() {
add_action('admin_init', [$this, 'admin_init']);
}
public function admin_init() {
// Initialize extensions
$this->load_extensions();
}
private function load_extensions() {
// Load installed extensions
$extensions = get_option('mainwp_extensions', []);
foreach ($extensions as $extension) {
if ($this->is_extension_active($extension)) {
$this->activate_extension($extension);
}
}
}
}</code></pre>
</div>
<h2>JavaScript Example</h2>
<div class="code-block">
<div class="code-header">
<span class="language-label">JavaScript</span>
<button class="copy-button">Copy</button>
</div>
<pre><code class="language-javascript">document.addEventListener('DOMContentLoaded', function() {
const copyButtons = document.querySelectorAll('.copy-button');
copyButtons.forEach(button => {
button.addEventListener('click', function() {
const codeBlock = this.closest('.code-block');
const codeElement = codeBlock.querySelector('code');
navigator.clipboard.writeText(codeElement.textContent).then(() => {
button.textContent = 'Copied!';
button.classList.add('copied');
setTimeout(() => {
button.textContent = 'Copy';
button.classList.remove('copied');
}, 2000);
});
});
});
});</code></pre>
</div>
<h2>HTML Example</h2>
<div class="code-block">
<div class="code-header">
<span class="language-label">HTML</span>
<button class="copy-button">Copy</button>
</div>
<pre><code class="language-html"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example Page</title>
<link href="styles.css" rel="stylesheet">
</head>
<body>
<header>
<h1>MainWP Documentation</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">API</a></li>
<li><a href="#">Hooks</a></li>
</ul>
</nav>
</header>
<main>
<section id="content">
<p>This is a sample HTML document.</p>
</section>
</main>
</body>
</html></code></pre>
</div>
<h2>CSS Example</h2>
<div class="code-block">
<div class="code-header">
<span class="language-label">CSS</span>
<button class="copy-button">Copy</button>
</div>
<pre><code class="language-css">/* MainWP styles */
:root {
--color-primary: #7fb100;
--color-secondary: #446200;
--color-text: #f2f3f2;
--color-background: #1c1d1b;
}
body {
font-family: 'Inter', sans-serif;
color: var(--color-text);
background-color: var(--color-background);
line-height: 1.6;
margin: 0;
padding: 0;
}
header {
background-color: var(--color-primary);
padding: 1rem;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
nav ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
nav li {
margin-right: 1rem;
}
nav a {
color: white;
text-decoration: none;
font-weight: 500;
}
nav a:hover {
text-decoration: underline;
}</code></pre>
</div>
<h2>Bash Example</h2>
<div class="code-block">
<div class="code-header">
<span class="language-label">Bash</span>
<button class="copy-button">Copy</button>
</div>
<pre><code class="language-bash">#!/bin/bash
# Generate documentation for MainWP
echo "Starting documentation generation..."
# Clone repositories if they don't exist
if [ ! -d "sources/mainwp-dashboard" ]; then
git clone https://github.com/mainwp/mainwp.git sources/mainwp-dashboard
fi
if [ ! -d "sources/mainwp-child" ]; then
git clone https://github.com/mainwp/mainwp-child.git sources/mainwp-child
fi
# Run phpDocumentor
echo "Generating API documentation..."
php vendor/bin/phpdoc -c phpdoc/dashboard.xml
php vendor/bin/phpdoc -c phpdoc/child.xml
echo "Generating hooks documentation..."
cd hooks-generator
./generate-hooks.sh
cd ..
echo "Documentation generation complete!"</code></pre>
</div>
</div>
<!-- Highlight.js core script -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- Highlight.js language plugins -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/php.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/xml.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/bash.min.js"></script>
<script>
// Initialize highlight.js
document.addEventListener('DOMContentLoaded', function() {
// Initialize syntax highlighting
hljs.configure({
ignoreUnescapedHTML: true
});
hljs.highlightAll();
// Initialize copy buttons
const copyButtons = document.querySelectorAll('.copy-button');
copyButtons.forEach(button => {
button.addEventListener('click', function() {
const codeBlock = this.closest('.code-block');
const codeElement = codeBlock.querySelector('code');
navigator.clipboard.writeText(codeElement.textContent).then(() => {
button.textContent = 'Copied!';
button.classList.add('copied');
setTimeout(() => {
button.textContent = 'Copy';
button.classList.remove('copied');
}, 2000);
});
});
});
});
</script>
</body>
</html>