Skip to main content

PureHTML

Purify HTML by filtering tags and classes

Install

pip install --upgrade purehtml

Usage

from purehtml import purify_html_files
from pathlib import Path

html_root = Path(__file__).parent / "samples"
html_paths = list(html_root.glob("*.html"))
html_path_and_purified_content_list = purify_html_files(html_paths)
for item in html_path_and_purified_content_list:
    html_path = item["html_path"]
    purified_content = item["purified_content"]
    print(html_path)
    print(purified_content)

What params should I choose in different scenarios?

Functions

purify_html_str  ( html_str  : str )

purify_html_file ( html_path : Union[Path, str] )

purify_html_files( html_paths: list[Union[Path, str]] )

Params

Here are the params of purify_html_files():

  • verbose: bool (default False)
    • True: Output to console
    • False: No output to console
  • output_format: str (default "html")
    • "html": Output HTML format (.html.pure)
    • "markdown": Output markdown format (.md)
  • keep_href: bool (default False)
    • True: Keep href in <a> tags, and keep src in <img> tags
      • This is useful for detailed information retrieval
    • False: Do not keep href and src
  • keep_format_tags: bool (default True)
    • True: Keep format tags
      • such as: <sub>, <sup>, <b>, <strong>, <em>, <a>, <i>, <u>, mark, del, cite, blockquote
      • This is useful for rendering HTML
    • False: Remove format tags
  • keep_group_tags: bool (default True)
    • True: Keep group tags: <div>, <section>, <details>
      • This is useful for hierarchical processing, such as grouping texts in RAG
    • False: Remove group tags
  • math_style: str (default "latex")
    • "latex": Convert math tag to latex string
      • This is useful for LLM and RAG
    • "latex_in_tag": Wrap above latex string with tag
      • <div> for block, <span> for inline
      • This is useful for hierarchical processing
    • "html": Keep math formulas in mathml format
      • This is useful for rendering HTML

For: LLM, RAG, text chunking and embedding

Hierarchical:

results = purify_html_files(
    html_paths,
    verbose=False,
    output_format="html",
    keep_href=False,
    keep_format_tags=False,
    keep_group_tags=True,
    math_style="latex_in_tag",
)

Flat:

results = purify_html_files(
    html_paths,
    verbose=False,
    output_format="html",
    keep_href=False,
    keep_format_tags=False,
    keep_group_tags=False,  # <--
    math_style="latex",     # <--
)

For: HTML rendering

With links:

results = purify_html_files(
    html_paths,
    verbose=False,
    output_format="html",
    keep_href=True,         # <--
    keep_format_tags=True,  # <--
    keep_group_tags=True,   # <--
    math_style="html",      # <--
)

Without links: (This is the default config in dev)

results = purify_html_files(
    html_paths,
    verbose=False,
    output_format="html",
    keep_href=False,        # <--
    keep_format_tags=True,
    keep_group_tags=True,
    math_style="html",
)

Even without any format:

results = purify_html_files(
    html_paths,
    verbose=False,
    output_format="html",
    keep_href=False,
    keep_format_tags=False, # <--
    keep_group_tags=True,
    math_style="html",
)

Metadata

Release files for purehtml 0.7.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for purehtml 0.7.5
File Size Uploaded Provenance Actions
purehtml-0.7.5.tar.gz 9.8 kB Without provenance Details for purehtml-0.7.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for purehtml 0.7.5
File Interpreter ABI Platform Actions
purehtml-0.7.5-py3-none-any.whl Python 3 none any Details for purehtml-0.7.5-py3-none-any.whl

Total release size: 19.4 kB

Release files / purehtml-0.7.5.tar.gz

Download URL purehtml-0.7.5.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
07c64fd5b503081ccbc13f9ce15c9dc1879331e6e9a2b163be16b5dd173eecba
BLAKE2b-256 checksum
How to use checksums
8a2784082ac063093a234a7dbced3ea3cc7a4f1fbe75f209dd314bc69418463a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / purehtml-0.7.5-py3-none-any.whl

Download URL purehtml-0.7.5-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71b4cb8c9bf7e07e7ab247a4630ff2e3395a36fa58f0429f4ca602e169cc469b
BLAKE2b-256 checksum
How to use checksums
589a79f3da8223db833a3d2cad629dff1930b872950a279892dcd390297199de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Security for purehtml 0.7.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page