york commited on
Commit
3e6ec56
·
verified ·
1 Parent(s): bbf20bd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +614 -19
index.html CHANGED
@@ -1,19 +1,614 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Modern Markdown Previewer</title>
7
+
8
+ <!-- Import Google Fonts -->
9
+ <link rel="preconnect" href="https://fonts.googleapis.com">
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
12
+
13
+ <!-- Import FontAwesome for Icons -->
14
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
15
+
16
+ <!-- Highlight.js CSS for Syntax Highlighting -->
17
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css">
18
+
19
+ <style>
20
+ /* --- CSS VARIABLES & THEME CONFIGURATION --- */
21
+ :root {
22
+ --primary-color: #3b82f6;
23
+ --primary-hover: #2563eb;
24
+ --bg-body: #f3f4f6;
25
+ --bg-panel: #ffffff;
26
+ --text-main: #1f2937;
27
+ --text-muted: #6b7280;
28
+ --border-color: #e5e7eb;
29
+ --code-bg: #f8fafc;
30
+ --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
31
+ --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
32
+ --radius-md: 0.5rem;
33
+ --radius-lg: 0.75rem;
34
+ --header-height: 60px;
35
+ --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
36
+ }
37
+
38
+ [data-theme="dark"] {
39
+ --bg-body: #0f172a;
40
+ --bg-panel: #1e293b;
41
+ --text-main: #f1f5f9;
42
+ --text-muted: #94a3b8;
43
+ --border-color: #334155;
44
+ --code-bg: #0d1117;
45
+ --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
46
+ --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
47
+ }
48
+
49
+ /* --- RESET & BASE STYLES --- */
50
+ * {
51
+ box-sizing: border-box;
52
+ margin: 0;
53
+ padding: 0;
54
+ }
55
+
56
+ body {
57
+ font-family: 'Inter', sans-serif;
58
+ background-color: var(--bg-body);
59
+ color: var(--text-main);
60
+ height: 100vh;
61
+ display: flex;
62
+ flex-direction: column;
63
+ overflow: hidden; /* Prevent body scroll, handle inside panels */
64
+ transition: background-color 0.3s ease, color 0.3s ease;
65
+ }
66
+
67
+ /* --- HEADER --- */
68
+ header {
69
+ height: var(--header-height);
70
+ background-color: var(--bg-panel);
71
+ border-bottom: 1px solid var(--border-color);
72
+ display: flex;
73
+ align-items: center;
74
+ justify-content: space-between;
75
+ padding: 0 1.5rem;
76
+ box-shadow: var(--shadow-sm);
77
+ z-index: 10;
78
+ }
79
+
80
+ .brand {
81
+ display: flex;
82
+ align-items: center;
83
+ gap: 0.75rem;
84
+ font-weight: 700;
85
+ font-size: 1.1rem;
86
+ color: var(--text-main);
87
+ text-decoration: none;
88
+ }
89
+
90
+ .brand i {
91
+ color: var(--primary-color);
92
+ }
93
+
94
+ .header-actions {
95
+ display: flex;
96
+ align-items: center;
97
+ gap: 1rem;
98
+ }
99
+
100
+ .btn-icon {
101
+ background: transparent;
102
+ border: 1px solid var(--border-color);
103
+ color: var(--text-muted);
104
+ width: 36px;
105
+ height: 36px;
106
+ border-radius: var(--radius-md);
107
+ display: flex;
108
+ align-items: center;
109
+ justify-content: center;
110
+ cursor: pointer;
111
+ transition: var(--transition);
112
+ font-size: 1rem;
113
+ }
114
+
115
+ .btn-icon:hover {
116
+ background-color: var(--code-bg);
117
+ color: var(--primary-color);
118
+ border-color: var(--primary-color);
119
+ }
120
+
121
+ .btn-primary {
122
+ background-color: var(--primary-color);
123
+ color: white;
124
+ border: none;
125
+ padding: 0.5rem 1rem;
126
+ border-radius: var(--radius-md);
127
+ font-weight: 500;
128
+ cursor: pointer;
129
+ display: flex;
130
+ align-items: center;
131
+ gap: 0.5rem;
132
+ transition: var(--transition);
133
+ font-size: 0.9rem;
134
+ }
135
+
136
+ .btn-primary:hover {
137
+ background-color: var(--primary-hover);
138
+ transform: translateY(-1px);
139
+ box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
140
+ }
141
+
142
+ /* --- MAIN LAYOUT --- */
143
+ main {
144
+ flex: 1;
145
+ display: grid;
146
+ grid-template-columns: 1fr 1fr;
147
+ height: calc(100vh - var(--header-height));
148
+ overflow: hidden;
149
+ }
150
+
151
+ /* --- EDITOR PANEL --- */
152
+ .editor-container {
153
+ display: flex;
154
+ flex-direction: column;
155
+ border-right: 1px solid var(--border-color);
156
+ background-color: var(--bg-panel);
157
+ position: relative;
158
+ }
159
+
160
+ .panel-header {
161
+ padding: 0.75rem 1rem;
162
+ border-bottom: 1px solid var(--border-color);
163
+ display: flex;
164
+ justify-content: space-between;
165
+ align-items: center;
166
+ background-color: rgba(255, 255, 255, 0.5);
167
+ backdrop-filter: blur(4px);
168
+ font-size: 0.85rem;
169
+ font-weight: 600;
170
+ color: var(--text-muted);
171
+ text-transform: uppercase;
172
+ letter-spacing: 0.05em;
173
+ }
174
+
175
+ .editor-wrapper {
176
+ flex: 1;
177
+ position: relative;
178
+ }
179
+
180
+ #markdown-input {
181
+ width: 100%;
182
+ height: 100%;
183
+ border: none;
184
+ resize: none;
185
+ padding: 1.5rem;
186
+ font-family: 'JetBrains Mono', monospace;
187
+ font-size: 0.95rem;
188
+ line-height: 1.6;
189
+ background-color: var(--bg-panel);
190
+ color: var(--text-main);
191
+ outline: none;
192
+ }
193
+
194
+ /* --- PREVIEW PANEL --- */
195
+ .preview-container {
196
+ background-color: var(--bg-body);
197
+ overflow-y: auto;
198
+ position: relative;
199
+ }
200
+
201
+ #preview-output {
202
+ max-width: 800px;
203
+ margin: 0 auto;
204
+ padding: 2rem;
205
+ background-color: var(--bg-panel);
206
+ min-height: 100%;
207
+ box-shadow: var(--shadow-sm);
208
+ border-top: 1px solid var(--border-color);
209
+ border-bottom: 1px solid var(--border-color);
210
+ }
211
+
212
+ /* --- MARKDOWN STYLING (Inside Preview) --- */
213
+ #preview-output h1, #preview-output h2, #preview-output h3 {
214
+ margin-top: 1.5rem;
215
+ margin-bottom: 0.75rem;
216
+ line-height: 1.2;
217
+ color: var(--text-main);
218
+ }
219
+
220
+ #preview-output h1 { font-size: 2.25rem; font-weight: 800; border-bottom: 2px solid var(--border-color); padding-bottom: 0.5rem; }
221
+ #preview-output h2 { font-size: 1.75rem; font-weight: 700; border-bottom: 1px solid var(--border-color); padding-bottom: 0.25rem; }
222
+ #preview-output h3 { font-size: 1.35rem; font-weight: 600; }
223
+
224
+ #preview-output p {
225
+ margin-bottom: 1rem;
226
+ line-height: 1.7;
227
+ color: var(--text-main);
228
+ }
229
+
230
+ #preview-output ul, #preview-output ol {
231
+ margin-bottom: 1rem;
232
+ padding-left: 1.5rem;
233
+ }
234
+
235
+ #preview-output li {
236
+ margin-bottom: 0.25rem;
237
+ line-height: 1.6;
238
+ }
239
+
240
+ #preview-output code {
241
+ font-family: 'JetBrains Mono', monospace;
242
+ font-size: 0.9em;
243
+ background-color: rgba(59, 130, 246, 0.1);
244
+ color: var(--primary-color);
245
+ padding: 0.2em 0.4em;
246
+ border-radius: 4px;
247
+ }
248
+
249
+ #preview-output pre {
250
+ background-color: var(--code-bg);
251
+ padding: 1rem;
252
+ border-radius: var(--radius-md);
253
+ overflow-x: auto;
254
+ margin-bottom: 1rem;
255
+ border: 1px solid var(--border-color);
256
+ }
257
+
258
+ #preview-output pre code {
259
+ background-color: transparent;
260
+ color: inherit;
261
+ padding: 0;
262
+ }
263
+
264
+ #preview-output blockquote {
265
+ border-left: 4px solid var(--primary-color);
266
+ padding-left: 1rem;
267
+ margin: 1rem 0;
268
+ color: var(--text-muted);
269
+ font-style: italic;
270
+ background: rgba(59, 130, 246, 0.05);
271
+ padding-top: 0.5rem;
272
+ padding-bottom: 0.5rem;
273
+ border-radius: 0 4px 4px 0;
274
+ }
275
+
276
+ #preview-output a {
277
+ color: var(--primary-color);
278
+ text-decoration: none;
279
+ font-weight: 500;
280
+ }
281
+
282
+ #preview-output a:hover {
283
+ text-decoration: underline;
284
+ }
285
+
286
+ #preview-output img {
287
+ max-width: 100%;
288
+ border-radius: var(--radius-md);
289
+ box-shadow: var(--shadow-md);
290
+ margin: 1rem 0;
291
+ }
292
+
293
+ #preview-output hr {
294
+ border: 0;
295
+ height: 1px;
296
+ background-image: linear-gradient(to right, rgba(0, 0, 0, 0), var(--border-color), rgba(0, 0, 0, 0));
297
+ margin: 2rem 0;
298
+ }
299
+
300
+ /* --- TOAST NOTIFICATION --- */
301
+ .toast {
302
+ position: fixed;
303
+ bottom: 2rem;
304
+ left: 50%;
305
+ transform: translateX(-50%) translateY(100px);
306
+ background-color: var(--text-main);
307
+ color: var(--bg-panel);
308
+ padding: 0.75rem 1.5rem;
309
+ border-radius: 50px;
310
+ box-shadow: var(--shadow-md);
311
+ opacity: 0;
312
+ transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
313
+ z-index: 100;
314
+ display: flex;
315
+ align-items: center;
316
+ gap: 0.5rem;
317
+ font-size: 0.9rem;
318
+ }
319
+
320
+ .toast.show {
321
+ transform: translateX(-50%) translateY(0);
322
+ opacity: 1;
323
+ }
324
+
325
+ /* --- RESPONSIVE DESIGN --- */
326
+ @media (max-width: 768px) {
327
+ main {
328
+ grid-template-columns: 1fr;
329
+ grid-template-rows: 1fr 1fr;
330
+ }
331
+
332
+ .editor-container {
333
+ border-right: none;
334
+ border-bottom: 1px solid var(--border-color);
335
+ }
336
+
337
+ #preview-output {
338
+ padding: 1rem;
339
+ }
340
+ }
341
+ </style>
342
+ </head>
343
+ <body>
344
+
345
+ <!-- Header Section -->
346
+ <header>
347
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="brand">
348
+ <i class="fa-solid fa-code"></i>
349
+ AnyCoder <span style="font-weight: 300; opacity: 0.7;">| Markdown Preview</span>
350
+ </a>
351
+
352
+ <div class="header-actions">
353
+ <button class="btn-icon" id="theme-toggle" title="Toggle Dark Mode">
354
+ <i class="fa-solid fa-moon"></i>
355
+ </button>
356
+ <button class="btn-icon" id="reset-btn" title="Reset Content">
357
+ <i class="fa-solid fa-rotate-right"></i>
358
+ </button>
359
+ <button class="btn-primary" id="download-btn">
360
+ <i class="fa-solid fa-download"></i> Download
361
+ </button>
362
+ </div>
363
+ </header>
364
+
365
+ <!-- Main Content Area -->
366
+ <main>
367
+ <!-- Editor Panel -->
368
+ <section class="editor-container">
369
+ <div class="panel-header">
370
+ <span><i class="fa-solid fa-pen-nib"></i> Input Markdown</span>
371
+ <span id="char-count">0 chars</span>
372
+ </div>
373
+ <div class="editor-wrapper">
374
+ <textarea id="markdown-input" spellcheck="false" placeholder="Type your markdown here..."># Hello World!
375
+
376
+ Welcome to this **Modern Markdown Previewer**.
377
+
378
+ ## Features
379
+ - **Real-time** preview
380
+ - **Syntax Highlighting** for code
381
+ - **Dark Mode** support
382
+ - **Responsive** layout
383
+
384
+ ### Example Code Block
385
+
386
+ \`\`\`javascript
387
+ function sayHello() {
388
+ console.log("Hello, AnyCoder!");
389
+ }
390
+ \`\`\`
391
+
392
+ > "The best way to predict the future is to create it." - Peter Drucker
393
+
394
+ [Click here for Hugging Face](https://huggingface.co/spaces/akhaliq/anycoder)
395
+ "></textarea>
396
+ </div>
397
+ </section>
398
+
399
+ <!-- Preview Panel -->
400
+ <section class="preview-container">
401
+ <div class="panel-header">
402
+ <span><i class="fa-solid fa-eye"></i> Live Preview</span>
403
+ </div>
404
+ <div id="preview-output"></div>
405
+ </section>
406
+ </main>
407
+
408
+ <!-- Toast Notification -->
409
+ <div id="toast" class="toast">
410
+ <i class="fa-solid fa-check-circle"></i> <span id="toast-message">Action Successful</span>
411
+ </div>
412
+
413
+ <!-- Highlight.js Library -->
414
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
415
+
416
+ <script>
417
+ /**
418
+ * AnyCoder Markdown Previewer Logic
419
+ * Handles Markdown parsing, Syntax Highlighting, Theming, and Interactions
420
+ */
421
+
422
+ // DOM Elements
423
+ const input = document.getElementById('markdown-input');
424
+ const output = document.getElementById('preview-output');
425
+ const themeToggle = document.getElementById('theme-toggle');
426
+ const resetBtn = document.getElementById('reset-btn');
427
+ const downloadBtn = document.getElementById('download-btn');
428
+ const charCount = document.getElementById('char-count');
429
+ const toast = document.getElementById('toast');
430
+ const toastMsg = document.getElementById('toast-message');
431
+
432
+ // Default Content
433
+ const defaultContent = `# Hello World!
434
+
435
+ Welcome to this **Modern Markdown Previewer**.
436
+
437
+ ## Features
438
+ - **Real-time** preview
439
+ - **Syntax Highlighting** for code
440
+ - **Dark Mode** support
441
+ - **Responsive** layout
442
+
443
+ ### Example Code Block
444
+
445
+ \`\`\`javascript
446
+ function sayHello() {
447
+ console.log("Hello, AnyCoder!");
448
+ }
449
+ \`\`\`
450
+
451
+ > "The best way to predict the future is to create it." - Peter Drucker
452
+
453
+ [Click here for Hugging Face](https://huggingface.co/spaces/akhaliq/anycoder)
454
+ `;
455
+
456
+ // --- Core Markdown Parser ---
457
+ // A simple, lightweight regex-based parser to avoid heavy external dependencies like marked.js
458
+ function parseMarkdown(text) {
459
+ let html = text;
460
+
461
+ // Escape HTML (Basic sanitization)
462
+ html = html.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
463
+
464
+ // Headers (H1 - H6)
465
+ html = html.replace(/^###### (.*$)/gim, '<h6>$1</h6>');
466
+ html = html.replace(/^##### (.*$)/gim, '<h5>$1</h5>');
467
+ html = html.replace(/^#### (.*$)/gim, '<h4>$1</h4>');
468
+ html = html.replace(/^### (.*$)/gim, '<h3>$1</h3>');
469
+ html = html.replace(/^## (.*$)/gim, '<h2>$1</h2>');
470
+ html = html.replace(/^# (.*$)/gim, '<h1>$1</h1>');
471
+
472
+ // Bold and Italic
473
+ html = html.replace(/\*\*\*(.*)\*\*\*/gim, '<strong><em>$1</em></strong>');
474
+ html = html.replace(/\*\*(.*)\*\*/gim, '<strong>$1</strong>');
475
+ html = html.replace(/\*(.*)\*/gim, '<em>$1</em>');
476
+ html = html.replace(/___(.*)___/gim, '<strong><em>$1</em></strong>');
477
+ html = html.replace(/__(.*)__/gim, '<strong>$1</strong>');
478
+ html = html.replace(/_(.*)_/gim, '<em>$1</em>');
479
+
480
+ // Blockquotes
481
+ html = html.replace(/^\> (.*$)/gim, '<blockquote>$1</blockquote>');
482
+
483
+ // Images
484
+ html = html.replace(/!\[(.*?)\]\((.*?)\)/gim, "<img alt='$1' src='$2' />");
485
+
486
+ // Links
487
+ html = html.replace(/\[(.*?)\]\((.*?)\)/gim, "<a href='$2' target='_blank'>$1</a>");
488
+
489
+ // Code Blocks (Pre/Code)
490
+ html = html.replace(/```([\s\S]*?)```/gim, "<pre><code class='language-js'>$1</code></pre>");
491
+
492
+ // Inline Code
493
+ html = html.replace(/`(.*)`/gim, "<code>$1</code>");
494
+
495
+ // Horizontal Rule
496
+ html = html.replace(/^---$/gim, '<hr>');
497
+
498
+ // Unordered Lists
499
+ html = html.replace(/^\s*-\s(.*$)/gim, '<ul><li>$1</li></ul>');
500
+ // Clean up consecutive uls
501
+ html = html.replace(/<\/ul>\s*<ul>/gim, '');
502
+
503
+ // Ordered Lists
504
+ html = html.replace(/^\s*\d+\.\s(.*$)/gim, '<ol><li>$1</li></ol>');
505
+ // Clean up consecutive ols
506
+ html = html.replace(/<\/ol>\s*<ol>/gim, '');
507
+
508
+ // Paragraphs
509
+ // Match lines not starting with HTML tags, and wrap them in <p>
510
+ // This is a simplified approach for a single-file demo
511
+ html = html.split('\n').map(line => {
512
+ if (line.trim() !== '' && !line.match(/^<(h|ul|ol|li|pre|blockquote|hr)/)) {
513
+ return `<p>${line}</p>`;
514
+ }
515
+ return line;
516
+ }).join('');
517
+
518
+ return html;
519
+ }
520
+
521
+ // --- Update Function ---
522
+ function updatePreview() {
523
+ const rawMarkdown = input.value;
524
+ const parsedHTML = parseMarkdown(rawMarkdown);
525
+
526
+ // Apply HTML
527
+ output.innerHTML = parsedHTML;
528
+
529
+ // Highlight Code Blocks
530
+ output.querySelectorAll('pre code').forEach((block) => {
531
+ hljs.highlightElement(block);
532
+ });
533
+
534
+ // Update Char Count
535
+ charCount.textContent = `${rawMarkdown.length} chars`;
536
+ }
537
+
538
+ // --- Theme Handling ---
539
+ function toggleTheme() {
540
+ const body = document.body;
541
+ const currentTheme = body.getAttribute('data-theme');
542
+ const icon = themeToggle.querySelector('i');
543
+
544
+ if (currentTheme === 'dark') {
545
+ body.removeAttribute('data-theme');
546
+ icon.classList.remove('fa-sun');
547
+ icon.classList.add('fa-moon');
548
+ localStorage.setItem('theme', 'light');
549
+ } else {
550
+ body.setAttribute('data-theme', 'dark');
551
+ icon.classList.remove('fa-moon');
552
+ icon.classList.add('fa-sun');
553
+ localStorage.setItem('theme', 'dark');
554
+ }
555
+ }
556
+
557
+ // --- Toast Notification ---
558
+ function showToast(message) {
559
+ toastMsg.textContent = message;
560
+ toast.classList.add('show');
561
+ setTimeout(() => {
562
+ toast.classList.remove('show');
563
+ }, 3000);
564
+ }
565
+
566
+ // --- Event Listeners ---
567
+
568
+ // Input Listener
569
+ input.addEventListener('input', updatePreview);
570
+
571
+ // Theme Toggle
572
+ themeToggle.addEventListener('click', toggleTheme);
573
+
574
+ // Reset Button
575
+ resetBtn.addEventListener('click', () => {
576
+ if(confirm("Are you sure you want to reset the content?")) {
577
+ input.value = defaultContent;
578
+ updatePreview();
579
+ showToast("Content reset to default");
580
+ }
581
+ });
582
+
583
+ // Download Button
584
+ downloadBtn.addEventListener('click', () => {
585
+ const blob = new Blob([input.value], { type: 'text/markdown' });
586
+ const url = URL.createObjectURL(blob);
587
+ const a = document.createElement('a');
588
+ a.href = url;
589
+ a.download = 'markdown-file.md';
590
+ document.body.appendChild(a);
591
+ a.click();
592
+ document.body.removeChild(a);
593
+ URL.revokeObjectURL(url);
594
+ showToast("Markdown file downloaded!");
595
+ });
596
+
597
+ // Load Saved Theme
598
+ window.addEventListener('DOMContentLoaded', () => {
599
+ const savedTheme = localStorage.getItem('theme');
600
+ const icon = themeToggle.querySelector('i');
601
+
602
+ if (savedTheme === 'dark') {
603
+ document.body.setAttribute('data-theme', 'dark');
604
+ icon.classList.remove('fa-moon');
605
+ icon.classList.add('fa-sun');
606
+ }
607
+
608
+ // Initialize
609
+ updatePreview();
610
+ });
611
+
612
+ </script>
613
+ </body>
614
+ </html>