all2md.parsers.chm
CHM (Microsoft Compiled HTML Help) parser that converts CHM files to AST representation.
This module provides the ChmParser class that parses CHM files, extracts HTML content from pages, and builds an AST representation. CHM files are compressed archives of HTML pages with a table of contents structure, commonly used for software documentation.
- class all2md.parsers.chm.ChmParser
Bases:
BaseParserConvert CHM files to AST representation.
This parser extracts content from Microsoft Compiled HTML Help (CHM) files, processes each page’s HTML content, and builds a unified AST document.
- Parameters:
options (ChmOptions or None) – CHM conversion options
progress_callback (ProgressCallback or None, default = None) – Optional callback for progress updates during parsing
Initialize the CHM parser with options and progress callback.
- __init__(options: ChmOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)
Initialize the CHM parser with options and progress callback.
- parse(input_data: str | Path | IO[bytes] | bytes) Document
Parse CHM file into an AST Document.
- Parameters:
input_data (str, Path, IO[bytes], or bytes) – The input CHM file to parse. Can be: - File path (str or Path) - File-like object in binary mode - Raw CHM bytes
- Returns:
AST Document node representing the parsed CHM structure
- Return type:
- Raises:
ParsingError – If parsing fails due to invalid CHM format
ValidationError – If input data is invalid
- convert_to_ast(chm_file: Any) Document
Convert CHM file to AST Document.
- Parameters:
chm_file (chm.chm.CHMFile) – CHM file object
- Returns:
AST document node
- Return type:
- extract_metadata(document: Any) DocumentMetadata
Extract metadata from CHM file.
- Parameters:
document (chm.chm.CHMFile) – CHM file object
- Returns:
Extracted metadata
- Return type:
Notes
CHM files have limited metadata support. This method attempts to extract what’s available, primarily from the title and home page.