# pyright: reportPrivateUsage=false """Provides `partition_html().""" from __future__ import annotations from functools import cached_property from typing import IO, Any, Callable, Iterator, List, Literal, Optional, cast from lxml import etree from unstructured.chunking import add_chunking_strategy from unstructured.documents.elements import Element, ElementType from unstructured.file_utils.encoding import read_txt_file from unstructured.file_utils.model import FileType from unstructured.partition.common.metadata import apply_metadata, get_last_modified_date from unstructured.partition.html.parser import Flow, html_parser from unstructured.partition.html.transformations import ( ontology_to_unstructured_elements, parse_html_to_ontology, ) from unstructured.safe_http import safe_get from unstructured.utils import is_temp_file_path @apply_metadata(FileType.HTML) @add_chunking_strategy def partition_html( filename: Optional[str] = None, *, file: Optional[IO[bytes]] = None, text: Optional[str] = None, encoding: Optional[str] = None, url: Optional[str] = None, headers: dict[str, str] = {}, ssl_verify: bool = True, skip_headers_and_footers: bool = False, detection_origin: Optional[str] = None, html_parser_version: Literal["v1", "v2"] = "v1", image_alt_mode: Optional[Literal["to_text"]] = "to_text", extract_image_block_to_payload: bool = False, extract_image_block_types: Optional[list[str]] = None, languages: Optional[list[str]] = None, detect_language_per_element: bool = False, language_fallback: Optional[Callable[[str], Optional[list[str]]]] = None, **kwargs: Any, ) -> list[Element]: """Partitions an HTML document into its constituent elements. HTML source parameters ---------------------- The HTML to be partitioned can be specified four different ways: filename A string defining the target filename path. file A file-like object using "r" mode --> open(filename, "r"). text The string representation of the HTML document. url The URL of a webpage to parse. Only for URLs that return an HTML document. headers The HTTP headers to be used in the HTTP request when `url` is specified. ssl_verify If the URL parameter is set, determines whether or not SSL verification is performed on the HTTP request. encoding The encoding method used to decode the text input. If None, utf-8 will be used. skip_headers_and_footers If True, ignores any content that is within
or