mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-21 04:09:26 +00:00
BeautifulSoup needs lxml or html5, have included html5lib. Also latest BeautifulSoup 4.1.3
18 lines
568 B
Python
18 lines
568 B
Python
|
|
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)
|