-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkdownFilter.html
110 lines (94 loc) · 3.15 KB
/
markdownFilter.html
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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown 过滤器</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h1 {
text-align: center;
color: #333;
}
textarea {
width: 100%;
height: 200px;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
resize: vertical;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Markdown 过滤器</h1>
<textarea id="input" placeholder="在这里粘贴您的 Markdown 内容..."></textarea>
<button onclick="filterMarkdown()">过滤</button>
<textarea id="output" placeholder="过滤后的内容将显示在这里..." readonly></textarea>
</div>
<script>
function filterMarkdown() {
const input = document.getElementById('input').value;
const output = document.getElementById('output');
let filtered = input;
// 移除 Jekyll 元数据
filtered = filtered.replace(/^---[\s\S]*?---/, '');
// 移除 HTML 标签
filtered = filtered.replace(/<[^>]*>/g, '');
// 移除图片
filtered = filtered.replace(/!\[.*?\]\(.*?\)/g, '');
// 移除链接,但保留链接文本
filtered = filtered.replace(/\[([^\]]+)\]\(.*?\)/g, '$1');
// 移除代码块
filtered = filtered.replace(/```[\s\S]*?```/g, '');
// 移除行内代码
filtered = filtered.replace(/`[^`\n]+`/g, '');
// 移除标题符号 (#)
filtered = filtered.replace(/^#{1,6}\s/gm, '');
// 移除列表符号
filtered = filtered.replace(/^[-*+]\s/gm, '');
// 移除数字列表
filtered = filtered.replace(/^\d+\.\s/gm, '');
// 移除引用符号
filtered = filtered.replace(/^>\s/gm, '');
// 移除水平线
filtered = filtered.replace(/^[-*_]{3,}\s*$/gm, '');
// 移除表格
filtered = filtered.replace(/^\|.*\|$/gm, '');
// 移除多余的空行
filtered = filtered.replace(/\n{3,}/g, '\n\n');
output.value = filtered.trim();
}
</script>
</body>
</html>