From ddf9d04e42168fdb25b742b35efc891789a4b6c9 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Fri, 18 Feb 2011 11:09:59 -0500 Subject: Have the html5lib builder set the sniffed encoding after parsing, rather than before as happens with lxml. --- beautifulsoup/builder/html5lib_builder.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'beautifulsoup/builder/html5lib_builder.py') diff --git a/beautifulsoup/builder/html5lib_builder.py b/beautifulsoup/builder/html5lib_builder.py index dc95493..a5aaa01 100644 --- a/beautifulsoup/builder/html5lib_builder.py +++ b/beautifulsoup/builder/html5lib_builder.py @@ -18,6 +18,9 @@ class HTML5TreeBuilder(HTMLTreeBuilder): parser = html5lib.HTMLParser(tree=self.create_treebuilder) doc = parser.parse(markup) + # Set the character encoding detected by the tokenizer. + doc.originalEncoding = parser.tokenizer.stream.charEncoding[0] + def create_treebuilder(self, namespaceHTMLElements): self.underlying_builder = TreeBuilderForHtml5lib( self.soup, namespaceHTMLElements) -- cgit v1.2.3