Skip to content

Commit

Permalink
Move serializer.htmlserializer to serializer
Browse files Browse the repository at this point in the history
The directory has long been pretty redundant, so let's just kill it.
  • Loading branch information
gsnedders committed Jul 13, 2016
1 parent 7bbde54 commit 6c30d0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
23 changes: 15 additions & 8 deletions html5lib/serializer/htmlserializer.py → html5lib/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from codecs import register_error, xmlcharrefreplace_errors

from ..constants import voidElements, booleanAttributes, spaceCharacters
from ..constants import rcdataElements, entities, xmlEntities
from .. import utils
from .constants import voidElements, booleanAttributes, spaceCharacters
from .constants import rcdataElements, entities, xmlEntities
from . import treewalkers, utils
from xml.sax.saxutils import escape

spaceCharacters = "".join(spaceCharacters)
Expand Down Expand Up @@ -73,6 +73,13 @@ def htmlentityreplace_errors(exc):
register_error("htmlentityreplace", htmlentityreplace_errors)


def serialize(input, tree="etree", encoding=None, **serializer_opts):
# XXX: Should we cache this?
walker = treewalkers.getTreeWalker(tree)
s = HTMLSerializer(**serializer_opts)
return s.render(walker(input), encoding)


class HTMLSerializer(object):

# attribute quoting options
Expand Down Expand Up @@ -181,24 +188,24 @@ def serialize(self, treewalker, encoding=None):
self.errors = []

if encoding and self.inject_meta_charset:
from ..filters.inject_meta_charset import Filter
from .filters.inject_meta_charset import Filter
treewalker = Filter(treewalker, encoding)
# Alphabetical attributes is here under the assumption that none of
# the later filters add or change order of attributes; it needs to be
# before the sanitizer so escaped elements come out correctly
if self.alphabetical_attributes:
from ..filters.alphabeticalattributes import Filter
from .filters.alphabeticalattributes import Filter
treewalker = Filter(treewalker)
# WhitespaceFilter should be used before OptionalTagFilter
# for maximum efficiently of this latter filter
if self.strip_whitespace:
from ..filters.whitespace import Filter
from .filters.whitespace import Filter
treewalker = Filter(treewalker)
if self.sanitize:
from ..filters.sanitizer import Filter
from .filters.sanitizer import Filter
treewalker = Filter(treewalker)
if self.omit_optional_tags:
from ..filters.optionaltags import Filter
from .filters.optionaltags import Filter
treewalker = Filter(treewalker)

for token in treewalker:
Expand Down
16 changes: 0 additions & 16 deletions html5lib/serializer/__init__.py

This file was deleted.

0 comments on commit 6c30d0b

Please sign in to comment.