Skip to content

Add {table} directive with column width support#2684

Open
theletterf wants to merge 12 commits intomainfrom
add-table-directive-column-widths
Open

Add {table} directive with column width support#2684
theletterf wants to merge 12 commits intomainfrom
add-table-directive-column-widths

Conversation

@theletterf
Copy link
Contributor

@theletterf theletterf commented Feb 11, 2026

Summary

  • Add a new MyST {table} directive that allows authors to control table column widths using a :widths: option with space-separated relative integers (e.g., :widths: 30 70), normalized to percentages and rendered via <colgroup>/<col> with table-layout: fixed CSS.
  • Support an optional caption via the directive argument (e.g., :::{table} My caption).
  • Extend WrappedTableRenderer to manually render <colgroup> and column width styles when custom widths are present, since Markdig's default HtmlTableRenderer does not emit them.
  • Add the same :widths: support to the {csv-include} directive, with shared parsing logic extracted into a WidthsParser helper.
  • Add comprehensive unit tests covering width parsing, HTML output, validation errors, and passthrough behavior for both directives.
  • Update docs/syntax/tables.md and docs/syntax/csv-include.md with practical examples.

Closes https://github.com/elastic/docs-eng-team/issues/424

Introduce a MyST `{table}` directive that allows authors to control table
column widths using a `:widths:` option (e.g., `:widths: 30 70`). Values
are normalized to percentages and rendered as `<colgroup>`/`<col>` elements
with `table-layout: fixed` CSS. Also supports an optional caption via the
directive argument.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link

github-actions bot commented Feb 11, 2026

🔍 Preview links for changed docs

Address code quality review comments by casting the sequence
at enumeration level rather than inside the loop body.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
theletterf and others added 2 commits February 11, 2026 18:32
Cover additional validation paths: zero width values, decimal width
values rejected by int parsing, and non-table content wrapped in the
{table} directive emitting a warning.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Set ImplicitParagraph = true when rendering cell content in the custom
colgroup renderer, matching Markdig's base HtmlTableRenderer behavior.
Without this, cell content was wrapped in <p> tags, adding unwanted
margin to header and body cells.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Extract shared width parsing logic into WidthsParser helper, reused by
both {table} and {csv-include} directives. The CSV include Razor view
now renders <colgroup>/<col> elements with table-layout: fixed when
widths are specified. Also fix caption markup to use <div> instead of
misplaced <caption> outside <table>.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Mpdreamz
Copy link
Member

Mpdreamz commented Feb 11, 2026

#2686 might impact this since it includes my upstream changes to markdig which changes the table AST.

Lets merge that one first and then update this PR.

@theletterf
Copy link
Contributor Author

@Mpdreamz #2686 merged, this one's ready to go!

The caption div was inside the overflow scroll container, causing it to
be squeezed by the fixed-width table layout. Move it before the wrapper
to match the {table} directive's rendering and the existing CSS rule
for .table-caption + .table-wrapper.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Tailwind defines a `table-caption` utility that sets `display: table-caption`,
which caused our caption element to shrink to min-content width and wrap each
word vertically. Rename the class to `md-table-caption` and update CSS,
renderers, and tests.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@theletterf
Copy link
Contributor Author

@elastic/docs-tech-leads @KOTungseth Green light to get this one in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants