Repository navigation
Escape row index labels in Markdown tables - #94
Merged
Merged
Conversation
With index=True, a pipe in a row label or index name added an extra cell, and a newline split the row. Apply the existing cell escaping to the index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Update: Thanks @bensynapse for reporting in #93
Problem
With
index=True, row labels and the index name were passed to tabulate without escaping. A pipe in a label (a|b) added an extra cell, and a newline in a label split the row, so the Markdown table broke:Cells and column headers were already escaped; the index was not.
Fix
When
index=True, apply the existing cell escaping (|→\|, and newlines →<br>forpipe/github) to the row labels and index name:index=Falsepath skips this step entirely.(1, 'a\\|b')), which escaping cannot fix, and does not show its names.Benchmark
convert_to_md_tableon a 5-column string table,masterversus this branch, median of 15 runs (macOS, Apple Silicon):indexindex=False(the default): no measurable change.index=Truewith aRangeIndex(whatread_csvproduces): about 1–1.5%.index=Truewith string labels: about 4–7%, one extra pass over the row labels.Most of the time is spent in
DataFrame.to_markdownitself in all cases.Benchmark script
Tests
New tests cover pipes and newlines in labels and the index name, the input DataFrame staying unchanged, and unchanged output for integer, date, tuple and MultiIndex indexes.
make testpasses (64 tests, 100% coverage).🤖 Generated with Claude Code