markupify


Namemarkupify JSON
Version 1.1.0 PyPI version JSON
download
home_page
SummaryA simple HTML5 generator based-on Python's OOP
upload_time2024-03-02 13:10:30
maintainer
docs_urlNone
authorChogirmaliYigit
requires_python>=3.9,<4.0
licenseMIT
keywords html python html-generator markup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # HTML5 generator from your Python code

![GitHub Release](https://img.shields.io/github/v/release/old-juniors/markupify?include_prereleases&display_name=release&label=Release)
![GitHub issue custom search in repo](https://img.shields.io/github/issues-search/old-juniors/markupify?query=is%3Aopen&label=Issues)
![PyPI - Downloads](https://img.shields.io/pypi/dm/markupify?label=Downloads)

# Features

- HTML5 tag creation with classes such as `A()` for `<a></a>`, `Hr()` for `<hr />`, etc.
- Pretty printing the html content with `pretty()` method.
- Create multiple html pages using `HTMLPage` class.
- Custom tag creation by inheriting `Element` class which declared at `markupify.tags`


# Goals

- Generate `*.html` files after creating html content.
- Create an `CSSPage` class to create some css contents.
- Generate `*.css` files.
- Show tag structure like `<body> -> <div> -> h1 -> "This is heading one!"` or something.
- Create a page object with specific head and body.


# Installation

```shell
pip install markupify
```


# Usage

```python
from markupify.page import HTMLPage
from markupify.tags import Meta, Link, Title, Div, H, Comment

# Alternatively, you can import these classes from markupify directly:
# from markupify import HTMLPage, Meta, Link, Title, Div, H, Comment


page = HTMLPage()

meta = Meta(charset="UTF-8")
link = Link(href="css/styles.css", rel="stylesheet")
title = Title("My first website")
div = Div(
    tag_content=H(
        tag_content="Greetings text"
    )
)
comment = Comment("This is a comment")

page.add_tag_to_head(meta, link, title)
page.add_tag_to_body(comment, div)

print(page)
```

Output:

```html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><link href="css/styles.css" rel="stylesheet" /><title>My first website</title></head><body><!-- This is a comment --><div><h1>Greetings text</h1></div></body></html>
```

To prettify that, use the `pretty()` method of the `page` object:

```python
print(page.pretty())
```

Output:

```html
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8"/>
  <link href="css/styles.css" rel="stylesheet"/>
  <title>
   My first website
  </title>
 </head>
 <body>
  <!-- This is a comment -->
  <div>
   <h1>
    Greetings text
   </h1>
  </div>
 </body>
</html>
```


# Customizing

> Devs! Maybe I forgot to create some tags you need. Feel free to create them yourself by inheriting from the `Element` class.

For example, create a double tag:

```python
from typing import Optional, Union
from markupify.tags import Element


class MyCustomTag(Element):
    def __init__(self, tag_content: Optional[Union[str, Element]], **props):
        """
        A tag class to represent <my_tag> tag.
        """
        super().__init__(tag_name="my_tag", tag_content=tag_content, **props)


my_tag = MyCustomTag("This my custom tag! 🥳")
print(my_tag)
```

Output:

```html
<my_tag>This my custom tag! 🥳</my_tag>
```

Add `class` property with `add_properties`

```python
my_tag.add_properties(_class="custom my-tag")
print(my_tag)
```

Output:

```html
<my_tag class="custom my-tag">This my custom tag! 🥳</my_tag>
```

> [!NOTE]
> Some keywords like `class` are built-in names in Python. So you need to use them with underscore before them.
> For example, instead of `class`, write `_class` and everything will be fine.


Create a single tag:

```python
from markupify.tags import Element


class Vl(Element):
    def __init__(self, **props):
        """
        A tag class to represent <vl> (Vertical Line) tag.
        """
        super().__init__(tag_name="vl", has_end_tag=False, **props)


vl = Vl()
print(vl)
```

Output:

```html
<vl />
```

Add `width` property with `add_property`

```python
vl.add_property("width", "5px")
print(vl)
```

Output:

```html
<vl width="5px" />
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "markupify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "html,python,html-generator,markup",
    "author": "ChogirmaliYigit",
    "author_email": "chogirmali.yigit@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/89/7f/f71f508d658464a96309b5ad593344aad36fd62498b4a68a25db46a37377/markupify-1.1.0.tar.gz",
    "platform": null,
    "description": "# HTML5 generator from your Python code\n\n![GitHub Release](https://img.shields.io/github/v/release/old-juniors/markupify?include_prereleases&display_name=release&label=Release)\n![GitHub issue custom search in repo](https://img.shields.io/github/issues-search/old-juniors/markupify?query=is%3Aopen&label=Issues)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/markupify?label=Downloads)\n\n# Features\n\n- HTML5 tag creation with classes such as `A()` for `<a></a>`, `Hr()` for `<hr />`, etc.\n- Pretty printing the html content with `pretty()` method.\n- Create multiple html pages using `HTMLPage` class.\n- Custom tag creation by inheriting `Element` class which declared at `markupify.tags`\n\n\n# Goals\n\n- Generate `*.html` files after creating html content.\n- Create an `CSSPage` class to create some css contents.\n- Generate `*.css` files.\n- Show tag structure like `<body> -> <div> -> h1 -> \"This is heading one!\"` or something.\n- Create a page object with specific head and body.\n\n\n# Installation\n\n```shell\npip install markupify\n```\n\n\n# Usage\n\n```python\nfrom markupify.page import HTMLPage\nfrom markupify.tags import Meta, Link, Title, Div, H, Comment\n\n# Alternatively, you can import these classes from markupify directly:\n# from markupify import HTMLPage, Meta, Link, Title, Div, H, Comment\n\n\npage = HTMLPage()\n\nmeta = Meta(charset=\"UTF-8\")\nlink = Link(href=\"css/styles.css\", rel=\"stylesheet\")\ntitle = Title(\"My first website\")\ndiv = Div(\n    tag_content=H(\n        tag_content=\"Greetings text\"\n    )\n)\ncomment = Comment(\"This is a comment\")\n\npage.add_tag_to_head(meta, link, title)\npage.add_tag_to_body(comment, div)\n\nprint(page)\n```\n\nOutput:\n\n```html\n<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\" /><link href=\"css/styles.css\" rel=\"stylesheet\" /><title>My first website</title></head><body><!-- This is a comment --><div><h1>Greetings text</h1></div></body></html>\n```\n\nTo prettify that, use the `pretty()` method of the `page` object:\n\n```python\nprint(page.pretty())\n```\n\nOutput:\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n  <meta charset=\"utf-8\"/>\n  <link href=\"css/styles.css\" rel=\"stylesheet\"/>\n  <title>\n   My first website\n  </title>\n </head>\n <body>\n  <!-- This is a comment -->\n  <div>\n   <h1>\n    Greetings text\n   </h1>\n  </div>\n </body>\n</html>\n```\n\n\n# Customizing\n\n> Devs! Maybe I forgot to create some tags you need. Feel free to create them yourself by inheriting from the `Element` class.\n\nFor example, create a double tag:\n\n```python\nfrom typing import Optional, Union\nfrom markupify.tags import Element\n\n\nclass MyCustomTag(Element):\n    def __init__(self, tag_content: Optional[Union[str, Element]], **props):\n        \"\"\"\n        A tag class to represent <my_tag> tag.\n        \"\"\"\n        super().__init__(tag_name=\"my_tag\", tag_content=tag_content, **props)\n\n\nmy_tag = MyCustomTag(\"This my custom tag! \ud83e\udd73\")\nprint(my_tag)\n```\n\nOutput:\n\n```html\n<my_tag>This my custom tag! \ud83e\udd73</my_tag>\n```\n\nAdd `class` property with `add_properties`\n\n```python\nmy_tag.add_properties(_class=\"custom my-tag\")\nprint(my_tag)\n```\n\nOutput:\n\n```html\n<my_tag class=\"custom my-tag\">This my custom tag! \ud83e\udd73</my_tag>\n```\n\n> [!NOTE]\n> Some keywords like `class` are built-in names in Python. So you need to use them with underscore before them.\n> For example, instead of `class`, write `_class` and everything will be fine.\n\n\nCreate a single tag:\n\n```python\nfrom markupify.tags import Element\n\n\nclass Vl(Element):\n    def __init__(self, **props):\n        \"\"\"\n        A tag class to represent <vl> (Vertical Line) tag.\n        \"\"\"\n        super().__init__(tag_name=\"vl\", has_end_tag=False, **props)\n\n\nvl = Vl()\nprint(vl)\n```\n\nOutput:\n\n```html\n<vl />\n```\n\nAdd `width` property with `add_property`\n\n```python\nvl.add_property(\"width\", \"5px\")\nprint(vl)\n```\n\nOutput:\n\n```html\n<vl width=\"5px\" />\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple HTML5 generator based-on Python's OOP",
    "version": "1.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/old-juniors/markupify/issues",
        "Source": "https://github.com/old-juniors/markupify"
    },
    "split_keywords": [
        "html",
        "python",
        "html-generator",
        "markup"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "16f40b0d6f8a9dbb9fce700e25371277f1ba4bfa9d5b35e379961a4f6766b2ab",
                "md5": "6982b6b235e8fd5e979fa66bfa9ca6a5",
                "sha256": "5063e2b3195ded7d1e7029b7777c585f93dca500fbe7367ef28da27e6696e731"
            },
            "downloads": -1,
            "filename": "markupify-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6982b6b235e8fd5e979fa66bfa9ca6a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 10052,
            "upload_time": "2024-03-02T13:10:28",
            "upload_time_iso_8601": "2024-03-02T13:10:28.673822Z",
            "url": "https://files.pythonhosted.org/packages/16/f4/0b0d6f8a9dbb9fce700e25371277f1ba4bfa9d5b35e379961a4f6766b2ab/markupify-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "897ff71f508d658464a96309b5ad593344aad36fd62498b4a68a25db46a37377",
                "md5": "bc536687b5e4b7a39da89d9db2d44ecb",
                "sha256": "4a19bf4a76b15970e751a216420689b3546643b199582297268e77d7c5814688"
            },
            "downloads": -1,
            "filename": "markupify-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bc536687b5e4b7a39da89d9db2d44ecb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 10701,
            "upload_time": "2024-03-02T13:10:30",
            "upload_time_iso_8601": "2024-03-02T13:10:30.091462Z",
            "url": "https://files.pythonhosted.org/packages/89/7f/f71f508d658464a96309b5ad593344aad36fd62498b4a68a25db46a37377/markupify-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-02 13:10:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "old-juniors",
    "github_project": "markupify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "markupify"
}
        
Elapsed time: 0.19368s