File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1+ """Tree adapters let you convert from one tree structure to another
2+
3+ Example:
4+
5+ .. code-block:: python
6+
7+ import html5lib
8+ from html5lib.treeadapters import genshi
9+
10+ doc = '<html><body>Hi!</body></html>'
11+ treebuilder = html5lib.getTreeBuilder('etree')
12+ parser = html5lib.HTMLParser(tree=treebuilder)
13+ tree = parser.parse(doc)
14+ TreeWalker = html5lib.getTreeWalker('etree')
15+
16+ genshi_tree = genshi.to_genshi(TreeWalker(tree))
17+
18+ """
119from __future__ import absolute_import , division , unicode_literals
220
321from . import sax
Original file line number Diff line number Diff line change 55
66
77def to_genshi (walker ):
8+ """Convert a tree to a genshi tree
9+
10+ :arg walker: the treewalker to use to walk the tree to convert it
11+
12+ :returns: generator of genshi nodes
13+
14+ """
815 text = []
916 for token in walker :
1017 type = token ["type" ]
Original file line number Diff line number Diff line change 1111
1212
1313def to_sax (walker , handler ):
14- """Call SAX-like content handler based on treewalker walker"""
14+ """Call SAX-like content handler based on treewalker walker
15+
16+ :arg walker: the treewalker to use to walk the tree to convert it
17+
18+ :arg handler: SAX handler to use
19+
20+ """
1521 handler .startDocument ()
1622 for prefix , namespace in prefix_mapping .items ():
1723 handler .startPrefixMapping (prefix , namespace )
You can’t perform that action at this time.
0 commit comments