HTML Template Parser
Modified version of Python's HTMLParser for HTML template parsing
🤔 For What?
The is an HTML template parser. It is a modified version of Python's HTMLParse library, expanded to handle template tags.
💾 Install
pip install html-template-parser
# or
poetry add html-template-parser
✨ How to Use
A basic usage example is remarkably similar to Python's HTMLParser:
from HtmlTemplateParser import Htp
from HtmlTemplateParser import AttributeParser
class MyAttributeParser(AttributeParser):
def handle_starttag_curly_perc(self, tag, attrs, props):
print("starttag_curly_perc", tag, attrs, props)
# get the position of the element relative to the original html
print(self.getpos())
# get the original html text
print(self.get_element_text())
def handle_endtag_curly_perc(self, tag, attrs, props):
print("endtag_curly_perc", tag, attrs, props)
def handle_value(self, value):
print("value", value)
class MyHTMLParser(Htp):
def handle_starttag(self, tag, attrs):
print("Encountered a start tag:", tag)
print(self.getpos())
MyAttributeParser(attrs).parse()
def handle_endtag(self, tag):
print("Encountered an end tag :", tag)
def handle_data(self, data):
print("Encountered some data :", data)
parser = MyHTMLParser()
parser.feed('<html><head><title>Test</title></head>'
'<body {% if this %}ok{% endif %}><h1>Parse me!</h1></body></html>')
🏷 Function Naming Conventions
Comments
- comment
<!-- --> - comment_curly_hash
{# data #} - comment_curly_two_exlaim
{{! data }} - starttag_comment_curly_perc
{% comment "attrs" %} - endtag_comment_curly_perc
{% endcomment %} - comment_at_star
@* data *@
Structure
-
startendtag
< /> -
starttag
< -
starttag_curly_perc
{% ... %} -
starttag_curly_two_hash
{{#...}} -
starttag_curly_four
{{{{...}}}} -
endtag
<.../> -
endtag_curly_perc
{% end.. %} -
endtag_curly_two_slash
{{/...}} -
endtag_curly_four_slash
{{{{/...}}}}
Data and Other
- unknown_decl
- charref
- entityref
- data
- curly_two
{{ ... }} - slash_curly_two
\{{ ... }} - curly_three
{{{ ... }}} - decl
- pi
Modifiers
Modifiers such as ~, !--, -, +, > will show up as props on the tags.
Attributes
Attributes are passed from the Htp as a complete string to be parsed with the attribute parser.
Metadata
Release files for html-template-parser 1.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| html_template_parser-1.7.0.tar.gz | 26.6 kB | Without provenance | Details for html_template_parser-1.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| html_template_parser-1.7.0-py3-none-any.whl | Python 3 | none | any | Details for html_template_parser-1.7.0-py3-none-any.whl |
Total release size: 54.0 kB
Release files / html_template_parser-1.7.0.tar.gz
| Download URL | html_template_parser-1.7.0.tar.gz |
|---|---|
| Size | 26.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dc91a1ecd2e4b7ad788722dced2a4d7896c74f58802b8acbe2cf7c4c0e1e4ca
|
|
BLAKE2b-256 checksum How to use checksums |
1d685c61646b039489c48223f1b4f6132f1a0cc9fb3ba4ece1b6c57ebaa22dc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1024-azure
|
Release files / html_template_parser-1.7.0-py3-none-any.whl
| Download URL | html_template_parser-1.7.0-py3-none-any.whl |
|---|---|
| Size | 27.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
728d7838d780507b8ab736239a3b8056f225444f44e182dc50e617e4729eaa55
|
|
BLAKE2b-256 checksum How to use checksums |
d4fabe98fae39dcb464fbaf6ac40bc3eb6767463904dc2dc6270df77e1cd4be4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1024-azure
|
Security for html-template-parser 1.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.