Skip to content

Commit a5204e2

Browse files
committed
Improve article tables and sidebar scrolling
1 parent 1825d08 commit a5204e2

2 files changed

Lines changed: 113 additions & 2 deletions

File tree

src/app/globals.css

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,61 @@ button {
15311531
padding: 0;
15321532
}
15331533

1534+
.article-table-wrap {
1535+
max-width: 100%;
1536+
overflow-x: auto;
1537+
margin: 1.2em 0 1.8em;
1538+
border: 1px solid rgba(85, 118, 128, 0.2);
1539+
border-radius: 16px;
1540+
background: rgba(255, 255, 255, 0.68);
1541+
box-shadow: 0 16px 40px rgba(27, 80, 96, 0.08);
1542+
}
1543+
1544+
.article-table {
1545+
width: 100%;
1546+
min-width: 640px;
1547+
border-collapse: separate;
1548+
border-spacing: 0;
1549+
color: var(--muted-strong);
1550+
font-size: 0.95rem;
1551+
line-height: 1.65;
1552+
}
1553+
1554+
.article-table th,
1555+
.article-table td {
1556+
min-width: 112px;
1557+
padding: 12px 14px;
1558+
border-right: 1px solid rgba(85, 118, 128, 0.16);
1559+
border-bottom: 1px solid rgba(85, 118, 128, 0.16);
1560+
vertical-align: top;
1561+
overflow-wrap: anywhere;
1562+
}
1563+
1564+
.article-table th:last-child,
1565+
.article-table td:last-child {
1566+
border-right: 0;
1567+
}
1568+
1569+
.article-table tr:last-child td {
1570+
border-bottom: 0;
1571+
}
1572+
1573+
.article-table th {
1574+
background: linear-gradient(180deg, rgba(47, 203, 231, 0.12), rgba(255, 255, 255, 0.72));
1575+
color: var(--foreground);
1576+
font-weight: 900;
1577+
text-align: left;
1578+
white-space: nowrap;
1579+
}
1580+
1581+
.article-table td {
1582+
background: rgba(255, 255, 255, 0.46);
1583+
}
1584+
1585+
.article-table tr:nth-child(even) td {
1586+
background: rgba(47, 203, 231, 0.045);
1587+
}
1588+
15341589
.article-view .katex {
15351590
color: var(--foreground);
15361591
font-size: 1.02em;
@@ -1571,13 +1626,17 @@ button {
15711626
position: sticky;
15721627
grid-column: 3;
15731628
top: 112px;
1574-
display: grid;
1629+
display: flex;
1630+
flex-direction: column;
15751631
gap: 14px;
15761632
min-width: 0;
1633+
max-height: calc(100dvh - 128px);
1634+
overflow: hidden;
15771635
}
15781636

15791637
.article-side-card {
15801638
display: grid;
1639+
flex: 0 0 auto;
15811640
gap: 10px;
15821641
padding: 18px;
15831642
}
@@ -1602,14 +1661,50 @@ button {
16021661
line-height: 1.75;
16031662
}
16041663

1664+
.article-summary-card p,
1665+
.article-toc {
1666+
scrollbar-width: thin;
1667+
scrollbar-color: rgba(85, 118, 128, 0.46) rgba(47, 203, 231, 0.08);
1668+
}
1669+
1670+
.article-summary-card p::-webkit-scrollbar,
1671+
.article-toc::-webkit-scrollbar,
1672+
.article-table-wrap::-webkit-scrollbar {
1673+
width: 8px;
1674+
height: 8px;
1675+
}
1676+
1677+
.article-summary-card p::-webkit-scrollbar-thumb,
1678+
.article-toc::-webkit-scrollbar-thumb,
1679+
.article-table-wrap::-webkit-scrollbar-thumb {
1680+
border-radius: 999px;
1681+
background: rgba(85, 118, 128, 0.44);
1682+
}
1683+
1684+
.article-summary-card p::-webkit-scrollbar-track,
1685+
.article-toc::-webkit-scrollbar-track,
1686+
.article-table-wrap::-webkit-scrollbar-track {
1687+
border-radius: 999px;
1688+
background: rgba(47, 203, 231, 0.08);
1689+
}
1690+
16051691
.article-side-card strong {
16061692
color: var(--foreground);
16071693
}
16081694

1695+
.article-toc {
1696+
flex: 1 1 auto;
1697+
min-height: 0;
1698+
overflow-y: auto;
1699+
align-content: start;
1700+
padding-right: 14px;
1701+
}
1702+
16091703
.article-toc a {
16101704
color: var(--muted);
16111705
font-size: 0.86rem;
16121706
font-weight: 800;
1707+
line-height: 1.55;
16131708
}
16141709

16151710
.article-toc a:hover {
@@ -1843,6 +1938,8 @@ button {
18431938
.article-sidebar {
18441939
position: static;
18451940
order: 2;
1941+
max-height: none;
1942+
overflow: visible;
18461943
}
18471944

18481945
.article-cover-card {
@@ -1851,6 +1948,8 @@ button {
18511948

18521949
.article-toc {
18531950
align-content: start;
1951+
overflow: visible;
1952+
padding-right: 18px;
18541953
}
18551954
}
18561955

src/lib/markdown-renderer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ function renderMath(markdown: string) {
121121
return rendered.join("\n");
122122
}
123123

124+
function wrapMarkdownTables(html: string) {
125+
return html.replace(/<table>([\s\S]*?)<\/table>/g, (match) => {
126+
if (match.includes('class="article-table"')) {
127+
return match;
128+
}
129+
130+
const table = match.replace("<table>", '<table class="article-table">');
131+
return `<div class="article-table-wrap">${table}</div>`;
132+
});
133+
}
134+
124135
export async function renderMarkdown(markdown: string) {
125136
const toc: TocItem[] = [];
126137
const withAnchors = markdown
@@ -147,9 +158,10 @@ export async function renderMarkdown(markdown: string) {
147158
gfm: true,
148159
breaks: true,
149160
});
161+
const htmlString = typeof html === "string" ? html : String(html);
150162

151163
return {
152-
html: typeof html === "string" ? html : String(html),
164+
html: wrapMarkdownTables(htmlString),
153165
toc,
154166
};
155167
}

0 commit comments

Comments
 (0)