Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/syntax/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ We support _some_ [GitHub Flavored Markdown (GFM) extensions](https://github.git

### Supported

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

### Not supported
Expand Down
60 changes: 50 additions & 10 deletions docs/syntax/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,64 @@ A table is an arrangement of data with rows and columns. Each row consists of ce
* a delimiter row separating the header from the data
* zero or more data rows

## Notes
## Basic Table

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

## GitHub Flavored Markdown (GFM) Table

You can use the GFM table syntax to create a table:

```
:::{tab-item} Output
| Country | Capital |
| ------- | --------------- |
| USA | Washington D.C. |
| Canada | Ottawa |
```
| Mexico | Mexico City |
| Brazil | Brasília |
| UK | London |
:::

:::{tab-item} Markdown
```markdown
| Country | Capital |
| ------- | --------------- |
| USA | Washington D.C. |
| Canada | Ottawa |
| Mexico | Mexico City |
| Brazil | Brasília |
| UK | London |
:::

::::

:::{note}

* A leading and trailing pipe is recommended for clarity of reading
* Spaces between pipes and cell content are trimmed
* Block-level elements cannot be inserted in a table

:::


## Responsive Table

Every table is responsive by default. The table will automatically scroll horizontally when the content is wider than the viewport.

::::{tab-set}

:::{tab-item} Output
| Product Name | Price ($) | Stock | Category | Rating | Color | Weight (kg) | Warranty (months) |
|--------------|-----------|--------|-----------|---------|----------|-------------|-------------------|
| Laptop Pro | 1299.99 | 45 | Computer | 4.5 | Silver | 1.8 | 24 |
| Smart Watch | 299.99 | 120 | Wearable | 4.2 | Black | 0.045 | 12 |
| Desk Chair | 199.50 | 78 | Furniture | 4.8 | Gray | 12.5 | 36 |
:::

:::{tab-item} Markdown
```markdown
| Product Name | Price ($) | Stock | Category | Rating | Color | Weight (kg) | Warranty (months) |
|--------------|-----------|--------|-----------|---------|----------|-------------|-------------------|
| Laptop Pro | 1299.99 | 45 | Computer | 4.5 | Silver | 1.8 | 24 |
| Smart Watch | 299.99 | 120 | Wearable | 4.2 | Black | 0.045 | 12 |
| Desk Chair | 199.50 | 78 | Furniture | 4.8 | Gray | 12.5 | 36 |
:::
```

::::
43 changes: 43 additions & 0 deletions src/Elastic.Markdown/Assets/markdown/table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@layer components {
.table-wrapper {

@apply max-w-full overflow-x-auto my-4;

table {
@apply w-full border-collapse;
}

th, td {
@apply py-2 px-4 min-w-30;
}

th:first-of-type {
border-top-left-radius: var(--radius-sm);
}
th:last-of-type {
border-top-right-radius: var(--radius-sm);
}
tr:last-of-type td:first-of-type {
border-bottom-left-radius: var(--radius-sm);
}
tr:last-of-type td:last-of-type {
border-bottom-right-radius: var(--radius-sm);
}

thead {
@apply font-semibold text-sm text-left align-top;
}

tbody {

font-family: "Inter", sans-serif;

tr {
@apply not-last:border-b-1 border-grey-30 hover:bg-grey-10;
/*&:nth-child(odd) {*/
/* @apply bg-grey-10;*/
/*}*/
}
}
}
}
1 change: 1 addition & 0 deletions src/Elastic.Markdown/Assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import "./copybutton.css";
@import "./markdown/admonition.css";
@import "./markdown/dropdown.css";
@import "./markdown/table.css";
@import "./markdown/definition-list.css";

#default-search::-webkit-search-cancel-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using Markdig;
using Markdig.Extensions.Tables;
using Markdig.Parsers;
using Markdig.Parsers.Inlines;
using Markdig.Renderers;
Expand Down Expand Up @@ -56,5 +57,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
}

_ = renderer.ObjectRenderers.Replace<HeadingRenderer>(new SectionedHeadingRenderer());

_ = renderer.ObjectRenderers.Replace<HtmlTableRenderer>(new WrappedTableRenderer());
}
}
19 changes: 19 additions & 0 deletions src/Elastic.Markdown/Myst/WrappedTableRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Markdig.Extensions.Tables;
using Markdig.Renderers;

namespace Elastic.Markdown.Myst;

public class WrappedTableRenderer : HtmlTableRenderer
{
protected override void Write(HtmlRenderer renderer, Table table)
{
// Wrap the table in a div to allow for overflow scrolling
_ = renderer.Write("<div class=\"table-wrapper\">");
base.Write(renderer, table);
_ = renderer.Write("</div>");
}
}