### Clone and Install HTML Codegen for Development (Bash) Source: https://context7_llms This sequence of commands clones the HTML Codegen library repository and installs its development dependencies using uv. This setup is for users who intend to contribute to or modify the library itself. ```bash git clone https://gitlab.com/html_codegen/html_codegen.git cd html_codegen uv sync --group dev ``` -------------------------------- ### Verify HTML Codegen Installation (Python) Source: https://context7_llms This Python snippet verifies a successful installation of the html_codegen library by generating a simple HTML file. If the 'test.html' file is created without errors, the installation is confirmed to be working correctly. ```python from html_codegen import html, head, body, title, div, p, h1 # Простой тест with html() as doc: with head(): title("Тест") with body(): h1().text("Установка прошла успешно!") div().p().text("Библиотека работает корректно.") doc.save("test.html") ``` -------------------------------- ### Install HTML Codegen via uv (Bash) Source: https://context7_llms This command installs the HTML Codegen library into your project using the uv package manager. It fetches the library directly from its GitLab repository. This is the recommended method for adding the dependency. ```bash uv add git+https://gitlab.com/html_codegen/html_codegen.git ``` -------------------------------- ### Install HTML Codegen via pip (Bash) Source: https://context7_llms This command installs the HTML Codegen library into your project using pip. It fetches the library directly from its GitLab repository. This is an alternative method for adding the dependency. ```bash pip install git+https://gitlab.com/html_codegen/html_codegen.git ``` -------------------------------- ### Create Simple HTML Page with html_codegen Source: https://context7_llms Generates a basic HTML page with a title, heading, and paragraph using the html_codegen library. This is a foundational example for creating static HTML content. ```python from html_codegen import html, head, body, title, div, p, h1 with html() as doc: with head(): title("Простая страница") with body(): h1().text("Добро пожаловать!") with div(attrs={"class": "container"}): p().text("Это пример HTML страницы.") doc.save("index.html") ``` -------------------------------- ### Install Specific Version of HTML Codegen (Bash) Source: https://context7_llms These commands demonstrate how to install specific versions, branches, or commits of the HTML Codegen library from its GitLab repository using uv or pip. This is useful for managing dependencies with specific requirements. ```bash # Конкретный тег uv add git+https://gitlab.com/html_codegen/html_codegen.git@v0.1.0 ``` ```bash # Конкретная ветка uv add git+https://gitlab.com/html_codegen/html_codegen.git@main ``` ```bash # Конкретный коммит pip install git+https://gitlab.com/html_codegen/html_codegen.git@abc123 ``` -------------------------------- ### Reinstall Dependencies with uv (Bash) Source: https://context7_llms This command re-installs all project dependencies using uv. It is a troubleshooting step for resolving dependency-related issues that might arise after installation or during development. ```bash uv sync --reinstall ``` -------------------------------- ### Generate Blog Structure with html_codegen Source: https://context7_llms Builds a complete HTML blog structure including header, navigation, main content with articles, sidebar, and footer using various html_codegen tags. This example showcases semantic HTML generation. ```python from html_codegen import ( html, head, body, title, meta, link, header, nav, main, article, aside, footer, h1, h2, p, ul, li, a, time ) with html() as blog: with head(): title("Мой блог") meta(attrs={"charset": "UTF-8"}) meta(attrs={"name": "viewport", "content": "width=device-width, initial-scale=1.0"}) link("styles.css", rel="stylesheet") with body(): with header(): h1().text("Мой блог") with nav(): with ul(): with li(): a(attrs={"href": "/"}).text("Главная") with li(): a(attrs={"href": "/about"}).text("О нас") with li(): a(attrs={"href": "/contact"}).text("Контакты") with main(): with article(): h2().text("Первая статья") p().text("Содержание первой статьи...") time(attrs={"datetime": "2024-01-15"}).text("2024-01-15") with article(): h2().text("Вторая статья") p().text("Содержание второй статьи...") with aside(): h2().text("Боковая панель") p().text("Дополнительная информация...") with footer(): p().text("© 2024 Мой блог") blog.save("blog.html") ``` -------------------------------- ### Create Registration Form with html_codegen Source: https://context7_llms Generates an HTML registration form with fields for name, email, and password using the html_codegen library. This example demonstrates the use of form, fieldset, label, and input tags. ```python from html_codegen import ( html, head, body, title, form, fieldset, legend, label, input_, button, div, h1 ) with html() as doc: with head(): title("Регистрация") with body(): h1().text("Регистрация") with form(attrs={"method": "POST", "action": "/register"}): with fieldset(): legend().text("Личная информация") with div(): label(attrs={"for": "name"}).text("Имя:") input_(attrs={"type": "text", "id": "name", "name": "name"}) with div(): label(attrs={"for": "email"}).text("Email:") input_(attrs={"type": "email", "id": "email", "name": "email"}) with div(): label(attrs={"for": "password"}).text("Пароль:") ``` -------------------------------- ### Create HTML Page with CSS Styles using html_codegen Source: https://context7_llms Demonstrates how to create an HTML page with an external CSS stylesheet linked using the html_codegen library. This example shows the inclusion of the `link` tag for styling. ```python from html_codegen import html, head, body, title, link, div, p, h1 with html() as doc: with head(): title("Страница со стилями") link("styles.css", rel="stylesheet") with body(): with div(attrs={"class": "container"}): h1().text("Стилизованная страница") with div(attrs={"class": "highlight"}): p().text("Этот текст выделен стилем.") doc.save("styled.html") ``` -------------------------------- ### Generate HTML Forms in Python Source: https://context7_llms Illustrates how to create HTML forms with labels, input fields, and submit buttons using the html_codegen library. This example includes setting form attributes like 'method' and 'action'. The output is saved to 'form.html'. ```python from html_codegen import html, body, form, input_, label, button with html() as doc: with body(): with form(attrs={"method": "POST", "action": "/submit"}): label(attrs={"for": "name"}).text("Имя:") input_(attrs={"type": "text", "id": "name", "name": "name"}) button(attrs={"type": "submit"}).text("Отправить") doc.save("form.html") ``` -------------------------------- ### Generate HTML Tables in Python Source: https://context7_llms Provides an example of creating an HTML table with a header (thead) and body (tbody) using the html_codegen library. Table rows (tr) and cells (th, td) are used to structure the data. The output is saved to 'table.html'. ```python from html_codegen import html, body, table, thead, tbody, tr, th, td with html() as doc: with body(): with table(attrs={"border": "1"}): with thead(): with tr(): th().text("Имя") th().text("Возраст") th().text("Город") with tbody(): with tr(): td().text("Иван") td().text("25") td().text("Москва") with tr(): td().text("Мария") td().text("30") td().text("Санкт-Петербург") doc.save("table.html") ``` -------------------------------- ### Generated HTML Structure Source: https://context7_llms This is the resulting HTML code generated from the Python snippet in the 'First example' section. It shows a standard HTML5 document structure with head and body content, including headings, paragraphs, and divs. ```html Моя первая страница

