Skip to main content

HTML to AST with positions

Project description

htmst

PyPI - Python Versions PyPI - Version GitHub

htmst is a python library for parsing html into AST with positions.

Installation

uv add htmst

or

pip install htmst

Usage

from htmst import HtmlAst

html = """<span foo="bar">hi</span>"""
ast = HtmlAst(html)

print(ast.root.children[0].tag) # span

print(ast.root.children[0].start.row) # 0
print(ast.root.children[0].start.col) # 0

print(ast.root.children[0].end.row) # 0
print(ast.root.children[0].end.col) # 25

print(ast.root.children[0].attrs[0].name) # foo
print(ast.root.children[0].attrs[0].value) # bar

print(ast.root.children[0].attrs[0].start.row) # 0
print(ast.root.children[0].attrs[0].start.col) # 6

print(ast.root.children[0].attrs[0].end.row) # 0
print(ast.root.children[0].attrs[0].end.col) # 15

Nodes

  • TextNode: represents texts
  • AttrNode: represents attributes
  • DoubleNode: represents double tags
  • SingleNode: represents single tags
  • CommentNode: represents comments
  • DoctypeNode: represents doctypes

Each node has a start and end position.

Contributing

Contributions are welcome! Please read the contributing guidelines for more information.

License

This project is licensed under the MIT License.

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

htmst-1.0a1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

htmst-1.0a1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file htmst-1.0a1.tar.gz.

File metadata

  • Download URL: htmst-1.0a1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for htmst-1.0a1.tar.gz
Algorithm Hash digest
SHA256 fb4b8c4b5575e6b234d058d5f3420b9822258965b72bcd07adf270cde0a2651c
MD5 f2fefae2e0c6d8ef612a0404bd612483
BLAKE2b-256 1a65b86a505264baab111c9c9243e90671d43e7a01196e65a72a6b63bd3cef61

See more details on using hashes here.

File details

Details for the file htmst-1.0a1-py3-none-any.whl.

File metadata

  • Download URL: htmst-1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for htmst-1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bdbae05ac0cbbcd8856e52b895c7b0a1f992ab2b19dc360d31f716727649d43
MD5 523a49004de048241cbb94d52cb3c5b3
BLAKE2b-256 b38960ffb33d75c12bbec72b6a81acb530009924e573c9f032771fa069ea319a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page