Package tidy
[hide private]
[frames] | no frames]

Source Code for Package tidy

 1  """The Tidy wrapper. 
 2  I am the main interface to TidyLib. This package supports processing HTML with 
 3  Tidy, with all the options that the tidy command line supports. 
 4   
 5  For more information on the tidy options, see the reference. These options can 
 6  be given as keyword arguments to parse and parseString, by changing dashes (-) 
 7  to underscores(_). 
 8   
 9  For example: 
10   
11  >>> import tidy 
12  >>> options = dict(output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0) 
13  >>> print tidy.parseString('<Html>Hello Tidy!', **options) 
14  <?xml version="1.0" encoding="us-ascii"?> 
15  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
16      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
17  <html xmlns="http://www.w3.org/1999/xhtml"> 
18    <head> 
19      <title></title> 
20    </head> 
21    <body> 
22      Hello Tidy! 
23    </body> 
24  </html> 
25   
26  For options like newline and output_encoding, which must be set to one of a 
27  fixed number of choices, you can provide either the numeric or string version 
28  of the choice; so both tidy.parseString('<HTML>foo</html>', newline=2) and 
29  tidy.parseString('<HTML>foo</html>', newline='CR') do the same thing.   
30   
31  There are no plans to support other features of TidyLib, such as document-tree 
32  traversal, since Python has several quality DOM implementations. (The author 
33  uses Twisted's implementation, twisted.web.microdom). 
34  """ 
35   
36  try: 
37      dict(x=1) 
38  except TypeError: 
39      raise ImportError("Python 2.3 or later is required to import this library.") 
40   
41  __all__ = ['error', 'lib'] 
42   
43  from tidy.lib import parse, parseString 
44  from tidy.error import * 
45