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.0-cp312-cp312-win_amd64.whl (353.9 kB view details)

Uploaded CPython 3.12Windows x86-64

innertext-0.2.0-cp312-cp312-musllinux_1_1_x86_64.whl (718.1 kB view details)

Uploaded CPython 3.12musllinux: musl 1.1+ x86-64

innertext-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (486.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

innertext-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (441.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

innertext-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl (446.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file innertext-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: innertext-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 353.9 kB
  • Tags: CPython 3.12, 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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 15dbd4d7c950ceb98f981215339d7b15acda45b00ee9e3b564c7e6710c18a01b
MD5 577558201a74cd5fec8aa45a0ec5c70f
BLAKE2b-256 76e445aa05979dbd8ae06d21d2f578a61656309bb4032d0a367a141ece503a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.0-cp312-cp312-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.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 132006b26e691d76b00034812dda0c5d378f5570314bf4da99094c7c1b5c0533
MD5 539fefa9e7008b78ddee9866602c6c80
BLAKE2b-256 4d990f52158a61586811d67d00447fcbb7c45700ce33318d255d5c626f2df42b

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.0-cp312-cp312-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.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3c10a39f5323c1e7779872f53c8d10f7a7ca512b1c668fbf9877bd8242d7c91
MD5 3c9a4a88b0deedf9e50c1b482508bdd5
BLAKE2b-256 9741eb766c4d3150d60dcb21ce13e298b34a283ad6dd4d4f9d23d2cf0c38101f

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.0-cp312-cp312-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.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for innertext-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b636be06f493ff5d64c1fcc472e941fbaf2715d9bec4202d0e15f567c7e907a2
MD5 f1b628557b9df78be2fce97a227ef2ac
BLAKE2b-256 17382bfc318d71f15ab9883dc1501636d2b4d4f195ea48d2442d88bc0cc7b889

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.0-cp312-cp312-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.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for innertext-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 041f0a4ddbd69be992a1e09b6ae4824cbf2ea194eb67f2d1a67edaad635f813f
MD5 1e810e45676555664d1e58813e0b106c
BLAKE2b-256 eff5af095a52a7a54768912d350d48d2f84e9549dab9e1718f6acab11ffe945e

See more details on using hashes here.

Provenance

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