### Brython Integration for Client-Side Python Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Illustrates how to integrate Brython for running Python code directly in the browser. This example creates a simple interactive application with a button that triggers client-side Python execution. ```python from html_codegen import html, head, body, title, div, button, p, h1, pyscript with html(use_brython=True) as doc: with head(): title("Brython приложение") with body(): h1().text("Интерактивное приложение") with div(attrs={"id": "app"}): p().text("Нажмите кнопку") button(attrs={"id": "btn"}).text("Кликни меня") p(attrs={"id": "result"}) pyscript("web.scripts.py.app") # Python код выполнится в браузере doc.save("brython_app.html") ``` -------------------------------- ### Install html_codegen Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Installs the html_codegen library using pip from a Git repository. This is the primary method for adding the library to your Python environment. ```bash pip install git+https://gitlab.com/html_codegen/html_codegen.git ``` -------------------------------- ### Define and Use Custom HTML Tags Source: https://context7.com/html_codegen/html_codegen/llms.txt Illustrates how to create custom HTML tags by inheriting from Tag or SingleTag. It shows examples of custom paired tags, self-closing tags, and tags that only accept text content, along with their usage in document generation. ```python from html_codegen import html, body, p from html_codegen.tags.base_ import Tag, SingleTag, OnlyTextTagMixin # Custom paired tag class custom_card(Tag): """A custom card component.""" pass # Custom self-closing tag class custom_icon(SingleTag): """A custom icon element.""" pass # Custom tag that only accepts text content class custom_label(OnlyTextTagMixin, Tag): """A label that can only contain text.""" pass # Using custom tags with html() as doc: with body(): with custom_card(attrs={"class": "info-card", "data-type": "info"}): custom_icon(attrs={"name": "info", "size": "24"}) custom_label().text("Important Notice") p().text("This is a custom card component.") doc.save("custom.html") ``` -------------------------------- ### Structure Document Body with html_codegen Source: https://context7.com/html_codegen/html_codegen/llms.txt Demonstrates building the document's `` content using the `body` tag. This example includes common semantic elements like `header`, `nav`, `main`, and `footer`, along with nested lists and links. The `body` tag also enforces a single instance and automatically handles Brython initialization if enabled. ```python from html_codegen import html, head, body, title, header, main, footer, h1, p, nav, ul, li, a with html() as doc: with head(): title("Semantic Page") with body(): # Header section with header(): h1().text("Site Title") with nav(): with ul(): li().a(attrs={"href": "/"}).text("Home") li().a(attrs={"href": "/about"}).text("About") # Main content with main(): h1().text("Welcome") p().text("Main content goes here...") # Footer with footer(): p().text("Copyright 2024") doc.save("semantic.html") ``` -------------------------------- ### Handle HTML CodeGen Exceptions Source: https://context7.com/html_codegen/html_codegen/llms.txt Provides examples of common exceptions raised by the HTML CodeGen library, such as SingleTagNestingError, DuplicateTagError, and BrythonNotEnabledError. It demonstrates how to use try-except blocks to catch and handle these errors gracefully. ```python from html_codegen import html, head, body, img, pyscript from html_codegen.exceptions import ( SingleTagNestingError, DuplicateTagError, BrythonNotEnabledError, NodeAlreadyHasParentError ) # SingleTagNestingError - void elements cannot have children try: with html() as doc: with body(): with img(attrs={"src": "photo.jpg"}): # img is a SingleTag pass # This will raise SingleTagNestingError except SingleTagNestingError as e: print(f"Error: {e}") # Single tag "img" cannot have nested tags # DuplicateTagError - only one head/body per document try: with html() as doc: with head(): pass with head(): # Second head tag pass # Raises DuplicateTagError except DuplicateTagError as e: print(f"Error: {e}") # Tag "head" can only appear once inside an "html" tag # BrythonNotEnabledError - pyscript requires Brython try: with html() as doc: # Missing use_brython=True with body(): pyscript("module.name") # Raises BrythonNotEnabledError except BrythonNotEnabledError as e: print(f"Error: {e}") # Correct usage with Brython enabled with html(use_brython=True) as doc: with body(): pyscript("web.scripts.py.app") # Works correctly doc.save("app.html") ``` -------------------------------- ### Generate Self-Closing HTML Elements with SingleTag Class Source: https://context7.com/html_codegen/html_codegen/llms.txt Illustrates the use of the 'SingleTag' class for creating self-closing HTML elements like meta, link, img, br, hr, and input. These elements do not support child nodes. The example shows how to add attributes to these tags. ```python from html_codegen import html, head, body, meta, link, img, br, hr, input_ with html() as doc: with head(): # Meta tags are self-closing meta(attrs={"charset": "UTF-8"}) meta(attrs={"name": "description", "content": "Page description"}) link("styles.css", rel="stylesheet") with body(): # Image tag img(attrs={ "src": "photo.jpg", "alt": "A photograph", "width": "300", "height": "200" }) # Line break br() # Horizontal rule hr() # Form input (note underscore suffix to avoid Python keyword conflict) input_(attrs={"type": "text", "name": "username", "placeholder": "Enter name"}) doc.save("void-elements.html") ``` -------------------------------- ### Generate Basic HTML Document with Renderer Source: https://context7.com/html_codegen/html_codegen/llms.txt Demonstrates how to create a simple HTML document using the html() context manager and render it to a string with custom indentation using the Renderer class. It also shows how to save the document to a file. ```python from html_codegen import html, Renderer # Create a document with html() as doc: with doc.head(): doc.title("Render Example") with doc.body(): with doc.div(attrs={"class": "content"}): doc.p().text("Hello World") # Using Renderer directly for custom rendering renderer = Renderer(doc, html_indent=4) # Custom 4-space indent # Get complete HTML output full_html = renderer.render() print(full_html) # Or use the built-in save method (uses default 2-space indent) doc.save("output.html") ``` -------------------------------- ### Basic HTML Generation using Context Managers Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Demonstrates basic HTML document generation using context managers (`with` statements) for hierarchical structures. It creates a simple HTML page with a title, heading, and a paragraph within a div. ```python from html_codegen import html, head, body, title, div, p, h1 # Context manager style with html() as doc: with head(): title("My Page") with body(): h1().text("Hello, World!") with div(attrs={"class": "container"}): p().text("This is html_codegen example.") doc.save("index.html") ``` -------------------------------- ### Generate Basic HTML Document with html_codegen Source: https://context7.com/html_codegen/html_codegen/llms.txt Demonstrates creating a basic HTML document using the `html` root tag and context managers. It shows how to add head, body, and nested elements, and save the output to a file or retrieve it as a string. This is the primary method for document generation. ```python from html_codegen import html, head, body, title, div, p, h1 # Create a basic HTML document using context manager with html() as doc: with head(): title("My Page") with body(): h1().text("Hello, World!") with div(attrs={"class": "container"}): p().text("This is html_codegen example.") # Save the document to a file doc.save("index.html") # Or get the HTML string html_string = doc.get_html() # Output: # # # # My Page # # #

