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.3.tar.gz (18.0 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.3-cp37-abi3-win_amd64.whl (355.7 kB view details)

Uploaded CPython 3.7+Windows x86-64

innertext-0.2.3-cp37-abi3-musllinux_1_1_x86_64.whl (719.4 kB view details)

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

innertext-0.2.3-cp37-abi3-musllinux_1_1_aarch64.whl (702.7 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ ARM64

innertext-0.2.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (487.9 kB view details)

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

innertext-0.2.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.6 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

innertext-0.2.3-cp37-abi3-macosx_11_0_arm64.whl (442.9 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

innertext-0.2.3-cp37-abi3-macosx_10_12_x86_64.whl (448.6 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: innertext-0.2.3.tar.gz
  • Upload date:
  • Size: 18.0 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.3.tar.gz
Algorithm Hash digest
SHA256 5f749f67fce749a189dabc8c84813d978f7d8cbd861e9284ca555f1f68f746ce
MD5 233965ce8c115d58d7cd9b3b0f4283e6
BLAKE2b-256 34337f94f7a35aed07c87484436e9ba86c36b771d33f0e3bdc307ef3904d7abe

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: innertext-0.2.3-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 355.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.3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 09ba50a08a0e98598a5548b520436e233db0bab5bddb6fe7f0ea500e0b5a18ba
MD5 eb53a21b9353704abe52c790c6c5dc06
BLAKE2b-256 d9a9559485cbaffde46fc10e919a4144404bc66a204b3ad71eaab05ff77c39f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 084888927e95f43bb008a9ca781d477746b5d2b5fbdee5713f4b9de4b0142e2d
MD5 1ed829080d47e3e2499e463cb8680ef6
BLAKE2b-256 4259a76e967db85754ef7e9f73e360a57819e8e81fe8ec66ed3b077951de5131

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 bb23904b6ec73c1a18616811eebd11ea1192a700634680b295e36a87129e97bf
MD5 8b0c95acd4cbf7f128e8391b8358cddf
BLAKE2b-256 2b38a933117015ed468a4e56382ecea137b547cd3b09bd8c5b6a0fece1c7ec14

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c18531060b96c20cefa64ab90cd8755eee9ef7983a31204c614e4ecfc54c2967
MD5 bd10f3947aeb295d09284906478af42c
BLAKE2b-256 2376aa0d708d998d511ba4e9b1458335c3ec681a38ab46abb5c07844ca192f73

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 89dc0665c41de14c7d9b90e364dc36a47216e7d8f31ff2c2c6bcb455a3c108d6
MD5 7218a17dba1f1b15d56b0865121ba135
BLAKE2b-256 8bb474fa4fd291baf9271fa94d6cdec3f9fb5adbbb609c87f237c7d62ab38175

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 096c4cda9f33c19b87cf8ad9b944e5c33439994d7b25364f6a0fba2424f63c7a
MD5 dd7b5e394cc768a323c767b2570de37b
BLAKE2b-256 3f5866c2adda99f242ed5c6cf3a1dd6f01f694feb381ffe7c868baa2346ace7c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.3-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b2bcfbf1ef55f0646448817bebb670edfdd79e6b213c175320a8a10cb7d001c2
MD5 23c8de14681f727f198755ec14149152
BLAKE2b-256 4ab93cd4e90cf5ec06e132df0df20b496919970734b930265a31e83a77c3fb4f

See more details on using hashes here.

Provenance

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