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

  • DoubleTagNode: represents double tags
  • SingleTagNode: represents single tags
  • AttrNode: represents attributes
  • TextNode: represents texts
  • 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.0a9.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htmst-1.0a9-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: htmst-1.0a9.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for htmst-1.0a9.tar.gz
Algorithm Hash digest
SHA256 a3c86f722b0e54969298e5b575897c616878075d0e22a1adf519a0769aedb1c2
MD5 a802d520f6d17a6f69c5132c9e2abf75
BLAKE2b-256 d7d9bb3759c655792b62e834cfed207f301cf1f0886ac0f55099ae72f6e7588c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: htmst-1.0a9-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for htmst-1.0a9-py3-none-any.whl
Algorithm Hash digest
SHA256 6f2e58c0b1379ede495de1f3e3dc3c197a68af35b3f7dd9d3047ab46f181897d
MD5 ec9d2cefb8bb73e5a645cbd6e2323f34
BLAKE2b-256 10a7170fff1df013443f4376139943f88539d106eaa05716fbbb5b9dc6c0a1cd

See more details on using hashes here.

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