Sort MD Tables
Sort Markdown tables without leaving the editor or converting your document to another format.
Usage
- Open a Markdown document containing a pipe table.
- Hover over any table header.
- Choose Ascending or Descending in the hover.
The extension rewrites only the body-row range. Header text, the delimiter row, cell spacing, links, inline code, and other row formatting remain intact.
Multi-column sorting
Sort MD Tables follows the established data-grid sort model:
- A column can be ascending, descending, or unsorted.
- Sorting a new column adds it as the next tie-breaker.
- Existing sort rules retain their priority. For example, sort Year first and Month second to group by year, then month.
- Clear one column's rule from that header, or use Clear all to restore the row order captured before the first sort.
The hover shows the active priority as 1. Year ↑ · 2. Month ↓. This is the same always-on multi-sort interaction documented by MUI X Data Grid, adapted to VS Code hover actions.
Comparison behavior
- Columns whose non-empty cells are all plain numbers use numeric comparison, including signs, decimals, and thousands separators.
- Columns whose non-empty cells are all complete date expressions are parsed by chrono-node and compared as instants. Chrono supports general human-written dates, ISO timestamps, relative dates, clock times, and recognized time-zone names or abbreviations. For example,
Tuesday August 11, 12:01 AM ET, 11 Aug 2026 04:01 UTC, and 2026-08-11T04:01:00Z are date values rather than text formats hard-coded by this extension.
- Other columns use case-insensitive natural alphanumeric comparison, so
Item 2 sorts before Item 10.
- Empty cells sort before non-empty cells in ascending order.
- Equal values preserve the pre-sort row order.
Date inference is column-wide: every non-empty cell must be consumed completely by chrono-node. A cell such as Release August 11 remains ordinary text because the date is only part of the cell. One shared reference instant is used for the whole sort so relative or incomplete dates are resolved consistently according to chrono-node's standard casual-English rules.
You can also run the four Sort MD Tables commands from the Command Palette while the cursor is in a table header.
Supported tables
The extension targets standard Markdown pipe tables with a header delimiter row containing at least three dashes per column. Leading and trailing pipes are optional. Escaped pipes and pipes inside inline-code spans are recognized as cell content.
Multiline cells and HTML <table> blocks are not Markdown pipe tables and are not changed.
Sort state and safety
Sorting changes the Markdown document and participates in VS Code's normal Undo history. Active multi-sort rules and the pre-sort row order are held in memory; they reset when the table body is manually edited or VS Code restarts. The already-sorted Markdown remains exactly as saved.
Sort MD Tables makes no network requests, collects no telemetry, and works in untrusted and virtual workspaces. Date parsing is performed locally by chrono-node.
Development
npm install
npm run check
npm run test:integration
npm run package:vsix
Press F5 in VS Code to launch an Extension Development Host.
License
MIT License. The full text is included in LICENSE.