html-template-parser


Namehtml-template-parser JSON
Version 1.7.0 PyPI version JSON
download
home_pagehttps://github.com/Riverside-Healthcare/html-void-elements
SummaryA parser for HTML templates.
upload_time2022-12-07 16:34:06
maintainer
docs_urlNone
authorChristopher Pickering
requires_python>=3.7,<4.0
licenseGPL-3.0-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">HTML Template Parser</h1>

<h4 align="center">Modified version of Python's HTMLParser for HTML template parsing</h4>

<p align="center">
  <a href="https://codecov.io/gh/Riverside-Healthcare/html-template-parser">
    <img src="https://codecov.io/gh/Riverside-Healthcare/html-template-parser/branch/master/graph/badge.svg?token=Chqq9Mai1h"/>
  </a>
  <a href="https://github.com/Riverside-Healthcare/html-template-parser/actions/workflows/test.yml">
    <img src="https://github.com/Riverside-Healthcare/html-template-parser/actions/workflows/test.yml/badge.svg" alt="Test Status">
  </a>
  <a href="https://www.codacy.com/gh/Riverside-Healthcare/html-template-parser/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Riverside-Healthcare/html-template-parser&amp;utm_campaign=Badge_Grade">
    <img src="https://app.codacy.com/project/badge/Grade/43736e5b780a49d88d8ce588f5cfb9bc"/>
  </a>
  <a href="https://pepy.tech/project/html-template-parser">
    <img src="https://static.pepy.tech/badge/html-template-parser" alt="Downloads">
  </a>
  <a href="https://pypi.org/project/html-template-parser/">
    <img src="https://badgen.net/pypi/v/html-template-parser" alt="Pypi Version">
  </a>
</p>

## 🤔 For What?

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

## 💾 Install

```sh
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:

```py
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Riverside-Healthcare/html-void-elements",
    "name": "html-template-parser",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Christopher Pickering",
    "author_email": "cpickering@rhc.net",
    "download_url": "https://files.pythonhosted.org/packages/1d/68/5c61646b039489c48223f1b4f6132f1a0cc9fb3ba4ece1b6c57ebaa22dc8/html_template_parser-1.7.0.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">HTML Template Parser</h1>\n\n<h4 align=\"center\">Modified version of Python's HTMLParser for HTML template parsing</h4>\n\n<p align=\"center\">\n  <a href=\"https://codecov.io/gh/Riverside-Healthcare/html-template-parser\">\n    <img src=\"https://codecov.io/gh/Riverside-Healthcare/html-template-parser/branch/master/graph/badge.svg?token=Chqq9Mai1h\"/>\n  </a>\n  <a href=\"https://github.com/Riverside-Healthcare/html-template-parser/actions/workflows/test.yml\">\n    <img src=\"https://github.com/Riverside-Healthcare/html-template-parser/actions/workflows/test.yml/badge.svg\" alt=\"Test Status\">\n  </a>\n  <a href=\"https://www.codacy.com/gh/Riverside-Healthcare/html-template-parser/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Riverside-Healthcare/html-template-parser&amp;utm_campaign=Badge_Grade\">\n    <img src=\"https://app.codacy.com/project/badge/Grade/43736e5b780a49d88d8ce588f5cfb9bc\"/>\n  </a>\n  <a href=\"https://pepy.tech/project/html-template-parser\">\n    <img src=\"https://static.pepy.tech/badge/html-template-parser\" alt=\"Downloads\">\n  </a>\n  <a href=\"https://pypi.org/project/html-template-parser/\">\n    <img src=\"https://badgen.net/pypi/v/html-template-parser\" alt=\"Pypi Version\">\n  </a>\n</p>\n\n## \ud83e\udd14 For What?\n\nThe is an HTML template parser. It is a modified version of Python's HTMLParse library, expanded to handle template tags.\n\n## \ud83d\udcbe Install\n\n```sh\npip install html-template-parser\n\n# or\n\npoetry add html-template-parser\n```\n\n## \u2728 How to Use\n\nA basic usage example is remarkably similar to Python's HTMLParser:\n\n```py\nfrom HtmlTemplateParser import Htp\nfrom HtmlTemplateParser import AttributeParser\n\n\nclass MyAttributeParser(AttributeParser):\n    def handle_starttag_curly_perc(self, tag, attrs, props):\n        print(\"starttag_curly_perc\", tag, attrs, props)\n\n        # get the position of the element relative to the original html\n        print(self.getpos())\n\n        # get the original html text\n        print(self.get_element_text())\n\n    def handle_endtag_curly_perc(self, tag, attrs, props):\n        print(\"endtag_curly_perc\", tag, attrs, props)\n\n    def handle_value(self, value):\n        print(\"value\", value)\n\n\nclass MyHTMLParser(Htp):\n    def handle_starttag(self, tag, attrs):\n        print(\"Encountered a start tag:\", tag)\n        print(self.getpos())\n\n        MyAttributeParser(attrs).parse()\n\n    def handle_endtag(self, tag):\n        print(\"Encountered an end tag :\", tag)\n\n    def handle_data(self, data):\n        print(\"Encountered some data  :\", data)\n\nparser = MyHTMLParser()\nparser.feed('<html><head><title>Test</title></head>'\n            '<body {% if this %}ok{% endif %}><h1>Parse me!</h1></body></html>')\n\n```\n\n## \ud83c\udff7 Function Naming Conventions\n\n### Comments\n\n- comment `<!-- -->`\n- comment_curly_hash `{# data #}`\n- comment_curly_two_exlaim `{{! data }}`\n- starttag_comment_curly_perc `{% comment \"attrs\" %}`\n- endtag_comment_curly_perc `{% endcomment %}`\n- comment_at_star `@* data *@`\n\n### Structure\n\n- startendtag `< />`\n- starttag `<`\n- starttag_curly_perc `{% ... %}`\n- starttag_curly_two_hash `{{#...}}`\n- starttag_curly_four `{{{{...}}}}`\n\n- endtag `<.../>`\n- endtag_curly_perc `{% end.. %}`\n- endtag_curly_two_slash `{{/...}}`\n- endtag_curly_four_slash ` {{{{/...}}}}`\n\n### Data and Other\n\n- unknown_decl\n- charref\n- entityref\n- data\n- curly_two `{{ ... }}`\n- slash_curly_two `\\{{ ... }}`\n- curly_three `{{{ ... }}}`\n- decl\n- pi\n\n\n### Modifiers\n\nModifiers such as `~`, `!--`, `-`, `+`, `>` will show up as props on the tags.\n\n### Attributes\n\nAttributes are passed from the Htp as a complete string to be parsed with the attribute parser.\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "A parser for HTML templates.",
    "version": "1.7.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3f60f0d8675a19ec526304db52e3a94a",
                "sha256": "728d7838d780507b8ab736239a3b8056f225444f44e182dc50e617e4729eaa55"
            },
            "downloads": -1,
            "filename": "html_template_parser-1.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f60f0d8675a19ec526304db52e3a94a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 27351,
            "upload_time": "2022-12-07T16:34:04",
            "upload_time_iso_8601": "2022-12-07T16:34:04.699141Z",
            "url": "https://files.pythonhosted.org/packages/d4/fa/be98fae39dcb464fbaf6ac40bc3eb6767463904dc2dc6270df77e1cd4be4/html_template_parser-1.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "6c1f3c68ea0822419c8a7eb1cefdd520",
                "sha256": "1dc91a1ecd2e4b7ad788722dced2a4d7896c74f58802b8acbe2cf7c4c0e1e4ca"
            },
            "downloads": -1,
            "filename": "html_template_parser-1.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6c1f3c68ea0822419c8a7eb1cefdd520",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 26649,
            "upload_time": "2022-12-07T16:34:06",
            "upload_time_iso_8601": "2022-12-07T16:34:06.244024Z",
            "url": "https://files.pythonhosted.org/packages/1d/68/5c61646b039489c48223f1b4f6132f1a0cc9fb3ba4ece1b6c57ebaa22dc8/html_template_parser-1.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-07 16:34:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Riverside-Healthcare",
    "github_project": "html-void-elements",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "html-template-parser"
}
        
Elapsed time: 0.07732s