mirror of
https://github.com/justhtmls/html-tools.git
synced 2026-11-25 09:56:57 +08:00
330 lines
9.9 KiB
HTML
330 lines
9.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<link rel="icon" href="../../favicon.svg">
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Markdown 表格生成器</title>
|
|
<link rel="canonical" href="https://www.htmls.dev/tools/markdown-table-generator/app.html">
|
|
<style>
|
|
:root {
|
|
--accent: #0f766e;
|
|
--accent-soft: #0f766e33;
|
|
--bg-dark: #0f172a;
|
|
--text: #0f172a;
|
|
--text-muted: #475569;
|
|
--border: #e2e8f0;
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #0f766e 0%, #0f172a 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
color: var(--text);
|
|
}
|
|
|
|
.container {
|
|
max-width: 1100px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
color: white;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.3rem;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.card {
|
|
background: rgba(255, 255, 255, 0.96);
|
|
border-radius: 18px;
|
|
padding: 26px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
|
gap: 16px;
|
|
}
|
|
|
|
label {
|
|
font-size: 14px;
|
|
color: var(--text-muted);
|
|
display: block;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
input[type="text"],
|
|
input[type="number"],
|
|
textarea,
|
|
select {
|
|
width: 100%;
|
|
padding: 10px 12px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 10px;
|
|
font-size: 14px;
|
|
background: white;
|
|
}
|
|
|
|
textarea {
|
|
min-height: 160px;
|
|
resize: vertical;
|
|
}
|
|
|
|
.row {
|
|
display: flex;
|
|
gap: 12px;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.actions {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.btn {
|
|
padding: 10px 18px;
|
|
border-radius: 10px;
|
|
border: none;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
background: var(--accent);
|
|
color: white;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-1px);
|
|
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #64748b;
|
|
}
|
|
|
|
.checkbox {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 13px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.meta {
|
|
margin-top: 10px;
|
|
font-size: 13px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.output-box {
|
|
background: #f8fafc;
|
|
border: 1px dashed var(--border);
|
|
padding: 12px;
|
|
border-radius: 12px;
|
|
margin-top: 16px;
|
|
}
|
|
|
|
.status {
|
|
margin-top: 12px;
|
|
font-size: 13px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.result-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
|
gap: 12px;
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.result-card {
|
|
background: #f8fafc;
|
|
border-radius: 12px;
|
|
padding: 12px;
|
|
border: 1px solid var(--border);
|
|
}
|
|
|
|
.result-card h4 {
|
|
font-size: 12px;
|
|
color: var(--text-muted);
|
|
margin-bottom: 6px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.result-card div {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
color: var(--accent);
|
|
word-break: break-all;
|
|
}
|
|
|
|
.tool-doc-link,
|
|
.tool-home-link {
|
|
position: fixed;
|
|
top: 16px;
|
|
padding: 6px 12px;
|
|
border-radius: 999px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
color: #0f172a;
|
|
background: rgba(255, 255, 255, 0.9);
|
|
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
text-decoration: none;
|
|
letter-spacing: 0.02em;
|
|
z-index: 9999;
|
|
box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
|
|
transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
|
|
}
|
|
|
|
.tool-doc-link {
|
|
right: 16px;
|
|
}
|
|
|
|
.tool-home-link {
|
|
right: 74px;
|
|
}
|
|
|
|
.tool-doc-link:hover,
|
|
.tool-home-link:hover {
|
|
background: rgba(255, 255, 255, 1);
|
|
border-color: rgba(15, 23, 42, 0.2);
|
|
transform: translateY(-1px);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<a class="tool-home-link" href="../../index.html">首页</a>
|
|
<a class="tool-doc-link" href="index.html">说明</a>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>Markdown 表格生成器</h1>
|
|
<p>将文本快速转换为 Markdown 表格</p>
|
|
</div>
|
|
<div class="card">
|
|
<div>
|
|
<label>输入文本(每行一条记录)</label>
|
|
<textarea id="input" placeholder="例如:
|
|
名称,价格,库存
|
|
A,10,20
|
|
B,12,8"></textarea>
|
|
</div>
|
|
<div class="row">
|
|
<div style="min-width: 200px;">
|
|
<label>分隔符</label>
|
|
<select id="delimiter">
|
|
<option value="comma" selected>逗号</option>
|
|
<option value="tab">制表符</option>
|
|
<option value="pipe">竖线 |</option>
|
|
<option value="custom">自定义</option>
|
|
</select>
|
|
</div>
|
|
<input id="custom-delimiter" type="text" placeholder="自定义分隔符" />
|
|
<label class="checkbox"><input type="checkbox" id="has-header" checked>首行作为表头</label>
|
|
<div class="actions">
|
|
<button class="btn" id="generate">生成表格</button>
|
|
<button class="btn btn-secondary" id="copy">复制结果</button>
|
|
<button class="btn btn-secondary" id="clear">清空</button>
|
|
<button class="btn btn-secondary" id="sample">加载示例</button>
|
|
</div>
|
|
</div>
|
|
<div class="output-box">
|
|
<label>Markdown 表格</label>
|
|
<textarea id="output" readonly placeholder="生成的 Markdown 表格"></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const input = document.getElementById('input');
|
|
const delimiterSelect = document.getElementById('delimiter');
|
|
const customDelimiter = document.getElementById('custom-delimiter');
|
|
const hasHeader = document.getElementById('has-header');
|
|
const output = document.getElementById('output');
|
|
|
|
function getDelimiter() {
|
|
const mode = delimiterSelect.value;
|
|
if (mode === 'comma') return ',';
|
|
if (mode === 'tab') return '\t';
|
|
if (mode === 'pipe') return '|';
|
|
const custom = customDelimiter.value;
|
|
return custom === '' ? ',' : custom;
|
|
}
|
|
|
|
function escapeCell(value) {
|
|
return value.replace(/\|/g, '\\|');
|
|
}
|
|
|
|
function generateTable() {
|
|
const value = input.value.trim();
|
|
if (!value) {
|
|
output.value = '';
|
|
return;
|
|
}
|
|
const delimiter = getDelimiter();
|
|
const lines = value.split(/\r?\n/).filter(Boolean);
|
|
const rows = lines.map(line => line.split(delimiter).map(cell => cell.trim()));
|
|
const maxCols = Math.max(...rows.map(row => row.length));
|
|
const fillRow = row => row.concat(Array(maxCols - row.length).fill(''));
|
|
const filledRows = rows.map(fillRow);
|
|
let headerRow = [];
|
|
let bodyRows = [];
|
|
if (hasHeader.checked) {
|
|
headerRow = filledRows[0];
|
|
bodyRows = filledRows.slice(1);
|
|
} else {
|
|
headerRow = Array.from({ length: maxCols }, (_, i) => `列${i + 1}`);
|
|
bodyRows = filledRows;
|
|
}
|
|
const headerLine = `| ${headerRow.map(escapeCell).join(' | ')} |`;
|
|
const separator = `| ${headerRow.map(() => '---').join(' | ')} |`;
|
|
const bodyLines = bodyRows.map(row => `| ${row.map(escapeCell).join(' | ')} |`);
|
|
output.value = [headerLine, separator, ...bodyLines].join('\n');
|
|
}
|
|
|
|
document.getElementById('generate').addEventListener('click', generateTable);
|
|
document.getElementById('copy').addEventListener('click', () => {
|
|
if (!output.value) return;
|
|
output.select();
|
|
document.execCommand('copy');
|
|
});
|
|
document.getElementById('clear').addEventListener('click', () => {
|
|
input.value = '';
|
|
output.value = '';
|
|
});
|
|
document.getElementById('sample').addEventListener('click', () => {
|
|
input.value = '名称,价格,库存
|
|
苹果,3,120
|
|
香蕉,2,90
|
|
橙子,4,60';
|
|
delimiterSelect.value = 'comma';
|
|
customDelimiter.value = '';
|
|
hasHeader.checked = true;
|
|
generateTable();
|
|
});
|
|
</script>
|
|
<script src="../../assets/clicks.js" defer></script>
|
|
</body>
|
|
</html>
|