all2md.options.csv
Configuration options for CSV parsing.
This module defines options for parsing CSV files with customizable dialects.
- class all2md.options.csv.CsvOptions
Bases:
BaseParserOptionsConfiguration options for CSV/TSV conversion.
This dataclass contains settings specific to delimiter-separated value file processing, including dialect detection and data limits.
- Parameters:
detect_csv_dialect (bool, default True) – Enable csv.Sniffer-based dialect detection (ignored if csv_delimiter is set).
delimiter (str | None, default None) – Override CSV/TSV delimiter (e.g., ‘,’, ‘\t’, ‘;’, ‘|’). When set, disables dialect detection.
quote_char (str | None, default None) – Override quote character (e.g., ‘”’, “’”). When set, uses this for quoting.
escape_char (str | None, default None) – Override escape character (e.g., ‘\’). When set, uses this for escaping.
double_quote (bool | None, default None) – Enable/disable double quoting (two quote chars = one literal quote). When set, overrides dialect’s doublequote setting.
has_header (bool, default True) – Whether the first row contains column headers. When False, generates generic headers (Column 1, Column 2, etc.).
max_rows (int | None, default None) – Maximum number of data rows per table (excluding header). None = unlimited.
max_cols (int | None, default None) – Maximum number of columns per table. None = unlimited.
truncation_indicator (str, default "...") – Appended note when rows/columns are truncated.
header_case (str, default "preserve") – Transform header case: preserve, title, upper, or lower.
skip_empty_rows (bool, default True) – Whether to skip completely empty rows.
strip_whitespace (bool, default False) – Whether to strip leading/trailing whitespace from all cells.
dialect_sample_size (int, default 4096) – Number of bytes to sample for csv.Sniffer dialect detection. Larger values may improve detection for heavily columnated files but increase memory usage during detection.
- detect_csv_dialect: bool = True
- dialect_sample_size: int = 4096
- delimiter: str | None = None
- quote_char: str | None = None
- escape_char: str | None = None
- double_quote: bool | None = None
- has_header: bool = True
- max_rows: int | None = None
- max_cols: int | None = None
- truncation_indicator: str = '...'
- header_case: Literal['preserve', 'title', 'upper', 'lower'] = 'preserve'
- skip_empty_rows: bool = True
- strip_whitespace: bool = False
- __init__(extract_metadata: bool = False, detect_csv_dialect: bool = True, dialect_sample_size: int = 4096, delimiter: str | None = None, quote_char: str | None = None, escape_char: str | None = None, double_quote: bool | None = None, has_header: bool = True, max_rows: int | None = None, max_cols: int | None = None, truncation_indicator: str = '...', header_case: Literal['preserve', 'title', 'upper', 'lower'] = 'preserve', skip_empty_rows: bool = True, strip_whitespace: bool = False) None
- class all2md.options.csv.CsvRendererOptions
Bases:
BaseRendererOptionsConfiguration options for CSV rendering from AST.
This dataclass contains settings for rendering AST table nodes to CSV format, including table selection, multi-table handling, and CSV dialect options.
- Parameters:
table_index (int or None, default=0) – Which table to export (0-indexed). Use 0 for first table, 1 for second, etc. Set to None to export all tables.
table_heading (str or None, default=None) – Select table that appears after a heading matching this text (case-insensitive substring). Takes precedence over table_index if both are specified. Example: “Results” will find first table after any heading containing “results”.
multi_table_mode (Literal["first", "all", "error"], default="first") – How to handle documents with multiple tables: - “first”: Export only the first table (default, safest) - “all”: Concatenate all tables with separator - “error”: Raise RenderingError if multiple tables found
table_separator (str, default="\n\n") – Separator text between tables when multi_table_mode=”all”. Only used when multiple tables are exported to a single file.
delimiter (str, default=",") – CSV field delimiter character. Common values: “,” (comma), “\t” (tab), “;” (semicolon).
quoting (Literal["minimal", "all", "nonnumeric", "none"], default="minimal") – CSV quoting style (maps to csv.QUOTE_* constants): - “minimal”: Quote fields only when needed (special chars present) - “all”: Quote all fields - “nonnumeric”: Quote all non-numeric fields - “none”: Never quote (escape special chars instead)
include_table_headings (bool, default=False) – When multi_table_mode=”all”, include the document heading before each table as a comment line (prefixed with #). Useful for identifying tables in combined output.
line_terminator (str, default="\n") – Line ending style. Use “\n” for Unix/Mac, “\r\n” for Windows.
handle_merged_cells (Literal["repeat", "blank", "placeholder"], default="repeat") – How to handle merged cells (cells with colspan > 1 or rowspan > 1): - “repeat”: Repeat the cell value across all merged positions - “blank”: Only the first cell has value, rest are empty - “placeholder”: Use “[merged]” marker in non-first cells
quote_char (str, default='"') – Character used for quoting fields when needed.
escape_char (str or None, default=None) – Character used for escaping when quoting=”none”. If None, doubling is used.
include_bom (bool, default=False) – Include UTF-8 BOM (byte order mark) at start of file. Useful for Excel compatibility with UTF-8 files.
Examples
- Extract first table to CSV:
>>> from all2md.renderers.csv import CsvRenderer >>> from all2md.options.csv import CsvRendererOptions >>> options = CsvRendererOptions() >>> renderer = CsvRenderer(options)
- Extract table by heading:
>>> options = CsvRendererOptions(table_heading="Results") >>> renderer = CsvRenderer(options)
- Export all tables:
>>> options = CsvRendererOptions( ... multi_table_mode="all", ... include_table_headings=True ... )
- table_index: int | None = 0
- table_heading: str | None = None
- multi_table_mode: Literal['first', 'all', 'error'] = 'first'
- table_separator: str = '\n\n'
- delimiter: str = ','
- quoting: Literal['minimal', 'all', 'nonnumeric', 'none'] = 'minimal'
- include_table_headings: bool = False
- line_terminator: str = '\n'
- handle_merged_cells: Literal['repeat', 'blank', 'placeholder'] = 'repeat'
- quote_char: str = '"'
- escape_char: str | None = None
- include_bom: bool = False
- __init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', table_index: int | None = 0, table_heading: str | None = None, multi_table_mode: MultiTableMode = 'first', table_separator: str = '\n\n', delimiter: str = ', ', quoting: CsvQuotingMode = 'minimal', include_table_headings: bool = False, line_terminator: str = '\n', handle_merged_cells: MergedCellHandling = 'repeat', quote_char: str = '"', escape_char: str | None = None, include_bom: bool = False) None