prettier-plugin-sort-markdown-table
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
Prettier plugin that sorts the rows of markdown tables alphabetically by the first column. Current stable version is 2.0.0, released May 2025, with a slow release cadence. Requires Prettier 3.x. Table sorting is opt-in: only tables preceded by a `<!-- prettier-sort-markdown-table -->` comment are sorted. Key differentiator: minimal configuration — just drop in and annotate — unlike other markdown formatters that require manual sorting.
Common errors
error Error: Cannot find module 'prettier-plugin-sort-markdown-table' ↓
cause Plugin not installed or not in node_modules.
fix
Run
npm i -D prettier-plugin-sort-markdown-table error Error: Invalid plugin: prettier-plugin-sort-markdown-table ↓
cause Prettier version is too old (pre v3) or plugin is not compatible.
fix
Upgrade Prettier to 3.x and use plugin v2.0.0 or later
error Error: [pretty-quick] No files matching the pattern found in the working tree. ↓
cause Running pretty-quick without specifying markdown files, or using wrong glob pattern.
fix
Use
pretty-quick --pattern '**/*.md' Warnings
breaking v2.0.0 drops support for Prettier 2; requires Prettier 3.x ↓
fix Upgrade Prettier to version 3.x
gotcha Table sorting only works when preceded by the annotation comment `<!-- prettier-sort-markdown-table -->`. Without it, no sorting occurs. ↓
fix Add `<!-- prettier-sort-markdown-table -->` on the line immediately above the table.
gotcha The plugin may conflict with other prettier plugins that also process markdown (e.g., prettier-plugin-md-nocjsp) leading to unexpected order of operations. ↓
fix Ensure plugins are listed in the correct order or test formatting with both plugins enabled.
deprecated v1.x is deprecated and may not work with newer Prettier versions; upgrade to v2 for compatibility. ↓
fix Upgrade to v2.0.0 and Prettier 3.x
Install
npm install prettier-plugin-sort-markdown-table yarn add prettier-plugin-sort-markdown-table pnpm add prettier-plugin-sort-markdown-table Imports
- plugin wrong
import prettierPluginSortMarkdownTable from 'prettier-plugin-sort-markdown-table'correctplugins: [require('prettier-plugin-sort-markdown-table')] - default export wrong
import { default } from 'prettier-plugin-sort-markdown-table'correctexport default { plugins: ['prettier-plugin-sort-markdown-table'] } - CLI usage wrong
prettier --plugin='prettier-plugin-sort-markdown-table' README.mdcorrectnpx prettier --plugin=prettier-plugin-sort-markdown-table --write README.md
Quickstart
npm i -D prettier prettier-plugin-sort-markdown-table
cat > .prettierrc.js << 'EOF'
module.exports = {
plugins: ['prettier-plugin-sort-markdown-table'],
};
EOF
cat > README.md << 'EOF'
<!-- prettier-sort-markdown-table -->
| name | email |
| ---- | ----- |
| zhang | zhang@a.com |
| wang | wang@a.com |
| alice | alice@example.com |
EOF
npx prettier --write README.md
# Output README.md rows sorted by first column alphabetically: alice, wang, zhang