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.5.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.5-cp37-abi3-win_amd64.whl (356.7 kB view details)

Uploaded CPython 3.7+Windows x86-64

innertext-0.2.5-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.5-cp37-abi3-musllinux_1_1_aarch64.whl (703.8 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.1+ ARM64

innertext-0.2.5-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.5-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.5-cp37-abi3-macosx_11_0_arm64.whl (443.9 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

innertext-0.2.5-cp37-abi3-macosx_10_12_x86_64.whl (449.5 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: innertext-0.2.5.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.5.tar.gz
Algorithm Hash digest
SHA256 4758a76bbacff6b814f0c0f323bda8597389af098c5371f70b5da4ddde856645
MD5 672b83ed59e08b7b98de1e89d811344c
BLAKE2b-256 0c6dd917d53ce9c1b3a0a7107c8916713be36af0ef8f1438c1474f211d2443df

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: innertext-0.2.5-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.5-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 91c329bb243658e1aac0ff0844e536cb9884670d81b5e0ab859c6dca213caa55
MD5 af0dcb6c6a86e264cfbc25bd61f2e03c
BLAKE2b-256 ec2ff912f70505d306c1b3c8091c7aac375b03b65143974241db399c29c78932

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 acd73d0185796253a913afb650c1617f281ea3ef5545866f27c118eda8f0fc21
MD5 3ce0ef8868849144ef00af0fb3a44fc7
BLAKE2b-256 c470754ed8e46c3c451f780dacd3578075af2a31ef5d347daf88b65d9557fcf0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 6db7adf28d2c547b8aae9a89acd494ef0ef0386ec467a0d4422bd82e4254463c
MD5 777cd0410fd72a23b6fa91621a1913af
BLAKE2b-256 ce01ea957a97fa4ae1e4f82a5db083debe2d11b95237462c7c01b0babac9f978

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9cf691a64244dc1caac7211204bfdc086e63467b2170bcc79ab123edcc7dbd72
MD5 491656ad0c299eeec36cf9cdbbd1dcb5
BLAKE2b-256 2c54320d2c54af180247d14bce1aad82d80331692d1be06ee19fbec82a9393fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 643e0a320e99046e796dce40c9b7bce1feb554b9af71cb46139336d0af62506b
MD5 51d780a086a8f0570b90fd58a1bf5cce
BLAKE2b-256 6c196f1337dd6bccc3822838241029f7f0ef74e86c897a570cbd998280af4b8c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95c8d9ca54e9640aef1119c8388778be33c0e25a64f93c34c46c3f7851c6d999
MD5 42a375eeef9456f51765c69979f92160
BLAKE2b-256 dc69fd66ecbb81eedd56471d78dbc9772e89c8b424776da3eac36d4d0ff293d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for innertext-0.2.5-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 08949d1ffd9971a487da0855751ea49db04473dae5d4117ab9de4ed4ff8a1e66
MD5 0598b85b1514b187e301a7dd841acaee
BLAKE2b-256 0a9afd6d36b16038c8d01aebe0fb209c8b95f0e7955109a86bf70ddcee4f95aa

See more details on using hashes here.

Provenance

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