Hello, World!

#
#

This is html_codegen example.

#
# # ``` -------------------------------- ### HTML Generation using Method Chaining Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Illustrates HTML document generation using a method chaining style. This approach allows for a more concise way to build nested HTML elements by calling methods directly on parent elements. ```python from html_codegen import html doc = html() body = doc.body() body.div(attrs={"id": "header"}).h1().text("Header") body.div(attrs={"id": "content"}).p().text("Content") doc.save("page.html") ``` -------------------------------- ### Configure Document Head with html_codegen Source: https://context7.com/html_codegen/html_codegen/llms.txt Shows how to populate the document's `` section using the `head` tag. This includes setting character encoding, viewport meta tags, the page title, and linking external stylesheets or including inline styles. The `head` tag enforces a single instance per document. ```python from html_codegen import html, head, title, meta, link, style with html() as doc: with head(): # Set character encoding meta(attrs={"charset": "UTF-8"}) # Viewport for responsive design meta(attrs={"name": "viewport", "content": "width=device-width, initial-scale=1.0"}) # Page title title("My Application") # External stylesheet link("https://cdn.example.com/styles.css", rel="stylesheet") # Inline styles from file style("./styles/main.css") doc.save("page.html") ``` -------------------------------- ### HTML Form Generation Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Demonstrates the creation of HTML forms, including labels, input fields, and buttons. This snippet shows how to define form attributes like method and action, and associate labels with inputs. ```python from html_codegen import html, body, form, input_, label, button, h1 with html() as doc: with body(): h1().text("Форма регистрации") with form(attrs={"method": "POST", "action": "/register"}): label(attrs={"for": "name"}).text("Имя:") input_(attrs={"type": "text", "id": "name", "name": "name"}) button(attrs={"type": "submit"}).text("Отправить") doc.save("form.html") ``` -------------------------------- ### Initialize HTML Class Instance (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Initializes an instance of an HTML class, setting up the tag name and optional attributes for an HTML element. This is a fundamental step for creating any HTML structure. ```python class HTML: def __init__(self, tag_name: str, attrs: dict | None = None) -> None: pass ``` ```python class Tag(HTML): def __init__(self, attrs: dict | None = None) -> None: pass ``` ```python class SingleTag(Tag): def __init__(self, *args, **kwargs) -> None: pass ``` ```python class html(Tag): def __init__(self, use_brython: bool = False, **kwargs) -> None: pass ``` -------------------------------- ### Create HTML Document Structure with Context Manager (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Demonstrates using the HTMLNode context manager to create hierarchical HTML structures. The `with` statement automatically adds elements to the current node when the block is exited, simplifying code organization. This is useful for building complex HTML documents programmatically. ```Python from html_codegen.core import HTMLNode # Example usage of the context manager with HTMLNode() as root_node: with HTMLNode() as child_node_1: with HTMLNode() as child_node_2: pass # child_node_2 is added to child_node_1 # child_node_1 is added to root_node # The root_node now contains a nested structure of HTMLNodes. ``` -------------------------------- ### Generate HTML Structure with Tag Class Source: https://context7.com/html_codegen/html_codegen/llms.txt Demonstrates using the base 'Tag' class to create nested HTML structures with opening and closing tags. It shows how to add attributes and text content to elements. This is suitable for generating standard HTML documents. ```python from html_codegen import html, body, div, p, span, h1, h2, article, section with html() as doc: with body(): # Structural tags with div(attrs={"class": "wrapper", "id": "main"}): h1().text("Article Title") # Semantic section tags with article(): with section(attrs={"class": "intro"}): h2().text("Introduction") p().text("Opening paragraph...") with section(attrs={"class": "content"}): h2().text("Main Content") with p(): span().text("Regular text ") span(attrs={"class": "highlight"}).text("highlighted") span().text(" more text") doc.save("article.html") ``` -------------------------------- ### Semantic HTML Element Generation Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/README.md Shows how to generate semantic HTML5 elements like header, main, article, section, and footer using the library. This promotes better structure and accessibility for web pages. ```python from html_codegen import html, head, body, title, header, main, article, section, footer, h1, h2, p with html() as doc: with head(): title("Семантическая страница") with body(): with header(): h1().text("Заголовок сайта") with main(): with article(): h2().text("Статья") section().p().text("Содержание статьи") with footer(): p().text("© 2024") doc.save("semantic.html") ``` -------------------------------- ### Generate HTML Lists (ul, ol, li, dl) with Python Source: https://context7.com/html_codegen/html_codegen/llms.txt Demonstrates creating unordered lists, ordered lists with nested elements, and definition lists using the html-codegen library. It utilizes context managers for structuring the HTML document and its elements. ```python from html_codegen import html, body, h2, ul, ol, li, dl, dt, dd, text, strong with html() as doc: with body(): h2().text("Unordered List") with ul(attrs={"class": "feature-list"}): li().text("First item") li().text("Second item") with li(): text("Third item with ") strong().text("bold text") h2().text("Ordered List") with ol(attrs={"type": "1", "start": "1"}): li().text("Step one") li().text("Step two") # Nested list with li(): text("Step three:") with ul(): li().text("Sub-step A") li().text("Sub-step B") li().text("Step four") h2().text("Definition List") with dl(): dt().text("HTML") dd().text("HyperText Markup Language - the standard markup language for web pages") dt().text("CSS") dd().text("Cascading Style Sheets - stylesheet language for describing presentation") dt().text("Python") dd().text("A high-level, general-purpose programming language") doc.save("lists.html") ``` -------------------------------- ### Embed Media Elements (img, video, audio, canvas) with Python Source: https://context7.com/html_codegen/html_codegen/llms.txt Shows how to embed various media elements like images, video players, audio players, and canvas elements into an HTML document using the html-codegen library. Supports multiple sources for video and audio. ```python from html_codegen import html, body, h2, img, video, audio, source, canvas, text with html() as doc: with body(): h2().text("Image") img(attrs={ "src": "photo.jpg", "alt": "A scenic photograph", "width": "600", "height": "400", "loading": "lazy" }) h2().text("Video Player") with video(attrs={"controls": "", "width": "640", "height": "360", "poster": "poster.jpg"}): source(attrs={"src": "video.mp4", "type": "video/mp4"}) source(attrs={"src": "video.webm", "type": "video/webm"}) text("Your browser does not support the video tag.") h2().text("Audio Player") with audio(attrs={"controls": "", "preload": "metadata"}): source(attrs={"src": "audio.mp3", "type": "audio/mpeg"}) source(attrs={"src": "audio.ogg", "type": "audio/ogg"}) text("Your browser does not support the audio tag.") h2().text("Canvas") canvas(attrs= { "id": "myCanvas", "width": "400", "height": "300", "style": "border: 1px solid #000;" }) doc.save("media.html") ``` -------------------------------- ### Create HTML Summary Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'summary' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class summary(Tag): """Represents an HTML summary tag.""" pass ``` -------------------------------- ### Create HTML Elements Dynamically (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Shows how to create HTML elements using the HTML class, which extends HTMLNode. This class allows for dynamic creation of child elements through method calls using tag names. It also supports setting attributes during initialization. ```Python from html_codegen.core import HTML # Create an HTML element with attributes my_div = HTML('div', attrs={'class': 'container', 'id': 'main'}) # Dynamically create a child element (e.g., a paragraph) my_p = my_div('p') my_p.text = 'This is a paragraph.' # Dynamically create another child element (e.g., an image) my_img = my_div('img', attrs={'src': 'image.jpg', 'alt': 'An image'}) my_img.is_single = True # The my_div element now contains my_p and my_img as children. ``` -------------------------------- ### Embed Python Code for Browser Execution (PyScript) with html-codegen Source: https://context7.com/html_codegen/html_codegen/llms.txt Illustrates how to embed Python code that runs in the browser using Brython. This requires enabling Brython on the root `html` tag and using the `pyscript` tag to reference a Python module. ```python from html_codegen import html, head, body, title, div, button, p, h1, pyscript # Create document with Brython enabled with html(use_brython=True) as doc: with head(): title("Interactive Counter") with body(): h1().text("Brython Counter App") with div(attrs={"id": "app", "style": "text-align: center; padding: 20px;"}): p(attrs={"id": "counter", "style": "font-size: 48px; font-weight: bold;"}).text("0") with div(attrs={"style": "margin-top: 20px;"}): button(attrs={"id": "decrement", "style": "font-size: 24px; margin: 5px;"}).text("-") button(attrs={"id": "reset", "style": "font-size: 24px; margin: 5px;"}).text("Reset") button(attrs={"id": "increment", "style": "font-size: 24px; margin: 5px;"}).text("+") # This will embed Python code from web/scripts/py/counter.py # The code runs in the browser using Brython pyscript("web.scripts.py.counter") doc.save("counter_app.html") # Example counter.py content (web/scripts/py/counter.py): # count = 0 # def update(): document['counter'].text = str(count) # def inc(e): global count; count += 1; update() # def dec(e): global count; count -= 1; update() # def reset(e): global count; count = 0; update() # document['increment'].bind('click', inc) # document['decrement'].bind('click', dec) # document['reset'].bind('click', reset) ``` -------------------------------- ### Generate HTML Sample Output Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'samp' tag for sample output from a computer program. This class inherits from the base Tag class. ```python class html_codegen.tags.samp(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a samp tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### Create HTML Details Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'details' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class details(Tag): """Represents an HTML details tag.""" pass ``` -------------------------------- ### Generate HTML Form with Python Source: https://context7.com/html_codegen/html_codegen/llms.txt This snippet demonstrates how to create an HTML form using the html_codegen library in Python. It includes various form elements like labels, inputs, textareas, selects, and buttons, along with standard form attributes. The generated HTML is saved to 'form.html'. ```python from html_codegen import ( html, head, body, title, form, fieldset, legend, label, input_, textarea, button, select, option, div ) with html() as doc: with head(): title("Registration Form") with body(): with form(attrs={"method": "POST", "action": "/register"}): with fieldset(): legend().text("Personal Information") with div(attrs={"class": "form-group"}): label(attrs={"for": "name"}).text("Full Name:") input_(attrs={ "type": "text", "id": "name", "name": "name", "required": "", "minlength": "2" }) with div(attrs={"class": "form-group"}): label(attrs={"for": "email"}).text("Email:") input_(attrs={ "type": "email", "id": "email", "name": "email", "required": "", "placeholder": "user@example.com" }) with div(attrs={"class": "form-group"}): label(attrs={"for": "country"}).text("Country:") with select(attrs={"id": "country", "name": "country"}): option(attrs={"value": ""}).text("Select...") option(attrs={"value": "us"}).text("United States") option(attrs={"value": "uk"}).text("United Kingdom") option(attrs={"value": "de"}).text("Germany") with div(attrs={"class": "form-group"}): label(attrs={"for": "message"}).text("Message:") textarea(attrs={ "id": "message", "name": "message", "rows": "4", "cols": "50" }) button(attrs={"type": "submit"}).text("Register") button(attrs={"type": "reset"}).text("Reset") doc.save("form.html") ``` -------------------------------- ### Create HTML Progress Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'progress' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class progress(Tag): """Represents an HTML progress tag.""" pass ``` -------------------------------- ### Create HTML Article Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'article' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class article(Tag): """Represents an HTML article tag.""" pass ``` -------------------------------- ### Create HTML Mark Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'mark' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class mark(Tag): """Represents an HTML mark tag.""" pass ``` -------------------------------- ### Create HTML Header Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'header' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class header(Tag): """Represents an HTML header tag.""" pass ``` -------------------------------- ### Overview of html-codegen Renderer Source: https://context7.com/html_codegen/html_codegen/llms.txt Provides a conceptual overview of the Renderer class within the html-codegen library. It explains that the renderer is responsible for converting the HTML node tree into formatted HTML strings, handling indentation, DOCTYPE, and tag formatting. It's typically used internally. ```python from html_codegen import html, head, body, title, div, p from html_codegen.renderer import Renderer # The Renderer class is used internally by html-codegen to convert the HTML node tree # into formatted HTML strings. It handles aspects like indentation, DOCTYPE declaration, # opening/closing tags, and text content formatting. # Example usage is typically implicit through methods like save() and get_html(). ``` -------------------------------- ### Create HTML Figcaption Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'figcaption' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class figcaption(Tag): """Represents an HTML figcaption tag.""" pass ``` -------------------------------- ### Create HTML Section Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'section' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class section(Tag): """Represents an HTML section tag.""" pass ``` -------------------------------- ### Create HTML Footer Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'footer' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class footer(Tag): """Represents an HTML footer tag.""" pass ``` -------------------------------- ### Create HTML Meter Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'meter' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class meter(Tag): """Represents an HTML meter tag.""" pass ``` -------------------------------- ### Create HTML Paragraph Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML p tag for paragraph text. This class inherits from the base Tag class. ```python class p(Tag): """Represents a p tag in HTML.""" pass ``` -------------------------------- ### HTML q Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the tag in HTML, used for short inline quotations. It inherits from the base Tag class. ```APIDOC ## q Tag ### Description This class represents a tag in HTML. It inherits from the _Tag class. ### Method POST ### Endpoint /html_codegen/tags/text/q ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attrs** (dict | None) - Optional - Attributes for the tag. ### Request Example ```json { "attrs": { "cite": "http://example.com/source" } } ``` ### Response #### Success Response (200) - **tag_name** (string) - The name of the HTML tag ('q'). - **attributes** (dict) - The attributes applied to the tag. #### Response Example ```json { "tag_name": "q", "attributes": { "cite": "http://example.com/source" } } ``` ``` -------------------------------- ### Create HTML Aside Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'aside' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class aside(Tag): """Represents an HTML aside tag.""" pass ``` -------------------------------- ### Create HTML Underline Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML u tag for underlined text. This class inherits from the base Tag class. ```python class u(Tag): """Represents a u tag in HTML.""" pass ``` -------------------------------- ### Generate HTML Quotation Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'q' tag for short, inline quotations. This class inherits from the base Tag class. ```python class html_codegen.tags.q(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a q tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### Create HTML Time Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'time' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class time(Tag): """Represents an HTML time tag.""" pass ``` -------------------------------- ### Create Title HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML title tag, which must contain text content. It inherits from OnlyTextTagMixin and Tag. ```python class title(OnlyTextTagMixin, Tag): """#### __init__(text_content: [str](https://docs.python.org/3/library/stdtypes.html#str),) -> [None](https://docs.python.org/3/library/constants.html#None)""" pass ``` -------------------------------- ### Create HTML Bold Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML b tag for bold text. This class inherits from the base Tag class. ```python class b(Tag): """Represents a b tag in HTML.""" pass ``` -------------------------------- ### Create HTML Strong Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML strong tag for important text. This class inherits from the base Tag class. ```python class strong(Tag): """Represents a strong tag in HTML.""" pass ``` -------------------------------- ### Create Base HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents a base HTML tag. This class inherits from the SingleTag class. ```python class base(SingleTag): pass ``` -------------------------------- ### Create HTML Dialog Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'dialog' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class dialog(Tag): """Represents an HTML dialog tag.""" pass ``` -------------------------------- ### HTML q Tag Generation (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the HTML 'q' tag, used for short inline quotations. This class inherits from the base Tag class in html_codegen. ```python class q(Tag): """Represents a q tag in HTML.""" pass ``` -------------------------------- ### Create Meta HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML meta tag. This class inherits from the SingleTag class. ```python class meta(SingleTag): pass ``` -------------------------------- ### Create HTML Progress Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML progress tag. This class inherits from the base Tag class and is used for generating progress bar elements. ```python class progress(Tag): """Represents a progress tag in HTML.""" pass ``` -------------------------------- ### Create HTML H1 Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'h1' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class h1(Tag): """Represents an HTML h1 tag.""" pass ``` -------------------------------- ### Create HTML Emphasis Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML em tag for emphasized text. This class inherits from the base Tag class. ```python class em(Tag): """Represents an em tag in HTML.""" pass ``` -------------------------------- ### Create HTML H6 Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML h6 tag for the smallest heading. This class inherits from the base Tag class. ```python class h6(Tag): """Represents a h6 tag in HTML.""" pass ``` -------------------------------- ### Create Map HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML map tag. This class inherits from the base Tag class and can be initialized with attributes. ```python class map_(Tag): """This class represents a map tag in HTML. It inherits from the _Tag class.""" pass ``` -------------------------------- ### Generate HTML Preformatted Text Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'pre' tag for preformatted text. This class inherits from the base Tag class and preserves whitespace and line breaks. ```python class html_codegen.tags.pre(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a pre tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### HTML sup Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the tag in HTML, used for superscript text. It inherits from the base Tag class. ```APIDOC ## sup Tag ### Description This class represents a tag in HTML. It inherits from the _Tag class. ### Method POST ### Endpoint /html_codegen/tags/text/sup ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attrs** (dict | None) - Optional - Attributes for the tag. ### Request Example ```json { "attrs": {} } ``` ### Response #### Success Response (200) - **tag_name** (string) - The name of the HTML tag ('sup'). - **attributes** (dict) - The attributes applied to the tag. #### Response Example ```json { "tag_name": "sup", "attributes": {} } ``` ``` -------------------------------- ### Create HTML Meter Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML meter tag. Inheriting from the base Tag class, this facilitates the creation of gauge-like elements. ```python class meter(Tag): """Represents a meter tag in HTML.""" pass ``` -------------------------------- ### HTML Summary Semantic Tag Generation Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the summary semantic tag in HTML5. It inherits from the Tag class. This class is used to generate the element, which provides a visible heading for a
element. ```python class html_codegen.tags.semantic_.summary(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) ``` -------------------------------- ### Create HTML H1 Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML h1 tag for the main heading. This class inherits from the base Tag class. ```python class h1(Tag): """Represents a h1 tag in HTML.""" pass ``` -------------------------------- ### Generate HTML Table with Python Source: https://context7.com/html_codegen/html_codegen/llms.txt This snippet shows how to generate an HTML table using the html_codegen library in Python. It includes support for table sections like thead, tbody, and tfoot, as well as rows (tr), headers (th), and data cells (td). The generated table is saved to 'table.html'. ```python from html_codegen import ( html, head, body, title, table, caption, thead, tbody, tfoot, tr, th, td ) with html() as doc: with head(): title("Sales Report") with body(): with table(attrs={"class": "data-table", "border": "1"}): caption().text("Quarterly Sales Report") # Table header with thead(): with tr(): th().text("Month") th().text("Sales") th().text("Revenue") th().text("Growth") # Table body with tbody(): with tr(): td().text("January") td().text("1,200") td().text("$24,000") td().text("+5%") with tr(): td().text("February") td().text("1,450") td().text("$29,000") td().text("+8%") with tr(): td().text("March") td().text("1,380") td().text("$27,600") td().text("+3%") # Table footer with tfoot(): with tr(): th().text("Total") th().text("4,030") th().text("$80,600") th().text("+5.3% avg") doc.save("table.html") ``` -------------------------------- ### HTML samp Tag Generation (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the HTML 'samp' tag, used for sample output from a computer program. This class inherits from the base Tag class in html_codegen. ```python class samp(Tag): """Represents a samp tag in HTML.""" pass ``` -------------------------------- ### Add Child Nodes to HTMLNode (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Illustrates the process of adding child nodes to an existing HTMLNode. The `add_node` method is used for this purpose, ensuring that the new node is correctly appended to the parent. A validation step (`add_node_validation`) can be implemented before adding the node. ```Python from html_codegen.core import HTMLNode parent_node = HTMLNode() child_node = HTMLNode() # Add the child_node to the parent_node parent_node.add_node(child_node) # The parent_node now has child_node as one of its children. ``` -------------------------------- ### Generate HTML Citation Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'cite' tag for the title of a work (e.g., book, movie). This class inherits from the base Tag class. ```python class html_codegen.tags.cite(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a cite tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### Generate HTML Address Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'address' tag for contact information. This class inherits from the base Tag class. ```python class html_codegen.tags.address(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents an address tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### Create HTML Figure Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'figure' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class figure(Tag): """Represents an HTML figure tag.""" pass ``` -------------------------------- ### Create Link HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML link tag, requiring href and rel attributes. It inherits from SingleTag and can accept additional keyword arguments. ```python class link(SingleTag): """#### __init__(href: [str](https://docs.python.org/3/library/stdtypes.html#str), , rel: [str](https://docs.python.org/3/library/stdtypes.html#str), **kwargs) -> [None](https://docs.python.org/3/library/constants.html#None) Initialize an HTML class instance. * **Parameters:** * **tag_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – Tag name of the element * **attrs** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict) *,* *optional*) – Dictionary of element attributes""" pass ``` -------------------------------- ### HTML kbd Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the tag in HTML, used for keyboard input. It inherits from the base Tag class. ```APIDOC ## kbd Tag ### Description This class represents a tag in HTML. It inherits from the _Tag class. ### Method POST ### Endpoint /html_codegen/tags/text/kbd ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attrs** (dict | None) - Optional - Attributes for the tag. ### Request Example ```json { "attrs": {} } ``` ### Response #### Success Response (200) - **tag_name** (string) - The name of the HTML tag ('kbd'). - **attributes** (dict) - The attributes applied to the tag. #### Response Example ```json { "tag_name": "kbd", "attributes": {} } ``` ``` -------------------------------- ### HTML sup Tag Generation (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the HTML 'sup' tag, used for superscript text. This class inherits from the base Tag class in html_codegen. ```python class sup(Tag): """Represents a sup tag in HTML.""" pass ``` -------------------------------- ### Generate HTML Keyboard Input Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'kbd' tag, typically used for keyboard input. This class inherits from the base Tag class. ```python class html_codegen.tags.kbd(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a kbd tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### Create HTML H5 Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML h5 tag for a smaller subheading. This class inherits from the base Tag class. ```python class h5(Tag): """Represents a h5 tag in HTML.""" pass ``` -------------------------------- ### Create HTML H2 Tag (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'h2' tag. Inherits from the base Tag class. Accepts optional attributes. ```python class h2(Tag): """Represents an HTML h2 tag.""" pass ``` -------------------------------- ### HTML address Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the
tag in HTML, used for contact information. It inherits from the base Tag class. ```APIDOC ## address Tag ### Description This class represents an
tag in HTML. It inherits from the _Tag class. ### Method POST ### Endpoint /html_codegen/tags/text/address ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attrs** (dict | None) - Optional - Attributes for the tag. ### Request Example ```json { "attrs": {} } ``` ### Response #### Success Response (200) - **tag_name** (string) - The name of the HTML tag ('address'). - **attributes** (dict) - The attributes applied to the tag. #### Response Example ```json { "tag_name": "address", "attributes": {} } ``` ``` -------------------------------- ### Generate HTML Line Break Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML 'br' tag for a single line break. This class inherits from the base Tag class. ```python class html_codegen.tags.br(attrs: [dict](https://docs.python.org/3/library/stdtypes.html#dict) | [None](https://docs.python.org/3/library/constants.html#None) = None) Bases: [`Tag`](#html_codegen.tags.base_.Tag) This class represents a br tag in HTML. It inherits from the _Tag class. ``` -------------------------------- ### HTML cite Tag Generation (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the HTML 'cite' tag, used for the title of a work (e.g., book, movie). This class inherits from the base Tag class in html_codegen. ```python class cite(Tag): """Represents a cite tag in HTML.""" pass ``` -------------------------------- ### Create Anchor HTML Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents an HTML anchor (a) tag, used for creating hyperlinks. This class inherits from the base Tag class and can be initialized with attributes. ```python class a(Tag): """This class represents an a tag in HTML. It inherits from the _Tag class.""" pass ``` -------------------------------- ### HTML pre Tag Generation (Python) Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the HTML 'pre' tag, used for preformatted text, preserving whitespace. This class inherits from the base Tag class in html_codegen. ```python class pre(Tag): """Represents a pre tag in HTML.""" pass ``` -------------------------------- ### HTML pre Tag Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md Represents the
 tag in HTML, used for preformatted text, typically code blocks. It inherits from the base Tag class.