Добро пожаловать!

Это мой первый пример с HTML Codegen.

``` -------------------------------- ### Generate HTML Page with Brython Support (Python) Source: https://context7_llms This Python code demonstrates the creation of a basic HTML page using the html_codegen library. It showcases the use of context managers for structuring the document and method calls for adding content. The generated HTML is saved to a file named 'page.html'. ```python from html_codegen import html, head, body, title, div, p, h1 with html() as doc: with head(): title("Моя первая страница") with body(): h1().text("Добро пожаловать!") div().p().text("Это мой первый пример с HTML Codegen.") doc.save("page.html") ``` -------------------------------- ### Create Semantic HTML5 Page Structure in Python Source: https://context7_llms Shows how to build a semantically structured HTML page using HTML5 elements like header, main, article, and footer. This approach improves SEO and accessibility. The generated HTML is saved to 'semantic.html'. ```python from html_codegen import html, head, body, title, header, main, article, footer, h1, h2, p with html() as doc: with head(): title("Семантическая страница") with body(): with header(): h1().text("Заголовок сайта") with main(): with article(): h2().text("Статья") p().text("Содержание статьи") with footer(): p().text("Подвал сайта") doc.save("semantic.html") ``` -------------------------------- ### Generate HTML Table and Save Source: https://context7_llms Creates an HTML table representing sales data for a quarter, including headers, body rows, and a footer summary. The generated HTML is saved to 'sales.html'. This demonstrates table structure generation. ```python from html_codegen import ( html, head, body, title, table, thead, tbody, tfoot, tr, th, td, caption, h1, div ) with html() as doc: with head(): title("Отчет по продажам") with body(): h1().text("Продажи по месяцам") with table(attrs={"border": "1"}): caption().text("Продажи за квартал") with thead(): with tr(): th().text("Месяц") th().text("Продажи") th().text("Прибыль") with tbody(): with tr(): td().text("Январь") td().text("100,000") td().text("20,000") with tr(): td().text("Февраль") td().text("120,000") td().text("25,000") with tr(): td().text("Март") td().text("110,000") td().text("22,000") with tfoot(): with tr(): th().text("Итого") th().text("330,000") th().text("67,000") doc.save("sales.html") ``` -------------------------------- ### Generate Brython Interactive App HTML Source: https://context7_llms Generates an HTML file for a Brython-enabled interactive application. It includes a title, heading, a div with a button and paragraphs, and integrates Python code to run in the browser. The output is saved to 'brython_app.html'. ```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"}) # Python код выполнится в браузере pyscript("web.scripts.py.app") doc.save("brython_app.html") ``` -------------------------------- ### Generate Basic HTML Page with HTML Codegen (Python) Source: https://context7_llms This snippet demonstrates how to generate a simple HTML page using the html_codegen library. It utilizes context managers for hierarchical structure and method calls for creating elements and setting text content. The generated HTML is saved to a file. ```python from html_codegen import html, head, body, title, div, p, h1 with html() as doc: with head(): title("Моя страница") with body(): h1().text("Привет, мир!") with div(attrs={"class": "container"}): p().text("Это пример использования html_codegen.") doc.save("index.html") ``` -------------------------------- ### Create HTML Lists (Ordered and Unordered) in Python Source: https://context7_llms Demonstrates the creation of both ordered (numbered) and unordered (bulleted) lists in HTML using the html_codegen library. Each list item is defined using the 'li' tag. The generated HTML is saved to 'lists.html'. ```python from html_codegen import html, body, ul, ol, li, h2 with html() as doc: with body(): h2().text("Нумерованный список:") with ol(): li().text("Первый элемент") li().text("Второй элемент") li().text("Третий элемент") h2().text("Маркированный список:") with ul(): li().text("Элемент 1") li().text("Элемент 2") li().text("Элемент 3") doc.save("lists.html") ``` -------------------------------- ### Generate HTML with Attributes in Python Source: https://context7_llms Demonstrates how to create HTML elements with specific attributes using the html_codegen library. The 'p' tag is used with a 'class' attribute to style the text. The resulting HTML is saved to 'attrs.html'. ```python from html_codegen import html, p with html() as doc: p(attrs={"class": "highlight"}).text("Текст с атрибутами") doc.save("attrs.html") ``` -------------------------------- ### Generate HTML Form and Save Source: https://context7_llms Generates a simple HTML form with password input and a submit button, then saves it to a file named 'register.html'. This snippet showcases basic HTML element creation. ```python from html_codegen import html, input, button with html() as doc: input(attrs={"type": "password", "id": "password", "name": "password"}) button(attrs={"type": "submit"}).text("Зарегистрироваться") doc.save("register.html") ``` -------------------------------- ### Dynamically Generate HTML Navigation Menu Source: https://context7_llms Implements a Python function `create_navigation_menu` that generates an HTML navigation list (`