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>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>词性标注工具</title>
<style>
/* 全局样式 */
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;
padding: 0;
background-color: #f9f9f9;
@@ -99,8 +100,8 @@
background-color: #218838;
}
</style>
</head>
<body>
</head>
<body>
<div class="container">
<h1>词性标注工具</h1>
@@ -114,7 +115,7 @@
<div id="file-upload-container" class="input-container active">
<form action="/process" method="post" enctype="multipart/form-data">
<label for="file">选择文件:</label>
<input type="file" name="file" id="file">
<input type="file" name="file" id="file" />
<div class="form-actions">
<button type="submit">提交文本</button>
</div>
@@ -125,7 +126,12 @@
<div id="text-paste-container" class="input-container">
<form action="/process" method="post">
<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">
<button type="submit">提交文本</button>
</div>
@@ -146,5 +152,5 @@
}
}
</script>
</body>
</body>
</html>

View File

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