a HTML/SVG/MathML to htpy converter
Project description
any2htpy
any2htpy is a principled converter for HTML/SVG and MathML to htpy inspired by html2htpy, the built-in tool for htpy.
Unlike html2htpy any2htpy uses a feature-complete HTML parser called justhtml.
Features
- adheres to SVG and MathML
- preserves case-sensitive attributes such as SVG
viewBox - preserves SVG path commands and other non-class attribute values with spaces
- tries best-effort DOM for malformed HTML
- properly preserves whitespace for respective tags
- only supports
class_syntax to allow stable parsing by TailwindCSS
A few things any2htpy needs to fix to be better suited for :
- auto-detect if code is just a fragment or a whole document
- boolean attributes are not yet detected (use
dictsyntax) - special attribute detection for AlpineJS or HTMX
- specifically passing HTMX events
:or AlpineJS@
- specifically passing HTMX events
Things that any2htpy will not do:
- add the
import htpycode - add the shorthand syntax of
htpy
Usage
usage: any2htpy [-h] [--input INPUT] [--stdin] [--debug] [--prefix PREFIX] [--fragment]
options:
-h, --help show this help message and exit
--input INPUT input as string or file
--stdin use stdin as input
--debug generate debug output
--prefix PREFIX use a prefix for the tags
--fragment use htpy fragment
input through stdin
[me@machine ] echo "<p>Hello World</p>" | uv run any2htpy --stdin --prefix htpy
htpy.p["Hello World"]
Disclaimer
As an AI-skeptic, specifically regarding code and software in general, justhtml is not exactly the obvious choice or more precisely the exact opposite one. However, the heavy test-rig with thousands of tests and the use as a parser without introducing it as a dependency in the resulting code make it a better choice than any other native Python parser library.
License
Licensed under the terms of the MIT License
Copyright
Copyright (c) 2026 Hartmut Seichter
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file any2htpy-0.1.3.tar.gz.
File metadata
- Download URL: any2htpy-0.1.3.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0ddbd256466c4e300a63e03359508f76cb5cfd9be9dba2166fef5aeece49b72
|
|
| MD5 |
d43669d2ea0aafc8d0ac38526b15a5ae
|
|
| BLAKE2b-256 |
32e26539cd43414ad82b2015f9263c9f2b7e97ca7212708b8fa401c75e8a0fb1
|
File details
Details for the file any2htpy-0.1.3-py3-none-any.whl.
File metadata
- Download URL: any2htpy-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0c2736d05ac93590a278e972cc0a0450d08a4f0226cbac99b8f8b7b4f2b99a5
|
|
| MD5 |
febef4af95c8331e54795c43db77481b
|
|
| BLAKE2b-256 |
48b194f7afaf45d6a45e462d027577d6d75f4cbbd22053cb0d5c2405df09df54
|