Add --markdown-tables to lay out Markdown tables - #4008
Closed
Arya-Programmer wants to merge 6 commits into
Closed
Arya-Programmer wants to merge 6 commits into
Arya-Programmer wants to merge 6 commits into
Conversation
- Add markdown_table module: buffers table lines, pads cells, draws borders - Honour :--- / :--: / ---: alignment and unicode cell widths - Skip fenced code blocks; keep one output line per input line
- Add integration test and markdown-table.md example - Refresh Markdown syntax-test snapshot - Add CHANGELOG entry
- Surround tables with ┌┬┐ / └┴┘ and rule the header with ╞═╪╡, matching comfy-table UTF8_FULL and rich SQUARE - Print the two added border lines as continuations, so they take a blank gutter instead of a line number - Leave tables alone under --unbuffered, which cannot buffer - Leave 4-space indented code blocks alone - Move the test ANSI helper into tests/utils
- Off by default, so bat's output stays byte-for-byte identical to the input and keeps the drop-in cat goal - Wire the flag through clap, app, Config and PrettyPrinter - Document it in README, the man page, both help texts and the bash/fish/zsh/ps1 completions - Restore the Markdown syntax-test snapshot to its upstream form - Test the default, the flag, and --unbuffered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4007.
Adds
--markdown-tables, which lays out the tables in a Markdown file so the columns line up, and draws a border around them.Cells keep the alignment the delimiter row asks for, and cell widths are measured with
unicode-width, so wide characters line up too. The border shape is the one comfy-table and rich settled on.How it works
A table cannot be laid out until all of its rows have been seen, so
TableRendererin the newsrc/markdown_table.rsholds the lines back until the table ends, then rewrites them. The rewrite happens before highlighting, so syntect and the decorations carry on as normal.The two border lines are the only lines that do not exist in the file. They are printed the way a wrapped line is, as a continuation with an empty gutter, so every real line keeps its own number.
Notes
It is off by default, because it changes the text that gets printed and that would work against the drop-in cat goal. Without the flag the output is byte for byte the input, and the Markdown syntax test fixture is unchanged.
It has no effect under
--unbuffered, since holding lines back is the opposite of what that mode is for, and no effect inside fenced or indented code blocks.PrettyPrinter::markdown_tablesexposes the same thing to library users.Known limits
Tabs inside cells are measured before
expand_tabsruns, so a cell containing a tab can still be off. A table wider than the terminal wraps like any other long line. With--line-range, only the visible rows are measured, so the columns can come out narrower than in a full render.