Skip to content

YaroslavDrozdovskiy/HTML_code_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Генератор html кода


  • В коде присутствуют три основных класса HTML, TopLevelTag и Tag, вызываемые контекстным менеджером with
  • Класс HTML определяет, куда сохранять вывод: на экран через print, или в файл, если передан именованный аргумент output = 'output.txt'

Пример

with HTML(output="test.html") as doc:
    with TopLevelTag("head") as head:
        with Tag("title") as title:
            title.text = "hello"
            head += title
        doc += head

    with TopLevelTag("body") as body:
        with Tag("h1", klass=("main-text",)) as h1:
            h1.text = "Test"
            body += h1

        with Tag("div", klass=("container", "container-fluid"), id="lead") as div:
            with Tag("p") as paragraph:
                paragraph.text = "another test"
                div += paragraph

            with Tag("img", is_single=True, src="/icon.png" data_image="responsive") as img:
                div += img

            body += div

        doc += body

Выполенный код сохранит результат в файл test.html

<html>
<head>
  <title>hello</title>
</head>
<body>
    <h1 class="main-text">Test</h1>
    <div class="container container-fluid" id="lead">
        <p>another test</p>
        <img src="/icon.png" data-image="responsive"/>
    </div>
</body>
</html>

About

Генератор html кода

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages