Skip to main content

A parser for HTML templates.

Project description

HTML Template Parser

Modified version of Python's HTMLParser for HTML template parsing

Test Status Downloads Pypi Version

🤔 For What?

The is an HTML template parser. It is a modified version of Python's HTMLParse library, expanded to handle template tags.

Currently Supported

  • Comments
  • Template tags (if/for/...)

💾 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

class MyHTMLParser(Htp):
    def handle_starttag(self, tag, attrs):
        print("Encountered a start tag:", tag)

    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><h1>Parse me!</h1></body></html>')

🏷 Function Naming Conventions

Comments

  • comment <!-- -->
  • comment_curly_hash {# data #}
  • comment_curly_exlaim {{! data }}
  • comment_curly_exlaim_dash {{!-- data }}
  • comment_curly_perc {% comment "attrs" %}
  • comment_curly_perc_closedata {% endcomment %}
  • comment_at_star @* data *@

Structure

  • startendtag < />

  • starttag <

  • starttag_curly_perc {% ... %}

  • starttag_curly_hash {{#...}}

  • starttag_curly_four {{{{...}}}}

  • endtag <.../>

  • endtag_curly_perc {% end.. %}

  • endtag_curly_hash {{/...}}

  • endtag_curly_four {{{{/...}}}}

Data and Other

  • unknown_decl
  • charref
  • entityref
  • data
  • curly {{ ... }}
  • decl
  • pi

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

html-template-parser-1.1.0a2.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

html_template_parser-1.1.0a2-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file html-template-parser-1.1.0a2.tar.gz.

File metadata

  • Download URL: html-template-parser-1.1.0a2.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.13.0-1022-azure

File hashes

Hashes for html-template-parser-1.1.0a2.tar.gz
Algorithm Hash digest
SHA256 eb2a47795a721948c8e40eea6d69dda320f5699f70cbb5fbad1e80b13f078005
MD5 cdcf0afbfecf9c74635230e834f4ba2d
BLAKE2b-256 456702eb0f3f3904b52ede880f7f88d60c8302eb450a9deb0a8db5eb39f82e23

See more details on using hashes here.

File details

Details for the file html_template_parser-1.1.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for html_template_parser-1.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 9fe20a61651bf4fe3fd0e5477d36e7c2b1255503d9646b297a09bb59891f72f8
MD5 b46da9b50937ffa03c30f996c478d62d
BLAKE2b-256 8c01937a18e4ca512098d3ade32571c2b3e3a139d38902444ae2fb64d16746bf

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