Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def convert(
reader = csv.reader(io.StringIO(content))
rows = list(reader)

# A leading blank line (or any empty rows before the header) parses as an
# empty list. If that becomes the header its column count is 0, and every
# data row then gets truncated to nothing -- silent total data loss.
# Skip leading empty rows so the first real row becomes the header.
while rows and len(rows[0]) == 0:
rows.pop(0)

if not rows:
return DocumentConverterResult(markdown="")

Expand Down
14 changes: 14 additions & 0 deletions packages/markitdown/tests/_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ class FileTestVector(object):
],
must_not_include=[],
),
FileTestVector(
filename="test_blank_first_line.csv",
mimetype="text/csv",
charset="utf-8",
url=None,
must_include=[
"| name | age |",
"| bob | 3 |",
"| alice | 7 |",
],
must_not_include=[
"| |",
],
),
FileTestVector(
filename="test.json",
mimetype="application/json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

name,age
bob,3
alice,7