前情提要:关于 $$ 符号的使用问题的说明(补),对于论坛公式的使用说明。
公式转换器 点击这里直接使用(可能不太稳定)。
源代码:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> MD 公式转换工具 </title>
<style>
:root {
--primary: #6366f1;
--primary-hover: #4f46e5;
--bg: #f8fafc;
--card-bg: rgba(255, 255, 255, 0.85);
--text-primary: #1e293b;
--text-secondary: #64748b;
--border: #e2e8f0;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--glass: rgba(255, 255, 255, 0.2);
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
--spacing: 1.5rem;
--radius: 12px;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0f172a;
--card-bg: rgba(15, 23, 42, 0.7);
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--border: #1e293b;
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.25), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
--glass: rgba(15, 23, 42, 0.4);
}
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: var(--bg);
color: var(--text-primary);
line-height: 1.6;
padding: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
background-image:
radial-gradient(at 80% 0%, hsla(189, 100%, 56%, 0.1) 0px, transparent 50%),
radial-gradient(at 0% 50%, hsla(355, 100%, 93%, 0.1) 0px, transparent 50%);
}
.container {
width: 100%;
max-width: 1000px;
margin: 0 auto;
padding: var(--spacing);
flex: 1;
}
header {
text-align: center;
margin-bottom: 3rem;
padding-top: 2rem;
}
h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
background: linear-gradient(90deg, var(--primary), #8b5cf6);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
letter-spacing: -0.025em;
}
.subtitle {
color: var(--text-secondary);
font-size: 1.125rem;
max-width: 600px;
margin: 0 auto;
}
.tool-card {
background: var(--card-bg);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 2.5rem;
border: 1px solid var(--glass);
transform: translateY(20px);
opacity: 0;
animation: fadeInUp 0.6s forwards;
transition: var(--transition);
}
@keyframes fadeInUp {
to {
opacity: 1;
transform: translateY(0);
}
}
.card-header {
display: flex;
align-items: center;
margin-bottom: 1.5rem;
}
.card-icon {
width: 48px;
height: 48px;
background: linear-gradient(135deg, var(--primary), #8b5cf6);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 1rem;
box-shadow: 0 4px 6px rgba(79, 70, 229, 0.15);
}
.card-icon svg {
width: 24px;
height: 24px;
color: white;
}
.card-title {
font-size: 1.25rem;
font-weight: 600;
}
.card-description {
color: var(--text-secondary);
font-size: 0.875rem;
}
.textarea-container {
position: relative;
margin-bottom: 1.5rem;
}
.textarea-label {
display: block;
margin-bottom: 0.5rem;
font-size: 0.875rem;
font-weight: 500;
color: var(--text-primary);
}
textarea {
width: 100%;
min-height: 150px;
padding: 1rem;
border: 1px solid var(--border);
border-radius: 8px;
resize: vertical;
font-size: 0.9375rem;
transition: var(--transition);
background: var(--card-bg);
color: var(--text-primary);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}
textarea:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
.button-group {
display: flex;
gap: 1rem;
margin: 2rem 0;
}
button {
flex: 1;
padding: 0.875rem 1rem;
background: var(--primary);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 0.9375rem;
font-weight: 500;
transition: var(--transition);
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
button:hover {
background: var(--primary-hover);
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
button:active {
transform: translateY(0);
}
button svg {
width: 18px;
height: 18px;
}
.stats {
display: flex;
justify-content: space-between;
font-size: 0.8125rem;
color: var(--text-secondary);
margin-bottom: 1rem;
}
.stat-item {
display: flex;
align-items: center;
gap: 0.25rem;
}
.stat-item svg {
width: 14px;
height: 14px;
}
footer {
text-align: center;
padding: 2rem 0;
color: var(--text-secondary);
font-size: 0.875rem;
margin-top: auto;
}
footer a {
color: var(--primary);
text-decoration: none;
transition: var(--transition);
}
footer a:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
.container {
padding: 1rem;
}
h1 {
font-size: 2rem;
}
.tool-card {
padding: 1.5rem;
}
.button-group {
flex-direction: column;
}
}
/* 微交互效果 */
.copied {
animation: pulse 1s;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
70% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>Markdown 公式转换器</h1>
<p class="subtitle">将 LaTeX 数学公式转换为兼容格式</p>
</header>
<main>
<div class="tool-card">
<div class="card-header">
<div class="card-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
</svg>
</div>
<div>
<h2 class="card-title">公式转换器</h2>
<p class="card-description">输入 Markdown 内容,自动转换兼容格式</p>
</div>
</div>
<div class="textarea-container">
<label for="input" class="textarea-label">输入 Markdown 内容</label>
<textarea id="input" placeholder="粘贴你的 Markdown 内容... 示例: 当 $a \\ne 0$ 时,方程解为:
$$
x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}
$$
"></textarea>
</div>
<div class="stats">
<div class="stat-item">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6" />
</svg>
<span id="inputStats">输入: 0 字符</span>
</div>
<div class="stat-item">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 17h8m0 0V9m0 8l-8-8-4 4-6-6" />
</svg>
<span id="outputStats">输出: 0 字符</span>
</div>
</div>
<div class="button-group">
<button onclick="convert()">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
立即转换
</button>
<button onclick="copyToClipboard()">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" />
</svg>
复制结果
</button>
</div>
<div class="textarea-container">
<label for="output" class="textarea-label">转换结果</label>
<textarea id="output" placeholder="转换结果将出现在这里..." readonly></textarea>
</div>
</div>
</main>
</div>
<script>
// 设置当前年份
document.getElementById('current-year').textContent = new Date().getFullYear();
function convert() {
const input = document.getElementById("input").value;
const output = input
.replace(/\$\$(.*?)\$\$/gs, "[math]\n$1\n[/math]")
.replace(/\$(.*?)\$/gs, "[imath]$1[/imath]");
document.getElementById("output").value = output;
updateStats();
// 添加微交互
const outputTextarea = document.getElementById("output");
outputTextarea.classList.add('copied');
setTimeout(() => outputTextarea.classList.remove('copied'), 1000);
}
function updateStats() {
const input = document.getElementById("input").value;
const output = document.getElementById("output").value;
document.getElementById("inputStats").textContent = `输入: ${input.length} 字符`;
document.getElementById("outputStats").textContent = `输出: ${output.length} 字符`;
}
async function copyToClipboard() {
const output = document.getElementById("output");
try {
await navigator.clipboard.writeText(output.value);
output.classList.add('copied');
setTimeout(() => output.classList.remove('copied'), 1000);
// 临时改变按钮文本
const copyButton = document.querySelector('button[onclick="copyToClipboard()"]');
const originalText = copyButton.innerHTML;
copyButton.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
</svg>
已复制
`;
setTimeout(() => {
copyButton.innerHTML = originalText;
}, 2000);
} catch (err) {
console.error('复制失败:', err);
}
}
// 实时统计输入字符
document.getElementById("input").addEventListener('input', updateStats);
// 初始化动画
document.addEventListener('DOMContentLoaded', () => {
const cards = document.querySelectorAll('.tool-card');
cards.forEach((card, index) => {
card.style.animationDelay = `${index * 0.1}s`;
});
});
</script>
</body>
</html>
代码由deepseek大模型生成,并进行了一些调整。