format code

This commit is contained in:
2025-07-06 21:49:41 +08:00
parent 8b6542dc91
commit afc49a4ea4
5 changed files with 250 additions and 223 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,13 +1,14 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>词性标注工具</title> <title>词性标注工具</title>
<style> <style>
/* 全局样式 */ /* 全局样式 */
body { body {
font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans", Arial, sans-serif; font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans", Arial,
sans-serif;
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #f9f9f9; background-color: #f9f9f9;
@@ -99,8 +100,8 @@
background-color: #218838; background-color: #218838;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>词性标注工具</h1> <h1>词性标注工具</h1>
@@ -114,7 +115,7 @@
<div id="file-upload-container" class="input-container active"> <div id="file-upload-container" class="input-container active">
<form action="/process" method="post" enctype="multipart/form-data"> <form action="/process" method="post" enctype="multipart/form-data">
<label for="file">选择文件:</label> <label for="file">选择文件:</label>
<input type="file" name="file" id="file"> <input type="file" name="file" id="file" />
<div class="form-actions"> <div class="form-actions">
<button type="submit">提交文本</button> <button type="submit">提交文本</button>
</div> </div>
@@ -125,7 +126,12 @@
<div id="text-paste-container" class="input-container"> <div id="text-paste-container" class="input-container">
<form action="/process" method="post"> <form action="/process" method="post">
<label for="text">粘贴文本:</label> <label for="text">粘贴文本:</label>
<textarea name="text" id="text" rows="10" placeholder="在这里粘贴要处理的文本"></textarea> <textarea
name="text"
id="text"
rows="10"
placeholder="在这里粘贴要处理的文本"
></textarea>
<div class="form-actions"> <div class="form-actions">
<button type="submit">提交文本</button> <button type="submit">提交文本</button>
</div> </div>
@@ -146,5 +152,5 @@
} }
} }
</script> </script>
</body> </body>
</html> </html>

View File

@@ -1,8 +1,8 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>标注结果</title> <title>标注结果</title>
<style> <style>
body { body {
@@ -15,7 +15,8 @@
} }
#result { #result {
font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans", "Noto Sans CJK SC", Arial, sans-serif; font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans",
"Noto Sans CJK SC", Arial, sans-serif;
font-size: 16px; font-size: 16px;
color: #333; color: #333;
line-height: 1.8; line-height: 1.8;
@@ -51,34 +52,54 @@
text-align: justify; text-align: justify;
} }
.word.n { color: red; } .word.n {
.word.v { color: blue; } color: red;
.word.a { color: green; } }
.word.d { color: orange; } .word.v {
color: blue;
}
.word.a {
color: green;
}
.word.d {
color: orange;
}
.word.hidden { color: inherit !important; } .word.hidden {
color: inherit !important;
}
</style> </style>
</head> </head>
<body> <body>
<h1>标注结果</h1> <h1>标注结果</h1>
<!-- 返回按钮 --> <!-- 返回按钮 -->
<a href="/" id="return">返回</a> <a href="/" id="return">返回</a>
<!-- 词性说明与控制 --> <!-- 词性说明与控制 -->
<div style="margin-bottom: 10px;"> <div style="margin-bottom: 10px">
<strong>词性显示控制:</strong> <strong>词性显示控制:</strong>
<label><input type="checkbox" id="toggle-n" checked> <span style="color: red;">名词</span></label> <label
<label><input type="checkbox" id="toggle-a" checked> <span style="color: green;">形容词</span></label> ><input type="checkbox" id="toggle-n" checked />
<span style="color: red">名词</span></label
>
<label
><input type="checkbox" id="toggle-a" checked />
<span style="color: green">形容词</span></label
>
<label><input type="checkbox" id="toggle-v"> <span style="color: blue;">动词</span></label> <label
<label><input type="checkbox" id="toggle-d"> <span style="color: orange;">副词</span></label> ><input type="checkbox" id="toggle-v" />
<span style="color: blue">动词</span></label
>
<label
><input type="checkbox" id="toggle-d" />
<span style="color: orange">副词</span></label
>
</div> </div>
<!-- 标注结果 --> <!-- 标注结果 -->
<div id="result"> <div id="result">{{ content | safe }}</div>
{{ content | safe }}
</div>
<div> <div>
<strong>导出结果:</strong> <strong>导出结果:</strong>
@@ -93,15 +114,15 @@
fetch("/export", { fetch("/export", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json",
}, },
body: JSON.stringify({ format: format, content: content }) // 确保键名正确 body: JSON.stringify({ format: format, content: content }), // 确保键名正确
}) })
.then(response => { .then((response) => {
if (response.ok) return response.blob(); if (response.ok) return response.blob();
throw new Error("导出失败"); throw new Error("导出失败");
}) })
.then(blob => { .then((blob) => {
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(blob);
const a = document.createElement("a"); const a = document.createElement("a");
a.style.display = "none"; a.style.display = "none";
@@ -111,8 +132,8 @@
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
}) })
.catch(err => alert(err.message)); .catch((err) => alert(err.message));
} }
</script> </script>
<script> <script>
@@ -129,7 +150,7 @@
Object.entries(toggles).forEach(([tag, checkbox]) => { Object.entries(toggles).forEach(([tag, checkbox]) => {
checkbox.addEventListener("change", () => { checkbox.addEventListener("change", () => {
const words = resultDiv.querySelectorAll(`.word.${tag}`); const words = resultDiv.querySelectorAll(`.word.${tag}`);
words.forEach(word => { words.forEach((word) => {
if (checkbox.checked) { if (checkbox.checked) {
word.classList.remove("hidden"); // 恢复颜色 word.classList.remove("hidden"); // 恢复颜色
} else { } else {
@@ -139,5 +160,5 @@
}); });
}); });
</script> </script>
</body> </body>
</html> </html>