skip to navigation
skip to content

BeautifulHTML 1.2.0

Can write a Beautiful HTML Code in python script.

Downloads ↓

About
============

This script can write BEAUTIFUL HTML.
Supported indent, it's simple code.

Class
============

1, BeautifulHTML
2, LittleBeautifulCSS


1, BeautifulHTML
--------------------
Methods:
----------
  write(self,str) -- write a tag.Please write a tag code at second argument.
  indent(self,str,block=1) -- write a tag with indent.
  delete(self) -- delete line.
  addoption(self,tag,data,content,indent=False,block=0,closetag=True)
      Write a new tag code with any option.
        tag -- tag name.
        data -- dictionary or list. it is tag option.
        content -- contents of tag code.
        indent -- Wheter do indent. True or False.
        block -- indent block size. int data please.
        closetag -- if you write a no-close-tag-code, it is True
  br(self) -- write a "br" tag.
  noclosetag(self) -- write a tag code without close-tag.
  setcss(self) -- return LittleBeautifulCSS class object.
  writecss(self,release,indent=False,block=0)
       Write a CSS code that create css element.
  printout(self) -- return item
  __str__(self) -- return item
  encoding(self) -- return encoding
  length(self) -- return the length of HTML tag line.
  outfile(self,filename) -- output a file.
  editvim(self) -- edit html code with vim.

2, LittleBeautifulCSS
-----------------------
Methods:
---------
  element(self,body,data) -- write css element.
     body -- element name.
     data -- element content. directory or list.
  delete(self) -- delete a css line.
  __str__(self) -- return css item
  release(self) -- release css code to "writecss" method of BeautifulHTML class object.
  length(self) -- return length of CSS code line.



Usage
=============

>>> from Bhtml import BeautifulHTML
>>> html = BeautifulHTML()
>>> html.write("<html>")
'<html>\n'
>>> html.indent("<head>")
'<html>\n\t<head>\n'
>>> html.indent("<title> sample </title>", block=2)
'<html>\n\t<head>\n\t\t<title> sample </title>\n'
>>> css = html.setcss()
>>>
>>> css.element("body",{"background":"#ccc","color":"#000"})
'body { background: #ccc; color: #000; }'
>>> html.writecss(css.release(),indent=True,block=2)
'<html>\n\t<head>\n\t\t<title> sample </title>\n\t\t<script type="text/css">\n\t\tbody { background: #ccc; color: #000; }\n\t\t</style>'
>>>
>>> print html
<html>
        <head>
                <title> sample </title>
                <style type="text/css">
                body { background: #ccc; color: #000; }
                </style>

>>> html.indent("</head>")
'<html>\n\t<head>\n\t\t<title> sample </title>\n\t\t<script type="text/css">\n\t\tbody { b    ackground: #ccc; color: #000; }\n\t\t</style>\n\t</head>'
 
File Type Py Version Uploaded on Size # downloads
BeautifulHTML-1.2.0.tar.gz (md5) Source 2011-02-17 2KB 405