Sort Markdown table rows alphabetically or numerically based on specific columns. Format and align table grids.
The Markdown Table Sorter operates by parsing raw GFM (GitHub Flavored Markdown) strings into a structured two-dimensional array. The engine utilizes a regular expression-based tokenizer to identify the header separator (the line containing dashes and colons) and splits the content into a header row and a body dataset. Once the data is internalized, the tool applies a custom comparator function that detects the data type of the selected column—distinguishing between numeric, alphanumeric, and boolean values—to ensure that '10' is sorted after '2' rather than before it in a lexicographical sequence.
Unlike basic text sorters, this tool implements a stable sorting algorithm that preserves the relative order of records with equal keys. Key technical capabilities include:
To utilize the tool, paste your raw Markdown table into the editor. Select the target column index and the desired sort direction. The tool will re-map the array and rejoin the strings using the original pipe | delimiters. For developers automating this via a pipeline, you can simulate the sorting logic using a JavaScript snippet:
const sortMdTable = (md) => { const lines = md.trim().split('\n'); const header = lines[0]; const separator = lines[1]; const rows = lines.slice(2).map(r => r.split('|').filter(c => c.trim() !== '')); rows.sort((a, b) => a[0].localeCompare(b[0], undefined, {numeric: true})); return [header, separator, ...rows.map(r => '| ' + r.join(' | ') + ' |')].join('\n'); };Alternatively, for those using Python for documentation preprocessing, the pandas library can be leveraged to read the markdown format, apply sort_values(), and export back to a string format.
The Markdown Table Sorter is designed as a client-side utility. This means the parsing and sorting logic execute entirely within the user's browser environment using WebAssembly or native JavaScript. No data is transmitted to a remote server, ensuring that sensitive API keys, internal IP addresses, or proprietary project data contained within your tables remain private. The tool adheres to a zero-trust architecture, meaning there is no backend database and no session logging of the input content.
This tool is specifically engineered for:
README.md files.The tool employs a natural sort algorithm that detects if a cell contains only digits or a combination of numbers and letters. If a column is identified as numeric, it converts the strings to floating-point numbers before comparison to avoid the common issue where '10' comes before '2'. For alphanumeric columns, it uses the localeCompare method with the numeric option enabled, ensuring a human-readable sequence.
The sorter is designed to preserve the structural integrity of GitHub Flavored Markdown (GFM). It isolates the header and the alignment separator row (e.g., |---|---|) before sorting the data rows. Once the sort is complete, it re-assembles the table by appending the sorted rows back to the original header, ensuring that the visual pipes and alignment markers remain intact.
All processing is performed locally within your browser's JavaScript engine. The tool does not use an API backend for the sorting logic, meaning your data never leaves your local machine. This makes the tool safe for use with sensitive internal documentation, as there is no risk of data interception or server-side logging of your table content.
The tool is optimized for standard GFM tables where each row has a consistent number of pipes. It does not support complex HTML-style merged cells (colspan/rowspan) as these are not natively supported by standard Markdown. If a row has an inconsistent number of columns, the tool will treat the missing cells as empty strings to prevent the sorting algorithm from crashing.
While the web tool is manual, you can achieve similar results in a Bash pipeline by using the 'sort' command combined with 'sed' to skip the header. For example, using `tail -n +3 input.md | sort -t'|' -k2,2 > sorted_body.txt` allows you to sort by the second column. You would then prepend the original header and separator lines back to the sorted body to recreate the full Markdown table.