-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.html
More file actions
371 lines (335 loc) · 10.4 KB
/
Copy patheditor.html
File metadata and controls
371 lines (335 loc) · 10.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>Markdown Editor · MX</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #f5f5f5;
color: #222;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.toolbar {
margin-bottom: 20px;
background: #fff;
padding: 16px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.btn {
padding: 6px 12px;
border-radius: 6px;
border: 1px solid #ddd;
background: #fff;
cursor: pointer;
font-size: 12px;
font-weight: 500;
margin-right: 5px;
}
.btn:hover {
background: #f5f5f5;
}
.btn.primary {
background: #2563eb;
color: #fff;
border-color: #2563eb;
}
.btn.primary:hover {
background: #1d4ed8;
}
.form-row {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 20px;
background: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.form-group {
margin-bottom: 16px;
}
.form-label {
display: block;
font-size: 14px;
font-weight: 500;
margin-bottom: 4px;
}
.form-input {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
}
.form-select {
width: 100%;
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
background: #fff;
}
.editor-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
height: calc(100vh - 250px);
}
.editor-panel, .preview-panel {
background: #fff;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.03);
padding: 20px;
display: flex;
flex-direction: column;
}
.panel-title {
font-weight: 600;
margin-bottom: 16px;
padding-bottom: 12px;
border-bottom: 1px solid #eee;
}
textarea {
flex: 1;
border: none;
outline: none;
resize: none;
font-family: 'Monaco', 'Consolas', monospace;
font-size: 14px;
line-height: 1.5;
padding: 0;
}
.preview-content {
flex: 1;
overflow-y: auto;
line-height: 1.6;
}
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4 {
margin-top: 1.5em;
margin-bottom: 0.5em;
}
.preview-content h1 { font-size: 2em; }
.preview-content h2 { font-size: 1.5em; }
.preview-content h3 { font-size: 1.2em; }
.preview-content p { margin: 1em 0; }
.preview-content code {
background: #f4f4f4;
padding: 2px 4px;
border-radius: 3px;
font-family: 'Monaco', 'Consolas', monospace;
}
.preview-content pre {
background: #f4f4f4;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
margin: 1em 0;
}
.preview-content pre code {
background: none;
padding: 0;
}
.preview-content blockquote {
border-left: 4px solid #ddd;
padding-left: 16px;
margin: 1em 0;
color: #666;
}
@media (max-width: 768px) {
.editor-container {
grid-template-columns: 1fr;
height: auto;
}
.editor-panel, .preview-panel {
height: 400px;
}
}
</style>
<link rel="stylesheet" href="theme.css" />
</head>
<body class="page-editor">
<div class="container">
<!-- 表单区域 -->
<div class="form-row">
<div class="form-group">
<label class="form-label">标题</label>
<input type="text" id="post-title" class="form-input" placeholder="输入文章标题">
</div>
<div class="form-group">
<label class="form-label">栏目</label>
<select id="post-category" class="form-select">
<option value="blog">Blog</option>
<option value="competitive-programming">Competitive Programming</option>
<option value="game-jam">Game Jam</option>
<option value="projects">Projects</option>
<option value="art">Art</option>
</select>
</div>
</div>
<!-- 工具栏 -->
<div class="toolbar">
<button class="btn" onclick="insertMarkdown('**', '**')">粗体</button>
<button class="btn" onclick="insertMarkdown('*', '*')">斜体</button>
<button class="btn" onclick="insertMarkdown('# ', '')">标题</button>
<button class="btn" onclick="insertMarkdown('- ', '')">列表</button>
<button class="btn" onclick="insertMarkdown('```\n', '\n```')">代码块</button>
<button class="btn" onclick="insertMarkdown('[', '](url)')">链接</button>
<button class="btn" onclick="insertMarkdown('')">图片</button>
<button class="btn primary" onclick="generateMarkdown()">生成Markdown</button>
<button class="btn" onclick="loadDraft()">加载草稿</button>
<button class="btn" onclick="clearEditor()">清空</button>
</div>
<!-- 编辑器和预览 -->
<div class="editor-container">
<div class="editor-panel">
<div class="panel-title">Markdown 编辑器</div>
<textarea id="markdown-input" placeholder="在这里输入 Markdown 内容...
# 标题示例
这是**粗体**文本,这是*斜体*文本。
## 列表
- 项目1
- 项目2
- 项目3
## 代码块
```javascript
console.log('Hello World!');
```
## 链接和图片
[链接文本](https://example.com)
"></textarea>
</div>
<div class="preview-panel">
<div class="panel-title">实时预览</div>
<div id="preview-content" class="preview-content">
<p style="color: #999; font-style: italic;">预览将在这里显示...</p>
</div>
</div>
</div>
</div>
<footer style="text-align: center; padding: 20px; color: #666;">
© <span id="year"></span> MX · Built with GitHub Pages
</footer>
<script src="theme.js"></script>
<script>
function slugify(text) {
return text
.toLowerCase()
.trim()
.replace(/[^a-z0-9\u4e00-\u9fa5]+/g, '-')
.replace(/^-+|-+$/g, '');
}
function insertMarkdown(before, after) {
const input = document.getElementById('markdown-input');
if (!input) return;
const start = input.selectionStart;
const end = input.selectionEnd;
const selectedText = input.value.substring(start, end);
const replacement = before + selectedText + after;
input.value = input.value.substring(0, start) + replacement + input.value.substring(end);
input.focus();
const newPos = start + before.length + selectedText.length;
input.selectionStart = newPos;
input.selectionEnd = newPos;
updatePreview();
}
function updatePreview() {
const input = document.getElementById('markdown-input');
const output = document.getElementById('preview-content');
if (!input || !output) return;
const markdown = input.value.trim();
if (!markdown) {
output.innerHTML = '<p style="color: #999; font-style: italic;">预览将在这里显示...</p>';
return;
}
if (typeof marked !== 'undefined' && marked.parse) {
output.innerHTML = marked.parse(markdown);
} else {
output.innerHTML = markdown.replace(/\n/g, '<br>');
}
}
function generateMarkdown() {
const title = document.getElementById('post-title').value.trim();
const category = document.getElementById('post-category').value;
const content = document.getElementById('markdown-input').value.trim();
if (!title || !content) {
alert('请填写标题和内容');
return;
}
const now = new Date();
const dateStr = now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0');
let folderName = '_posts';
let fileName = `${dateStr}-${slugify(title)}.md`;
if (category !== 'blog') {
const folderMap = {
'competitive-programming': '_cp',
'game-jam': '_gamejam',
'projects': '_projects',
'art': '_art'
};
folderName = folderMap[category] || category;
fileName = `${slugify(title)}.md`;
}
const frontMatter = `---\ntitle: "${title}"\ndate: ${dateStr}\ncategory: ${category}\n---\n\n`;
const markdownContent = frontMatter + content + '\n';
const blob = new Blob([markdownContent], { type: 'text/markdown' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
alert(`Markdown文章已生成:${fileName}\n请将文件保存到 ${folderName}/ 文件夹中。`);
}
function loadDraft() {
const draft = localStorage.getItem('markdown-draft');
if (draft) {
document.getElementById('markdown-input').value = draft;
updatePreview();
alert('草稿已加载');
} else {
alert('没有找到草稿');
}
}
function clearEditor() {
if (!confirm('确定要清空所有内容吗?')) return;
document.getElementById('post-title').value = '';
document.getElementById('markdown-input').value = '';
updatePreview();
localStorage.removeItem('markdown-draft');
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('year').textContent = new Date().getFullYear();
const input = document.getElementById('markdown-input');
if (input) {
input.addEventListener('input', function() {
updatePreview();
localStorage.setItem('markdown-draft', input.value);
});
}
const urlParams = new URLSearchParams(window.location.search);
const category = urlParams.get('category');
if (category) {
document.getElementById('post-category').value = category;
}
updatePreview();
});
</script>
</body>
</html>