-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown-preview.html
More file actions
187 lines (155 loc) · 6.4 KB
/
markdown-preview.html
File metadata and controls
187 lines (155 loc) · 6.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Preview</title>
<link rel="stylesheet" href="common.css">
<script src="https://cdn.jsdelivr.net/npm/marked@15.0.4/marked.min.js"></script>
<style>
body { display: flex; flex-direction: column; }
.preview-content {
flex: 1;
padding: 20px;
overflow-y: auto;
background: rgba(255,255,255,0.3);
line-height: 1.7;
}
.preview-content h1 { font-size: 2rem; margin: 0 0 16px 0; border-bottom: 2px solid var(--accent-coral); padding-bottom: 8px; }
.preview-content h2 { font-size: 1.5rem; margin: 24px 0 12px 0; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 6px; }
.preview-content h3 { font-size: 1.25rem; margin: 20px 0 10px 0; }
.preview-content h4 { font-size: 1.1rem; margin: 16px 0 8px 0; }
.preview-content h5, .preview-content h6 { font-size: 1rem; margin: 12px 0 6px 0; }
.preview-content p { margin: 0 0 16px 0; }
.preview-content code {
background: rgba(0,0,0,0.06);
padding: 2px 6px;
border-radius: var(--radius-sm);
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
font-size: 0.9em;
}
.preview-content pre {
background: rgba(0,0,0,0.06);
padding: 16px;
border-radius: var(--radius-md);
overflow-x: auto;
margin: 0 0 16px 0;
}
.preview-content pre code {
background: none;
padding: 0;
font-size: 0.85rem;
line-height: 1.5;
}
.preview-content blockquote {
border-left: 4px solid var(--accent-blue);
margin: 0 0 16px 0;
padding: 8px 16px;
background: rgba(77, 150, 255, 0.1);
border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.preview-content blockquote p:last-child { margin-bottom: 0; }
.preview-content ul, .preview-content ol { margin: 0 0 16px 0; padding-left: 24px; }
.preview-content li { margin-bottom: 4px; }
.preview-content hr { border: none; border-top: 2px solid rgba(0,0,0,0.1); margin: 24px 0; }
.preview-content a { color: var(--accent-blue); text-decoration: none; }
.preview-content a:hover { text-decoration: underline; }
.preview-content img { max-width: 100%; border-radius: var(--radius-md); }
.preview-content table { border-collapse: collapse; width: 100%; margin: 0 0 16px 0; }
.preview-content th, .preview-content td { border: 1px solid rgba(0,0,0,0.1); padding: 8px 12px; text-align: left; }
.preview-content th { background: rgba(0,0,0,0.04); font-weight: 600; }
.empty-preview { color: var(--text-secondary); font-style: italic; }
</style>
</head>
<body>
<a href="index.html" class="back-link">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M19 12H5M12 19l-7-7 7-7"/>
</svg>
All Tools
</a>
<header>
<h1>Markdown Preview</h1>
<p class="subtitle">Live markdown to HTML preview</p>
</header>
<div class="controls">
<button id="clearBtn" class="secondary">Clear</button>
</div>
<div class="container">
<div class="pane">
<div class="pane-header">
<span class="label">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
</svg>
Markdown
</span>
</div>
<textarea id="markdownInput" placeholder="# Hello World
Write your **markdown** here...
- List item 1
- List item 2
> Blockquote
`inline code`
```
code block
```
[Link](https://example.com)" spellcheck="false"></textarea>
</div>
<div class="pane">
<div class="pane-header">
<span class="label">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="16 18 22 12 16 6"></polyline>
<polyline points="8 6 2 12 8 18"></polyline>
</svg>
Preview
</span>
<button id="copyHtml" class="copy-btn">Copy HTML</button>
</div>
<div id="preview" class="preview-content">
<p class="empty-preview">Preview will appear here...</p>
</div>
</div>
</div>
<script>
const markdownInput = document.getElementById('markdownInput');
const preview = document.getElementById('preview');
const clearBtn = document.getElementById('clearBtn');
const copyHtml = document.getElementById('copyHtml');
// Configure marked
marked.setOptions({
breaks: true,
gfm: true
});
function updatePreview() {
const md = markdownInput.value;
if (!md.trim()) {
preview.innerHTML = '<p class="empty-preview">Preview will appear here...</p>';
return;
}
preview.innerHTML = marked.parse(md);
}
markdownInput.addEventListener('input', updatePreview);
clearBtn.addEventListener('click', () => {
markdownInput.value = '';
updatePreview();
markdownInput.focus();
});
copyHtml.addEventListener('click', () => {
const html = preview.innerHTML;
if (!html || html.includes('empty-preview')) return;
navigator.clipboard.writeText(html).then(() => {
const originalText = copyHtml.textContent;
copyHtml.textContent = 'Copied!';
copyHtml.classList.add('copied');
setTimeout(() => {
copyHtml.textContent = originalText;
copyHtml.classList.remove('copied');
}, 2000);
});
});
</script>
</body>
</html>