feat: 表格渲染样式重新(完整版)、项目代码清理和优化
This commit is contained in:
parent
53a24bfd09
commit
25abc09cb4
Binary file not shown.
|
|
@ -38,7 +38,7 @@ const options: Options = {
|
|||
if (!text) return ''
|
||||
if (!obj.useMd) return text
|
||||
try {
|
||||
// Configure marked renderer to add target="_blank" to links
|
||||
// Configure marked renderer to add target="_blank" to links and table classes
|
||||
const renderer = {
|
||||
link(token: Tokens.Link) {
|
||||
const href = token.href || ''
|
||||
|
|
@ -46,6 +46,13 @@ const options: Options = {
|
|||
const text = token.text || ''
|
||||
return `<a href="${href}"${title} target="_blank">${text}</a>`
|
||||
},
|
||||
table(token: Tokens.Table) {
|
||||
const header = token.header.map(cell => `<th>${cell.text}</th>`).join('')
|
||||
const rows = token.rows.map(row =>
|
||||
`<tr>${row.map(cell => `<td>${cell.text}</td>`).join('')}</tr>`
|
||||
).join('')
|
||||
return `<table class="markdown-table"><thead><tr>${header}</tr></thead><tbody>${rows}</tbody></table>`
|
||||
},
|
||||
}
|
||||
|
||||
marked.use({ renderer, gfm: true })
|
||||
|
|
|
|||
|
|
@ -317,4 +317,58 @@
|
|||
background: #4f90f22d;
|
||||
border: 1px solid #4f90f2;
|
||||
}
|
||||
|
||||
/* Markdown表格样式 */
|
||||
.markdown-table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 4px 0;
|
||||
font-size: 11px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
||||
background-color: #fafafa;
|
||||
overflow: hidden;
|
||||
white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
|
||||
}
|
||||
|
||||
.markdown-table th,
|
||||
.markdown-table td {
|
||||
border: 1px solid #e0e0e0;
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
|
||||
}
|
||||
|
||||
.markdown-table th {
|
||||
background-color: #f5f5f5;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #d0d0d0;
|
||||
}
|
||||
|
||||
.markdown-table td {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.markdown-table tr:nth-child(even) td {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.markdown-table tr:hover td {
|
||||
background-color: #f0f8ff;
|
||||
}
|
||||
|
||||
/* 移除多余的边框,保持简洁 */
|
||||
.markdown-table th:not(:last-child),
|
||||
.markdown-table td:not(:last-child) {
|
||||
border-right: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.markdown-table tr:not(:last-child) td {
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ const options: Options = {
|
|||
if (!text) return ''
|
||||
if (!obj.useMd) return text
|
||||
try {
|
||||
// Configure marked renderer to add target="_blank" to links
|
||||
// Configure marked renderer to add target="_blank" to links and table classes
|
||||
const renderer = {
|
||||
link(token: Tokens.Link) {
|
||||
const href = token.href || ''
|
||||
|
|
@ -46,6 +46,13 @@ const options: Options = {
|
|||
const text = token.text || ''
|
||||
return `<a href="${href}"${title} target="_blank">${text}</a>`
|
||||
},
|
||||
table(token: Tokens.Table) {
|
||||
const header = token.header.map(cell => `<th>${cell.text}</th>`).join('')
|
||||
const rows = token.rows.map(row =>
|
||||
`<tr>${row.map(cell => `<td>${cell.text}</td>`).join('')}</tr>`
|
||||
).join('')
|
||||
return `<table class="markdown-table"><thead><tr>${header}</tr></thead><tbody>${rows}</tbody></table>`
|
||||
},
|
||||
}
|
||||
|
||||
marked.use({ renderer, gfm: true })
|
||||
|
|
|
|||
|
|
@ -317,4 +317,58 @@
|
|||
background: #4f90f22d;
|
||||
border: 1px solid #4f90f2;
|
||||
}
|
||||
|
||||
/* Markdown表格样式 */
|
||||
.markdown-table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 4px 0;
|
||||
font-size: 11px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
||||
background-color: #fafafa;
|
||||
overflow: hidden;
|
||||
white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
|
||||
}
|
||||
|
||||
.markdown-table th,
|
||||
.markdown-table td {
|
||||
border: 1px solid #e0e0e0;
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
white-space: normal !important; /* 覆盖MindElixir的pre-wrap */
|
||||
}
|
||||
|
||||
.markdown-table th {
|
||||
background-color: #f5f5f5;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #d0d0d0;
|
||||
}
|
||||
|
||||
.markdown-table td {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.markdown-table tr:nth-child(even) td {
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.markdown-table tr:hover td {
|
||||
background-color: #f0f8ff;
|
||||
}
|
||||
|
||||
/* 移除多余的边框,保持简洁 */
|
||||
.markdown-table th:not(:last-child),
|
||||
.markdown-table td:not(:last-child) {
|
||||
border-right: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.markdown-table tr:not(:last-child) td {
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue