-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdedit (1).html
More file actions
180 lines (154 loc) · 5.22 KB
/
mdedit (1).html
File metadata and controls
180 lines (154 loc) · 5.22 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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Usage</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css/github-markdown-dark.min.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
<script src="https://cdn.jsdelivr.net/npm/marked-katex-extension/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<style>
body {
margin: 0;
padding: 20px;
box-sizing: border-box;
background: #0d1117;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.container {
width: 100%;
max-width: 900px;
}
.markdown-body {
width: 100%;
overflow-wrap: break-word;
}
.katex-display {
display: block !important;
text-align: center;
margin: 10px 0;
font-size: 1em;
}
.toc {
display: none;
}
pre,
code {
user-select: text;
}
input[type="file"] {
margin-bottom: 20px;
}
</style>
</head>
<body>
<!-- 上传文件按钮 -->
<input type="file" id="fileInput" accept=".md" />
<div class="container">
<article id="content" class="markdown-body"></article>
</div>
<script>
marked.use(markedKatex());
marked.setOptions({
highlight: (code, lang) => {
if (lang && hljs.getLanguage(lang)) return hljs.highlight(code, { language: lang }).value;
return hljs.highlightAuto(code).value;
}
});
// 解析上传的 Markdown 文件
function parseMarkdown(file) {
const reader = new FileReader();
reader.onload = function (e) {
const md = e.target.result;
document.getElementById('content').innerHTML = marked.parse(md, { headerIds: true, mangle: false });
document.querySelectorAll('h2,h3,h4').forEach(h => {
h.id = h.innerText.toLowerCase().replace(/\s+/g, '-');
});
hljs.highlightAll();
resizeKatex();
};
reader.readAsText(file);
}
function resizeKatex() {
const w = document.querySelector('.markdown-body').clientWidth;
document.querySelectorAll('.katex-display').forEach(e => {
e.style.fontSize = ''; // 恢复默认大小
const actual = e.scrollWidth;
if (actual > w) {
const fs = parseFloat(getComputedStyle(e).fontSize);
e.style.fontSize = (fs * w / actual) + 'px';
}
});
}
// 文件上传事件
document.getElementById('fileInput').addEventListener('change', function (e) {
const file = e.target.files[0];
if (file && file.type === "text/markdown") {
parseMarkdown(file);
} else {
alert("请选择一个有效的 Markdown 文件!");
}
});
// 在页面加载时自动加载指定的 Markdown 文件
// window.addEventListener('load', function() {
// fetch('./usage.md')
// .then(res => res.text())
// .then(md => {
// content.innerHTML = marked.parse(md, { headerIds: true, mangle: false });
// content.querySelectorAll('h2,h3,h4').forEach(h => {
// h.id = h.innerText.toLowerCase().replace(/\s+/g, '-');
// });
// hljs.highlightAll();
// resizeKatex();
// })
// .catch(() => {
// content.innerHTML = `<p style="color: red;">Alas, the file <b>usage.md</b> was not found.</p>`;
// });
// });
function findScore(constant, target) {
if (target <= 0) return 600000;
if (target > constant + 1.5) return "Unable to deduce points";
if (target >= constant) {
if (target === constant + 1.5) return 1000000;
return Math.ceil(850000 + (target - constant) * 100000);
}
if (target >= Math.max(0, 0.5 * constant - 1.5)) {
const denominator = constant / 300000 + 1 / 100000;
const score = (target + constant * 11/6 + 8.5) / denominator;
return Math.min(Math.ceil(score), 849999);
}
if (Math.abs(constant - 3) < 1e-6) return 600000;
const score = 600000 + (target * 200000) / (constant - 3);
return Math.min(Math.ceil(score), 699999);
}
function updateOutput() {
const input = document.getElementById("constantInput").value;
const output = document.getElementById("output");
if (input === "") {
output.textContent = "reality\tscore\n请填写 c (constant),结果将以公式形式计算";
return;
}
const c = parseFloat(input);
let result = "reality\tscore\n";
// 先计算所有结果
const data = [];
for (let r = 0; r <= c + 1.5; r += 0.01) {
const score = findScore(c, parseFloat(r.toFixed(2)));
data.push({ r: r.toFixed(2), s: score });
}
// 倒序输出
for (let i = data.length - 1; i >= 0; i--) {
result += `${data[i].r}\t${data[i].s}\n`;
}
output.textContent = result;
}
</script>
</body>
</html>