Prettier plugin that sorts markdown tables according to their first column.
This version of the plugin only works with Prettier 3. For Prettier 2, please use 1.x.
npm i -D prettier-plugin-sort-markdown-table
Add the plugin to your Prettier configuration file:
{
"plugins": ["prettier-plugin-sort-markdown-table"]
}
Annotate tables you want to sort with <!-- prettier-sort-markdown-table -->
comment.
For example:
<!-- prettier-sort-markdown-table -->
| name | email | description |
| -- | -- | --- |
| zhang | [email protected] | zhang |
| wang | [email protected] | wang |
| li | [email protected] | li |
| amity | [email protected] | amity |
| batman | [email protected] | batman |
Becomes:
<!-- prettier-sort-markdown-table -->
| name | email | description |
| ------ | ------------ | ----------- |
| amity | [email protected] | amity |
| batman | [email protected] | batman |
| li | [email protected] | li |
| wang | [email protected] | wang |
| zhang | [email protected] | zhang |
MIT © Doma