Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

First pass at docs for html5lib.treeadapters#380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gsnedders merged 1 commit intohtml5lib:masterfromwillkg:307-treeadapter
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletionshtml5lib/treeadapters/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
"""Tree adapters let you convert from one tree structure to another

Example:

.. code-block:: python

import html5lib
from html5lib.treeadapters import genshi

doc = '<html><body>Hi!</body></html>'
treebuilder = html5lib.getTreeBuilder('etree')
parser = html5lib.HTMLParser(tree=treebuilder)
tree = parser.parse(doc)
TreeWalker = html5lib.getTreeWalker('etree')

genshi_tree = genshi.to_genshi(TreeWalker(tree))

"""
from __future__ import absolute_import, division, unicode_literals

from . import sax
Expand Down
7 changes: 7 additions & 0 deletionshtml5lib/treeadapters/genshi.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,13 @@


def to_genshi(walker):
"""Convert a tree to a genshi tree

:arg walker: the treewalker to use to walk the tree to convert it

:returns: generator of genshi nodes

"""
text = []
for token in walker:
type = token["type"]
Expand Down
8 changes: 7 additions & 1 deletionhtml5lib/treeadapters/sax.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,13 @@


def to_sax(walker, handler):
"""Call SAX-like content handler based on treewalker walker"""
"""Call SAX-like content handler based on treewalker walker

:arg walker: the treewalker to use to walk the tree to convert it

:arg handler: SAX handler to use

"""
handler.startDocument()
for prefix, namespace in prefix_mapping.items():
handler.startPrefixMapping(prefix, namespace)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp