all2md.parsers.csv

CSV/TSV to AST converter.

This module provides conversion from CSV and TSV files to AST representation. It replaces the combined spreadsheet parser with a focused delimiter-separated values parser.

class all2md.parsers.csv.CsvToAstConverter

Bases: BaseParser

Convert CSV/TSV files to AST representation.

This converter handles CSV and TSV (tab-separated values) formats by building Table nodes from delimited text data.

Parameters:

options (CsvOptions or None) – Conversion options

Initialize the CSV parser with options and progress callback.

__init__(options: Any = None, progress_callback: Callable[[ProgressEvent], None] | None = None)

Initialize the CSV parser with options and progress callback.

parse(input_data: str | Path | IO[bytes] | IO[str] | bytes) Document

Parse CSV/TSV file into an AST.

Parameters:

input_data (str, Path, IO[bytes], IO[str], or bytes) – The input CSV/TSV file to parse

Returns:

AST Document node representing the parsed spreadsheet structure

Return type:

Document

Raises:

ParsingError – If parsing fails due to invalid format

csv_to_ast(input_data: str | Path | IO[bytes] | IO[str] | bytes, delimiter: str | None = None) Document

Convert CSV/TSV to AST Document.

Parameters:
  • input_data (Union[str, Path, IO[bytes], IO[str], bytes]) – Input data

  • delimiter (str | None) – Delimiter character to use (e.g., ‘,’ for CSV, ‘\t’ for TSV)

Returns:

AST document with table node

Return type:

Document

extract_metadata(document: Any) DocumentMetadata

Extract metadata from CSV/TSV document.

Parameters:

document (Any) – Document object (None for CSV/TSV)

Returns:

Empty metadata (CSV/TSV don’t have structured metadata)

Return type:

DocumentMetadata