-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd.html
More file actions
85 lines (75 loc) · 2.01 KB
/
md.html
File metadata and controls
85 lines (75 loc) · 2.01 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple Markdown Editor</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
height: 100vh;
margin: 0;
background: #f5f5f5;
}
#editor, #preview {
width: 50%;
padding: 1rem;
box-sizing: border-box;
overflow-y: auto;
height: 100vh;
}
#editor {
border-right: 1px solid #ccc;
background: white;
}
#markdown-input {
width: 100%;
height: 100%;
border: none;
resize: none;
font-size: 1rem;
font-family: monospace;
outline: none;
}
#preview {
background: white;
}
</style>
</head>
<body>
<section id="editor">
<textarea id="markdown-input" placeholder="Write your Markdown here..."></textarea>
</section>
<section id="preview">
<!-- Rendered HTML preview will appear here -->
</section>
<!-- Marked library for Markdown parsing -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
const input = document.getElementById('markdown-input');
const preview = document.getElementById('preview');
// Function to update the preview by parsing Markdown to HTML
function updatePreview() {
const markdownText = input.value;
// Convert markdown to HTML safely
const html = marked.parse(markdownText, { breaks: true });
preview.innerHTML = html;
}
// Update preview on input
input.addEventListener('input', updatePreview);
// Initialize with some sample Markdown content
input.value = `# Welcome to Markdown Editor
Type your **Markdown** on the left, and see the _live preview_ on the right.
- Easy to use
- Live preview
- Supports **bold**, *italic*, \`code\`, [links](https://example.com), and more!
\`\`\`js
// Sample code block
console.log('Hello, Markdown!');
\`\`\`
`;
updatePreview();
</script>
</body>
</html>