feat: add TSV support and delimiter auto-detection to CsvConverter#2021
Open
anandmt wants to merge 1 commit into
Open
feat: add TSV support and delimiter auto-detection to CsvConverter#2021anandmt wants to merge 1 commit into
anandmt wants to merge 1 commit into
Conversation
Extend CsvConverter to handle TSV files alongside CSV by accepting .tsv extension and text/tab-separated-values MIME type, and using csv.Sniffer to auto-detect delimiters with sensible fallbacks. Also escape pipe characters and newlines in cell values to prevent broken Markdown tables.
|
@anandmt please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Summary
CsvConverterto accept.tsvfiles andtext/tab-separated-values/text/tsvMIME typescsv.Snifferwith sensible fallbacks (tab for.tsv, comma otherwise)|) and newlines in cell values to prevent broken Markdown tables (also addresses [BUG]: CsvConverter produces broken Markdown tables when cell values contain pipe characters (|) #2019)Motivation
TSV (Tab-Separated Values) files are extremely common in data science, bioinformatics, and LLM pipelines, but are not currently supported by MarkItDown. This is a natural extension of the existing CSV converter.
Changes
_csv_converter.py: Added.tsvextension and TSV MIME types to accepted formats. Added_detect_delimiter()usingcsv.Snifferfor auto-detection with fallbacks. Added_escape_cell()to escape pipe characters and newlines in cell values.test_files/test.tsv: New test file with tab-delimited data including a pipe character in a cell value._test_vectors.py: NewFileTestVectorfor TSV conversion withmust_includechecks.Test plan
convert_local,convert_stream_with_hints,convert_stream_without_hints,convert_file_uri,convert_data_uri)test_mskanji.csv) continues to pass — delimiter auto-detected as comma\|in output