Git Product home page Git Product logo

bs4tag's Introduction

This library is based on the sources and definitions of yattag with the fondamental difference that BeautifulSoup is used as the html renderer.

Differences between bs4tag and yattag

* At this time, only SimpleDoc has been converted, Doc class is work in progress. *

  • The SimpleDoc/Doc object contains a BeautifulSoup intance in the soup attribute
  • asis() and ttls() functions added to SimpleDoc

( tutorial for both libraries: yattag.org and BS4)

Limitations

  • No support for custom indentation (indent)
  • stag_end option is not available

Basic example

Nested html tags, no need to close tags, same as yattag.

from bs4tag import Doc

doc, tag, text = Doc().tagtext()

with tag('html'):
    with tag('body', id = 'hello'):
        with tag('h1'):
            text('Hello world!')

print(doc.getvalue())

With BeautifulSoup added functionalities

Insert bs4tag document into a BeautifulSoup instance.

def body_text():
    doc, tag, text = SimpleDoc().tagtext()
    with tag('h1'):
        text('Hello world!')
    return doc.soup


doc, tag, text = SimpleDoc().tagtext()

with tag('html'):
    with tag('body', id='hello'):
        pass

doc.soup.find(id='hello').append(body_text())

print(doc.getvalue())
# <html><body id="hello"><h1>Hello world!</h1></body></html>

Installation

pip3 install bs4tag

This library is compatible with the tutorial on yattag.org

GitHub repo: https://github.com/ceprio/bs4tag Derived from: https://github.com/leforestier/yattag

bs4tag's People

Contributors

ceprio avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.