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")"

Packaging Notes

The published Python package uses a two-layer layout:

  • innertext is a regular Python package with a runtime __init__.py
  • the compiled Rust extension is loaded as innertext._innertext

This avoids namespace-package import issues and ensures import innertext always exposes inner_text, outer_text, and text_content.

Type Hints

This package ships with PEP 561-compatible typing metadata:

  • innertext/__init__.pyi defines the public API types
  • innertext/py.typed marks the package as typed

Type checkers such as mypy and pyright can therefore infer:

  • inner_text(html: str) -> str
  • outer_text(html: str) -> str
  • text_content(html: str) -> str

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 Distribution

innertext-0.2.4.tar.gz (18.6 kB view details)

Uploaded Source

Built Distributions

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

innertext-0.2.4-cp37-abi3-win_amd64.whl (356.7 kB view details)

Uploaded CPython 3.7+Windows x86-64

innertext-0.2.4-cp37-abi3-musllinux_1_1_x86_64.whl (720.5 kB view details)

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

innertext-0.2.4-cp37-abi3-musllinux_1_1_aarch64.whl (703.8 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ ARM64

innertext-0.2.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (488.8 kB view details)

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

innertext-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (527.4 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

innertext-0.2.4-cp37-abi3-macosx_11_0_arm64.whl (443.9 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

innertext-0.2.4-cp37-abi3-macosx_10_12_x86_64.whl (449.8 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file innertext-0.2.4.tar.gz.

File metadata

  • Download URL: innertext-0.2.4.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for innertext-0.2.4.tar.gz
Algorithm Hash digest
SHA256 6675cc9d6171dda0c502502a36e1a7868c55aa03d420cf757e627381388f1dfc
MD5 79bb274837130b696afd920e418a598a
BLAKE2b-256 938115a4ecc6afb72947f8e11dd7711c97f2f863adb0f7c59212979218d8a88e

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4.tar.gz:

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.4-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: innertext-0.2.4-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 356.7 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.4-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a108360255f30751ec995fc870a9ba6f77274e74f5f9bd24754cd4e78eadd880
MD5 e7197839e117623b60b8c82fb443d5a0
BLAKE2b-256 be1e54640f807a2637eaa1dbb3dbf4a9c1fbe41653789a3e893ebfe06d8db9b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-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.4-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 cc63dbea6b556b9d8f38fbd45132679ca13269665cf6ef0a80534474c3b68777
MD5 dbba7f0d83997465459a721e2d8f0e8f
BLAKE2b-256 e14ff84dcec107aaf45f871b524788cf2b43f59a1e72d338cd2e018ea37602de

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-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.4-cp37-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 82856274148786daa6ce41764de636343aa45289b9cb15ab1a2c869f194839d7
MD5 1fe4f821b22c632ccd0a1ed70b8befc4
BLAKE2b-256 cc01a3c04348104e5e2a8d8759bd8dc6cd052e25fed49d96a0545e4ab8717507

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-cp37-abi3-musllinux_1_1_aarch64.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.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7b3155990b73a46a636612e69b891f7d7ad1fbf257d180e1d2c860315626432
MD5 15c0d70a0700a206e7eca177182c3ded
BLAKE2b-256 a25fe46facadf9dea57c5cc5b182b38f739bc64dc2d5464318c709ae2b0afa6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-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.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8038596425ad557a30771ebc2485eb98f69295d64b69c66c7b35fb59c273603e
MD5 c24e58a5482fbf2ff854574eaeafef66
BLAKE2b-256 7b0e916da3d2a5f06622005ae15bb92d6ad9d04f86ce18233178d7681d4838a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.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.4-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c9a2324c70d29656a0590682ec376e07ff630503352bb437f0df6ba0543bfda
MD5 8cbba565b300c058ac730dad4030ff3f
BLAKE2b-256 98f00e5a4708c9a3ab67fe21fac7602501050bac67d77cfc4faeecef592990f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-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.4-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.4-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9b3e6d5d026de49955013b7547d718605463c74110a8fe49a7ebb334b709c4f7
MD5 2f88e19add371b6637fc658039a4e07c
BLAKE2b-256 9c21bad257678a2a86eea1ca61f11b5f86c608d537bb68b203d71b5b0c35a809

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.4-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