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 Distribution

innertext-0.2.2.tar.gz (17.5 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.2-cp37-abi3-win_amd64.whl (354.9 kB view details)

Uploaded CPython 3.7+Windows x86-64

innertext-0.2.2-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.2-cp37-abi3-musllinux_1_1_aarch64.whl (701.8 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ ARM64

innertext-0.2.2-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.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (525.8 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

innertext-0.2.2-cp37-abi3-macosx_11_0_arm64.whl (442.0 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

innertext-0.2.2-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.2.tar.gz.

File metadata

  • Download URL: innertext-0.2.2.tar.gz
  • Upload date:
  • Size: 17.5 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.2.tar.gz
Algorithm Hash digest
SHA256 89536bb9319a85e43b71a51ef73a48378f1c79038fc3f673c5ebf9eda62a20f7
MD5 0a0a0f4b0160bf49390e30800712a292
BLAKE2b-256 0117125fa46beb715772c7f9d9f43b19a3b5e7dbaf07063018e02285ff66ae53

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.2.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.2-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: innertext-0.2.2-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.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6aecd0764cd780ce8c605e653134bd211b46018197fe1de1c3eb1a47e0af9b10
MD5 f1b4270a6b1a7f512ef58bf854ce1f55
BLAKE2b-256 4e442335541a5fb2e4136d38f4692d1e5a704ffd7da3d8a78954cb41f5e30123

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a59ac544840c2910086a14829278638e308300fdab19c2146e24ec342dcecf05
MD5 d1f2c6ea6c3dda1fd360b487e2231a0f
BLAKE2b-256 4058c759c87bd951e0f136f1d37d7042d030630705b103b3bef092cf3bce25a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 46ccc4ee6edc2b397238f6a4a31c3610d7f2cdc5013ccfec17d897c812a28494
MD5 93d548cec8f2d4a5a222e7dd1243c89f
BLAKE2b-256 9442674729140bcd8147e92a25b993a20d47539270eecce74d24752864b974e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e774f727aefd5c173103f4b4473dbef62546774cc02e615e3f8443cc5f7b1e1f
MD5 c5aa0248a0c5ba13af9faa895dc3a183
BLAKE2b-256 ea21dd13557fdd6f638f33cdebc3c311dcd1ca614252345f78d01324538eeb23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 19bcf6557e5b51d526cd2ad67ea08e0b96a8fdfc3ad8dfdf709308402f084743
MD5 ea50e65b2a20d985d3654dbf99d9e5c5
BLAKE2b-256 9d25f310129dcf5da69b8d7ea07a6a3a31f98dd461d21b34136a3cc7fad236c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for innertext-0.2.2-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.2-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 838ab66a24ee6ba17330728a66a2b6bddf187ca06976250a0435cad58f495815
MD5 7bb90cde3f19fb3aeb322b42599eeba4
BLAKE2b-256 30bd1a753c788c7cfbdccd9068be2ffd50ce34cbd17b2aee47dd9e3ed7a9f62b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.2-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c9e05bee33fe63da95506b4dd701d2dee74448a325740e3606bfa2c11faafadd
MD5 bdc298ed95d0fb7674eb53470a5c6914
BLAKE2b-256 85dfd3bb04cdde494128839b2cec4dd3ab5ba5e1a655e7bf8ebdeb205d10d981

See more details on using hashes here.

Provenance

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