Shared validation for Office image-rendering hooks.
# Source: https://github.com/microsoft/markitdown | License: MIT | Copyright Microsoft Corporation
# Provided via justclaw.it.com; keep this notice with the code.
"""Shared validation for Office image-rendering hooks."""
from typing import Optional
from bs4 import BeautifulSoup, Doctype
def _parse_image_html(fragment: Optional[str]) -> Optional[BeautifulSoup]:
if fragment is not None and not isinstance(fragment, str):
raise TypeError("_image_to_html must return an HTML string or None")
if fragment is None or not fragment.strip():
return None
soup = BeautifulSoup(fragment, "html.parser")
if soup.find(["html", "head", "body"]) or any(
isinstance(node, Doctype) for node in soup.descendants
):
raise ValueError("_image_to_html must return
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key