Render multiline cells as <br> instead of breaking the table - #88
Merged
Merged
Conversation
A markdown table row has to fit on a single line, so a cell containing a newline split one logical row across several broken rows. Newlines in cells are now replaced with <br>, alongside the existing pipe escaping. This only applies to table formats that put a row on one line (pipe, github); formats like grid display multiline cells themselves and are left alone. This affects every reader, not just read_csv: pandas already parsed quoted multiline cells correctly, it was the markdown conversion that broke them. Closes #83 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uz8oZU8gDib9swRkLKSoXe
timvink
commented
Sep 14, 2026
mkdocs logs the error and then re-raises it. Whether that log record ends up in CliRunner's result.output is flaky on windows: the same commit passed on windows-3.10 in one run and failed in another. The exception itself is deterministic, carries the same message, and is what the plugin actually contracts to raise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uz8oZU8gDib9swRkLKSoXe
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 #83.
The issue's diagnosis was off
The report asks for
csv.readerfrom the stdlib as a new reader, because "the pandas readers don't recognize multiline cells in CSV". They actually do —pd.read_csvparses the reporter's own example correctly:{'id': 23456, 'severity': 'low', 'description': 'Sometimes the cell text is quoted.\n\nBut not always'}What broke was rendering.
df.to_markdown(tablefmt="pipe")emits the embedded newline literally, so one logical row shatters into three broken ones:Adding
csv.readerwould have changed nothing — it returns the identical cell value.The fix
In
convert_to_md_table, newlines in cells and column names are replaced with<br>, alongside the pipe escaping that was already there. Both now run in a singleescape()pass.This is guarded on
tablefmt: it only applies topipeandgithub, which put a row on one line. Formats likegridrender multiline cells natively, and injecting<br>there would be visible junk.Because the fix sits in the markdown conversion rather than in a reader, it benefits every reader —
read_excel,read_yaml,read_jsonand friends, not justread_csv.No new config option: a cell with a newline produces a broken table today, so there's no working behaviour to preserve.
Note on the second example in the issue
The first block in the report isn't valid CSV — the line break isn't inside quotes:
csv.readersplits that into three separate records too, so no reader change could have helped. Multiline cells have to be quoted, which the docs note now says.Tests
test_replace_newlines— unit coverage for the new helpertest_convert_to_md_table_multiline— asserts the table stays 4 linestest_convert_to_md_table_multiline_other_tablefmt— assertsgridoutput is untouchedtest_csv_with_multiline_cells— full mkdocs build over a newtests/fixtures/csv_multiline/fixture, asserting 3<tr>in the rendered tableFull suite passes (38),
mkdocs build --strictis clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01Uz8oZU8gDib9swRkLKSoXe