Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 32 lines (28 sloc) 0.831 kB
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
1 # Example usages:
2 #
3 # filters:
4 # xhtml2html.plugin?quote_attr_values=True&quote_char="'"
5 #
6 # -- or --
7 #
8 # [xhtml2html.plugin]
9 # quote_attr_values=True
10 # quote_char="'"
11
12 import sys
1e2b6a1 @rubys Recover from 'eval' errors
authored
13 opts = {}
14 for name,value in zip(sys.argv[1::2],sys.argv[2::2]):
15 name = name.lstrip('-')
16 try: opts[name] = eval(value)
17 except: opts[name] = value
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
18
4912d60 @rubys HTML5 and Chrome fixes
authored
19 try:
20 from xml.dom import minidom
21 doc = minidom.parse(sys.stdin)
22 except:
23 from html5lib import liberalxmlparser, treebuilders
24 parser = liberalxmlparser.XHTMLParser(tree=treebuilders.getTreeBuilder('dom'))
25 doc = parser.parse(sys.stdin, encoding='utf-8')
26
27 from html5lib import treewalkers, serializer
28 tokens = treewalkers.getTreeWalker('dom')(doc)
4b1e0da @rubys filters/xhtml2html =~ s/Genshi/html5lib/
authored
29 serializer = serializer.HTMLSerializer(**dict(opts))
30 for text in serializer.serialize(tokens, encoding='utf-8'):
31 sys.stdout.write(text)
Something went wrong with that request. Please try again.