Skip to main content

Pure Rust WHATWG-compliant innerText, outerText, and textContent extraction

Project description

innertext (Python)

Pure Rust WHATWG-compliant innerText, outerText, and textContent extraction from HTML.

Installation

pip install innertext

Quick Start

import innertext

html = """
<div id="root">
    Hello <span style="display:none">hidden</span> World
    <script>console.log("not shown")</script>
</div>
"""

# Get rendered text (CSS-aware)
print(innertext.inner_text(html))  # "Hello World"

# Get structural text (CSS-blind)
print(innertext.text_content(html))  # "Hello hidden console.log("not shown")"

API

Functions

inner_text(html: str) -> str

Extract innerText from HTML string. Implements the WHATWG innerText algorithm:

  • Respects display CSS property (skips display:none)
  • Respects visibility CSS property
  • Respects white-space CSS property (normal, pre, pre-line, pre-wrap)
  • Respects text-transform CSS property
  • Handles replaced elements (textarea, input, img)
  • Converts <br> tags to newlines

outer_text(html: str) -> str

Extract outerText from HTML string. Per WHATWG spec, outerText getter is identical to innerText getter.

text_content(html: str) -> str

Extract textContent from HTML string. Performs CSS-blind structural walk:

  • Ignores all CSS properties
  • Includes display:none content
  • Includes <script> and <style> content

Accuracy

100% Chromium parity on 36+ test cases covering:

  • Display and visibility handling
  • Whitespace normalization (normal, pre, pre-line)
  • Block element newlines
  • Table cell/row separators
  • Replaced elements (textarea, input, img, button)
  • Metadata elements (script, style)
  • Unicode and entity handling

Performance

  • Pure Rust implementation
  • Zero external runtime dependencies
  • <1ms per document (parsing + extraction)
  • Minimal memory overhead (O(n) DOM tree)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

innertext-0.2.1-cp37-abi3-win_amd64.whl (354.9 kB view details)

Uploaded CPython 3.7+Windows x86-64

innertext-0.2.1-cp37-abi3-musllinux_1_1_x86_64.whl (718.6 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ x86-64

innertext-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (487.1 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

innertext-0.2.1-cp37-abi3-macosx_11_0_arm64.whl (442.1 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

innertext-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl (447.8 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file innertext-0.2.1-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: innertext-0.2.1-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 354.9 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for innertext-0.2.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 66cf04da9bc78715cb27fd5a6288aff73d7d417e5fae5adfafc90021709c57c1
MD5 d42f4dc1125749f2ee12532b6cd0ec07
BLAKE2b-256 03de4ccb173f95ba92380282f8a272241ba429040ad025727fbfeb52870a78c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.1-cp37-abi3-win_amd64.whl:

Publisher: publish-pypi.yml on jafayer/innertext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file innertext-0.2.1-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.1-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 248e3631a7314a6bb64122cd43392c90ecf4a095b79fba242f4b87f7c1e580a1
MD5 f63d975056ccccf846f89ec2717f04a2
BLAKE2b-256 8efda7335e568f1d2d8bf68dc38f7ac9215b245ad85372cdd1b02901783ef343

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.1-cp37-abi3-musllinux_1_1_x86_64.whl:

Publisher: publish-pypi.yml on jafayer/innertext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file innertext-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73ae01f7027dc706bb4f894c4ca45bb5ce3b54662905c77e35098e4a3eb307bf
MD5 df3b7fdd15edeb755772d32345c4b917
BLAKE2b-256 b004b7eec6ab1f046195f338721081da056c11e1dabfaf02397bd5bff5ac28d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on jafayer/innertext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file innertext-0.2.1-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for innertext-0.2.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af5a98875b66cd93749f4903e243c3337312a9dfbe9aa614d48a6cf92acce41d
MD5 f0df480719e5cd8ba791aae69a2a5381
BLAKE2b-256 0b6988022c41cfbe2ac4971c86121f74607361b8c09669eb477994f35f6512cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.1-cp37-abi3-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on jafayer/innertext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file innertext-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 747731f31ea1f854db78652c928e1e459db44f8ae76436e09ebfcc7789388fff
MD5 8929e9222181cba6f0a87b43a006c361
BLAKE2b-256 40e1077a3a8476b08a412c58aac5b66a15bc8029818003a3672a6eda14183828

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-pypi.yml on jafayer/innertext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page