all2md.parsers.mhtml

MHTML parser that converts MHTML files to AST representation.

This module provides the MhtmlToAstConverter class that parses MHTML single-file web archives and builds an AST representation.

class all2md.parsers.mhtml.MhtmlToAstConverter

Bases: BaseParser

Convert MHTML files to AST representation.

This parser extracts HTML content from MHTML archives and converts it to AST using the HTML parser.

Parameters:

options (MhtmlOptions or None) – MHTML conversion options

Initialize the MHTML parser with options and progress callback.

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

Initialize the MHTML parser with options and progress callback.

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

Parse MHTML file into an AST Document.

Parameters:

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

Returns:

AST Document node representing the parsed MHTML structure

Return type:

Document

Raises:

ParsingError – If parsing fails due to invalid MHTML format

extract_metadata(document: Any, html_content: str = '') DocumentMetadata

Extract metadata from MHTML message.

Parameters:
  • document (EmailMessage) – MHTML message object

  • html_content (str, optional) – HTML content for additional metadata extraction

Returns:

Extracted metadata

Return type:

DocumentMetadata