Skip to content

Commit 77adba4

Browse files
authored
Add table (#570)
* Add table * Fix link * Fine-tune
1 parent b83b0d5 commit 77adba4

File tree

6 files changed

+117
-11
lines changed

6 files changed

+117
-11
lines changed

docs/syntax/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ We support _some_ [GitHub Flavored Markdown (GFM) extensions](https://github.git
6969

7070
### Supported
7171

72-
* [](tables.md#github-flavored-markdown-gfm-table)
72+
* [](tables.md#basic-table)
7373
* Strikethrough: ~~as seen here~~
7474

7575
### Not supported

docs/syntax/tables.md

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,64 @@ A table is an arrangement of data with rows and columns. Each row consists of ce
66
* a delimiter row separating the header from the data
77
* zero or more data rows
88

9-
## Notes
9+
## Basic Table
1010

11-
* A leading and trailing pipe is recommended for clarity of reading
12-
* Spaces between pipes and cell content are trimmed
13-
* Block-level elements cannot be inserted in a table
11+
::::{tab-set}
1412

15-
## GitHub Flavored Markdown (GFM) Table
16-
17-
You can use the GFM table syntax to create a table:
18-
19-
```
13+
:::{tab-item} Output
2014
| Country | Capital |
2115
| ------- | --------------- |
2216
| USA | Washington D.C. |
2317
| Canada | Ottawa |
24-
```
18+
| Mexico | Mexico City |
19+
| Brazil | Brasília |
20+
| UK | London |
21+
:::
2522

23+
:::{tab-item} Markdown
24+
```markdown
2625
| Country | Capital |
2726
| ------- | --------------- |
2827
| USA | Washington D.C. |
2928
| Canada | Ottawa |
29+
| Mexico | Mexico City |
30+
| Brazil | Brasília |
31+
| UK | London |
32+
:::
33+
34+
::::
35+
36+
:::{note}
37+
38+
* A leading and trailing pipe is recommended for clarity of reading
39+
* Spaces between pipes and cell content are trimmed
40+
* Block-level elements cannot be inserted in a table
41+
42+
:::
43+
44+
45+
## Responsive Table
46+
47+
Every table is responsive by default. The table will automatically scroll horizontally when the content is wider than the viewport.
48+
49+
::::{tab-set}
50+
51+
:::{tab-item} Output
52+
| Product Name | Price ($) | Stock | Category | Rating | Color | Weight (kg) | Warranty (months) |
53+
|--------------|-----------|--------|-----------|---------|----------|-------------|-------------------|
54+
| Laptop Pro | 1299.99 | 45 | Computer | 4.5 | Silver | 1.8 | 24 |
55+
| Smart Watch | 299.99 | 120 | Wearable | 4.2 | Black | 0.045 | 12 |
56+
| Desk Chair | 199.50 | 78 | Furniture | 4.8 | Gray | 12.5 | 36 |
57+
:::
58+
59+
:::{tab-item} Markdown
60+
```markdown
61+
| Product Name | Price ($) | Stock | Category | Rating | Color | Weight (kg) | Warranty (months) |
62+
|--------------|-----------|--------|-----------|---------|----------|-------------|-------------------|
63+
| Laptop Pro | 1299.99 | 45 | Computer | 4.5 | Silver | 1.8 | 24 |
64+
| Smart Watch | 299.99 | 120 | Wearable | 4.2 | Black | 0.045 | 12 |
65+
| Desk Chair | 199.50 | 78 | Furniture | 4.8 | Gray | 12.5 | 36 |
66+
:::
67+
```
68+
69+
::::
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@layer components {
2+
.table-wrapper {
3+
4+
@apply max-w-full overflow-x-auto my-4;
5+
6+
table {
7+
@apply w-full border-collapse;
8+
}
9+
10+
th, td {
11+
@apply py-2 px-4 min-w-30;
12+
}
13+
14+
th:first-of-type {
15+
border-top-left-radius: var(--radius-sm);
16+
}
17+
th:last-of-type {
18+
border-top-right-radius: var(--radius-sm);
19+
}
20+
tr:last-of-type td:first-of-type {
21+
border-bottom-left-radius: var(--radius-sm);
22+
}
23+
tr:last-of-type td:last-of-type {
24+
border-bottom-right-radius: var(--radius-sm);
25+
}
26+
27+
thead {
28+
@apply font-semibold text-sm text-left align-top;
29+
}
30+
31+
tbody {
32+
33+
font-family: "Inter", sans-serif;
34+
35+
tr {
36+
@apply not-last:border-b-1 border-grey-30 hover:bg-grey-10;
37+
/*&:nth-child(odd) {*/
38+
/* @apply bg-grey-10;*/
39+
/*}*/
40+
}
41+
}
42+
}
43+
}

src/Elastic.Markdown/Assets/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@import "./copybutton.css";
99
@import "./markdown/admonition.css";
1010
@import "./markdown/dropdown.css";
11+
@import "./markdown/table.css";
1112
@import "./markdown/definition-list.css";
1213

1314
#default-search::-webkit-search-cancel-button {

src/Elastic.Markdown/Myst/Directives/DirectiveMarkdownExtension.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information
44

55
using Markdig;
6+
using Markdig.Extensions.Tables;
67
using Markdig.Parsers;
78
using Markdig.Parsers.Inlines;
89
using Markdig.Renderers;
@@ -56,5 +57,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
5657
}
5758

5859
_ = renderer.ObjectRenderers.Replace<HeadingRenderer>(new SectionedHeadingRenderer());
60+
61+
_ = renderer.ObjectRenderers.Replace<HtmlTableRenderer>(new WrappedTableRenderer());
5962
}
6063
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Markdig.Extensions.Tables;
6+
using Markdig.Renderers;
7+
8+
namespace Elastic.Markdown.Myst;
9+
10+
public class WrappedTableRenderer : HtmlTableRenderer
11+
{
12+
protected override void Write(HtmlRenderer renderer, Table table)
13+
{
14+
// Wrap the table in a div to allow for overflow scrolling
15+
_ = renderer.Write("<div class=\"table-wrapper\">");
16+
base.Write(renderer, table);
17+
_ = renderer.Write("</div>");
18+
}
19+
}

0 commit comments

Comments
 (0)