Skip to content

Commit f7708c4

Browse files
willkggsnedders
authored andcommitted
First pass at documenting html5lib.filters (#375)
1 parent 69152dc commit f7708c4

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

html5lib/filters/alphabeticalattributes.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def _attr_key(attr):
1717

1818

1919
class Filter(base.Filter):
20+
"""Alphabetizes attributes for elements"""
2021
def __iter__(self):
2122
for token in base.Filter.__iter__(self):
2223
if token["type"] in ("StartTag", "EmptyTag"):

html5lib/filters/inject_meta_charset.py

+8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55

66
class Filter(base.Filter):
7+
"""Injects ``<meta charset=ENCODING>`` tag into head of document"""
78
def __init__(self, source, encoding):
9+
"""Creates a Filter
10+
11+
:arg source: the source token stream
12+
13+
:arg encoding: the encoding to set
14+
15+
"""
816
base.Filter.__init__(self, source)
917
self.encoding = encoding
1018

html5lib/filters/lint.py

+12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@
1010

1111

1212
class Filter(base.Filter):
13+
"""Lints the token stream for errors
14+
15+
If it finds any errors, it'll raise an ``AssertionError``.
16+
17+
"""
1318
def __init__(self, source, require_matching_tags=True):
19+
"""Creates a Filter
20+
21+
:arg source: the source token stream
22+
23+
:arg require_matching_tags: whether or not to require matching tags
24+
25+
"""
1426
super(Filter, self).__init__(source)
1527
self.require_matching_tags = require_matching_tags
1628

html5lib/filters/optionaltags.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
class Filter(base.Filter):
7+
"""Removes optional tags from the token stream"""
78
def slider(self):
89
previous1 = previous2 = None
910
for token in self.source:

html5lib/filters/sanitizer.py

+37-6
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@
705705

706706

707707
class Filter(base.Filter):
708-
""" sanitization of XHTML+MathML+SVG and of inline style attributes."""
708+
"""Sanitizes token stream of XHTML+MathML+SVG and of inline style attributes"""
709709
def __init__(self,
710710
source,
711711
allowed_elements=allowed_elements,
@@ -718,6 +718,37 @@ def __init__(self,
718718
attr_val_is_uri=attr_val_is_uri,
719719
svg_attr_val_allows_ref=svg_attr_val_allows_ref,
720720
svg_allow_local_href=svg_allow_local_href):
721+
"""Creates a Filter
722+
723+
:arg allowed_elements: set of elements to allow--everything else will
724+
be escaped
725+
726+
:arg allowed_attributes: set of attributes to allow in
727+
elements--everything else will be stripped
728+
729+
:arg allowed_css_properties: set of CSS properties to allow--everything
730+
else will be stripped
731+
732+
:arg allowed_css_keywords: set of CSS keywords to allow--everything
733+
else will be stripped
734+
735+
:arg allowed_svg_properties: set of SVG properties to allow--everything
736+
else will be removed
737+
738+
:arg allowed_protocols: set of allowed protocols for URIs
739+
740+
:arg allowed_content_types: set of allowed content types for ``data`` URIs.
741+
742+
:arg attr_val_is_uri: set of attributes that have URI values--values
743+
that have a scheme not listed in ``allowed_protocols`` are removed
744+
745+
:arg svg_attr_val_allows_ref: set of SVG attributes that can have
746+
references
747+
748+
:arg svg_allow_local_href: set of SVG elements that can have local
749+
hrefs--these are removed
750+
751+
"""
721752
super(Filter, self).__init__(source)
722753
self.allowed_elements = allowed_elements
723754
self.allowed_attributes = allowed_attributes
@@ -737,11 +768,11 @@ def __iter__(self):
737768
yield token
738769

739770
# Sanitize the +html+, escaping all elements not in ALLOWED_ELEMENTS, and
740-
# stripping out all # attributes not in ALLOWED_ATTRIBUTES. Style
741-
# attributes are parsed, and a restricted set, # specified by
742-
# ALLOWED_CSS_PROPERTIES and ALLOWED_CSS_KEYWORDS, are allowed through.
743-
# attributes in ATTR_VAL_IS_URI are scanned, and only URI schemes specified
744-
# in ALLOWED_PROTOCOLS are allowed.
771+
# stripping out all attributes not in ALLOWED_ATTRIBUTES. Style attributes
772+
# are parsed, and a restricted set, specified by ALLOWED_CSS_PROPERTIES and
773+
# ALLOWED_CSS_KEYWORDS, are allowed through. attributes in ATTR_VAL_IS_URI
774+
# are scanned, and only URI schemes specified in ALLOWED_PROTOCOLS are
775+
# allowed.
745776
#
746777
# sanitize_html('<script> do_nasty_stuff() </script>')
747778
# => &lt;script> do_nasty_stuff() &lt;/script>

html5lib/filters/whitespace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class Filter(base.Filter):
13-
13+
"""Collapses whitespace except in pre, textarea, and script elements"""
1414
spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
1515

1616
def __iter__(self):

0 commit comments

Comments
 (0)