@@ -77,19 +77,22 @@ def parse():
7777def printOutput (parser , document , opts ):
7878 if opts .encoding :
7979 print "Encoding:" , parser .tokenizer .stream .charEncoding
80- if not opts .no_tree :
81- if opts .xml :
82- sys .stdout .write (document .toxml ("utf-8" ))
83- elif opts .html :
84- tokens = treewalkers .getTreeWalker (opts .treebuilder )(document )
85- for text in serializer .HTMLSerializer ().serialize (tokens , encoding = 'utf-8' ):
86- sys .stdout .write (text )
87- elif opts .hilite :
88- sys .stdout .write (document .hilite ("utf-8" ))
89- else :
90- if not hasattr (document ,'__getitem__' ): document = [document ]
91- for fragment in document :
92- print parser .tree .testSerializer (fragment ).encode ("utf-8" )
80+ if opts .xml :
81+ sys .stdout .write (document .toxml ("utf-8" ))
82+ elif opts .tree :
83+ if not hasattr (document ,'__getitem__' ): document = [document ]
84+ for fragment in document :
85+ print parser .tree .testSerializer (fragment ).encode ("utf-8" )
86+ elif opts .hilite :
87+ sys .stdout .write (document .hilite ("utf-8" ))
88+ elif opts .html :
89+ kwargs = {}
90+ for opt in ['inject_meta_charset' , 'strip_whitespace' , 'sanitize' ,
91+ 'omit_optional_tags' ]:
92+ kwargs [opt ] = getattr (opts ,opt )
93+ tokens = treewalkers .getTreeWalker (opts .treebuilder )(document )
94+ for text in serializer .HTMLSerializer (** kwargs ).serialize (tokens , encoding = 'utf-8' ):
95+ sys .stdout .write (text )
9396 if opts .error :
9497 errList = []
9598 for pos , message in parser .errors :
@@ -107,9 +110,6 @@ def getOptParser():
107110 action = "store_true" , default = False , dest = "time" ,
108111 help = "Time the run using time.time (may not be accurate on all platforms, especially for short runs)" )
109112
110- parser .add_option ("" , "--no-tree" , action = "store_true" , default = False ,
111- dest = "no_tree" , help = "Do not print output tree" )
112-
113113 parser .add_option ("-b" , "--treebuilder" , action = "store" , type = "string" ,
114114 dest = "treebuilder" , default = "simpleTree" )
115115
@@ -119,17 +119,36 @@ def getOptParser():
119119 parser .add_option ("-f" , "--fragment" , action = "store_true" , default = False ,
120120 dest = "fragment" , help = "Parse as a fragment" )
121121
122+ parser .add_option ("" , "--tree" , action = "store_true" , default = False ,
123+ dest = "tree" , help = "Output as debug tree" )
124+
122125 parser .add_option ("-x" , "--xml" , action = "store_true" , default = False ,
123126 dest = "xml" , help = "Output as xml" )
124127
125- parser .add_option ("" , "--html" , action = "store_true " , default = False ,
126- dest = "html" , help = "Output as html" )
128+ parser .add_option ("" , "--no- html" , action = "store_false " , default = True ,
129+ dest = "html" , help = "Don't output html" )
127130
128131 parser .add_option ("" , "--hilite" , action = "store_true" , default = False ,
129132 dest = "hilite" , help = "Output as formatted highlighted code." )
130133
131134 parser .add_option ("-c" , "--encoding" , action = "store_true" , default = False ,
132135 dest = "encoding" , help = "Print character encoding used" )
136+
137+ parser .add_option ("" , "--inject-meta-charset" , action = "store_true" ,
138+ default = False , dest = "inject_meta_charset" ,
139+ help = "inject <meta charset>" )
140+
141+ parser .add_option ("" , "--strip-whitespace" , action = "store_true" ,
142+ default = False , dest = "strip_whitespace" ,
143+ help = "strip whitespace" )
144+
145+ parser .add_option ("" , "--omit-optional-tags" , action = "store_true" ,
146+ default = False , dest = "omit_optional_tags" ,
147+ help = "omit-optional-tags" )
148+
149+ parser .add_option ("" , "--sanitize" , action = "store_true" , default = False ,
150+ dest = "sanitize" , help = "sanitize" )
151+
133152 return parser
134153
135154if __name__ == "__main__" :
0 commit comments