8000 Added support for <meta http-equiv="Content-Type" content="..."> in i… · awesome-python/html5lib-python@0dbe154 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0dbe154

Browse files
committed
Added support for <meta http-equiv="Content-Type" content="..."> in inject_meta_charset filter (Python only) along with a few tests.
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40782
1 parent d9f6172 commit 0dbe154

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/filters/inject_meta_charset.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ def __iter__(self):
1818

1919
elif type == "EmptyTag":
2020
if token["name"].lower() == "meta":
21-
# replace charset with actual encoding
22-
for i,(name,value) in enumerate(token["data"]):
23-
if name == 'charset':
24-
token["data"][i] = (token["data"][i][0], self.encoding)
25-
meta_found = True
21+
# replace charset with actual encoding
22+
has_http_equiv_content_type = False
23+
content_index = -1
24+
for i,(name,value) in enumerate(token["data"]):
25+
if name.lower() == 'charset':
26+
token["data"][i] = (u'charset', self.encoding)
27+
meta_found = True
28+
break
29+
elif name == 'http-equiv' and value.lower() == 'content-type':
30+
has_http_equiv_content_type = True
31+
elif name == 'content':
32+
content_index = i
33+
else:
34+
if has_http_equiv_content_type and content_index >= 0:
35+
token["data"][content_index] = (u'content', u'text/html; charset=%s' % self.encoding)
36+
meta_found = True
2637

2738
elif token["name"].lower() == "head" and not meta_found:
2839
# insert meta into empty head

0 commit comments

Comments
 (0)
0