```APIDOC
## pre Tag

### Description
This class represents a 
 tag in HTML. It inherits from the _Tag class.

### Method
POST

### Endpoint
/html_codegen/tags/text/pre

### Parameters
#### Path Parameters
None

#### Query Parameters
None

#### Request Body
- **attrs** (dict | None) - Optional - Attributes for the tag.

### Request Example
```json
{
  "attrs": {
    "class": "code-block"
  }
}
```

### Response
#### Success Response (200)
- **tag_name** (string) - The name of the HTML tag ('pre').
- **attributes** (dict) - The attributes applied to the tag.

#### Response Example
```json
{
  "tag_name": "pre",
  "attributes": {
    "class": "code-block"
  }
}
```
```

--------------------------------

### HTML kbd Tag Generation (Python)

Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md

Represents the HTML 'kbd' tag, used for keyboard input. This class inherits from the base Tag class in html_codegen.

```python
class kbd(Tag):
    """Represents a kbd tag in HTML."""
    pass
```

--------------------------------

### HTML samp Tag

Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md

Represents the  tag in HTML, used for sample output from a computer program. It inherits from the base Tag class.

```APIDOC
## samp Tag

### Description
This class represents a  tag in HTML. It inherits from the _Tag class.

### Method
POST

### Endpoint
/html_codegen/tags/text/samp

### Parameters
#### Path Parameters
None

#### Query Parameters
None

#### Request Body
- **attrs** (dict | None) - Optional - Attributes for the tag.

### Request Example
```json
{
  "attrs": {}
}
```

### Response
#### Success Response (200)
- **tag_name** (string) - The name of the HTML tag ('samp').
- **attributes** (dict) - The attributes applied to the tag.

#### Response Example
```json
{
  "tag_name": "samp",
  "attributes": {}
}
```
```

--------------------------------

### HTML cite Tag

Source: https://gitlab.com/html_codegen/html_codegen/-/blob/main/docs/source/api.md

Represents the  tag in HTML, used for the title of a creative work. It inherits from the base Tag class.

```APIDOC
## cite Tag

### Description
This class represents a  tag in HTML. It inherits from the _Tag class.

### Method
POST

### Endpoint
/html_codegen/tags/text/cite

### Parameters
#### Path Parameters
None

#### Query Parameters
None

#### Request Body
- **attrs** (dict | None) - Optional - Attributes for the tag.

### Request Example
```json
{
  "attrs": {}
}
```

### Response
#### Success Response (200)
- **tag_name** (string) - The name of the HTML tag ('cite').
- **attributes** (dict) - The attributes applied to the tag.

#### Response Example
```json
{
  "tag_name": "cite",
  "attributes": {}
}
```
```