fix: 优化表格预览样式及块级装饰行范围计算
continuous-integration/drone/push Build is passing

This commit is contained in:
seahi committed 2026-09-23 11:01:48 +08:00
1 parent 71c59837eb
commit 3c628e404d
2 files changed
+10 -4

No files matched your search

+1 -1
View File
@@ -672,7 +672,7 @@ body.single-col .post-list {
.article-content th,
.article-content td {
border: 1px solid var(--border-color);
padding: 0.6rem 1rem;
padding: 0.3rem 0.8rem;
}
.article-content th {
+9 -3
View File
@@ -223,7 +223,7 @@ class TablePreviewWidget extends WidgetType {
// Basic markdown parsing for links and strong could be done here, but textContent is safer
td.textContent = col;
td.style.border = '1px solid var(--border-color, #e5e7eb)';
td.style.padding = '0.6rem 1rem';
td.style.padding = '0.3rem 0.8rem';
td.style.textAlign = alignments[colIndex] || 'left';
if (isHeader) {
td.style.backgroundColor = 'rgba(0, 0, 0, 0.03)';
@@ -266,14 +266,20 @@ function getTableDecorations(state: EditorState) {
node.to === currentTableRange.to;
if (!isCurrent) {
const tableStr = state.doc.sliceString(node.from, node.to);
// Ensure block replace decorations cover entire lines
const startLine = state.doc.lineAt(node.from);
const endLine = state.doc.lineAt(node.to);
const from = startLine.from;
const to = endLine.to;
const tableStr = state.doc.sliceString(from, to);
// Skip malformed tables or empty ones
if (tableStr.trim().length > 0) {
const deco = Decoration.replace({
widget: new TablePreviewWidget(tableStr),
block: true
});
widgets.push(deco.range(node.from, node.to));
widgets.push(deco.range(from, to));
}
}
}