You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
568 B
17 lines
568 B
|
|
from html5lib import treewalkers
|
|
|
|
from htmlserializer import HTMLSerializer
|
|
from xhtmlserializer import XHTMLSerializer
|
|
|
|
def serialize(input, tree="simpletree", format="html", encoding=None,
|
|
**serializer_opts):
|
|
# XXX: Should we cache this?
|
|
walker = treewalkers.getTreeWalker(tree)
|
|
if format == "html":
|
|
s = HTMLSerializer(**serializer_opts)
|
|
elif format == "xhtml":
|
|
s = XHTMLSerializer(**serializer_opts)
|
|
else:
|
|
raise ValueError, "type must be either html or xhtml"
|
|
return s.render(walker(input), encoding)
|
|
|