# Example usages:
#
# filters:
#   xhtml2html.plugin?quote_attr_values=True&quote_char="'"
#
# -- or --
#
# [xhtml2html.plugin]
# quote_attr_values=True
# quote_char="'"

import sys
opts = {}
for name,value in zip(sys.argv[1::2],sys.argv[2::2]):
  name = name.lstrip('-')
  try:    opts[name] = eval(value)
  except: opts[name] = value

try:
  from xml.dom import minidom
  doc = minidom.parse(sys.stdin)
except:
  from html5lib import liberalxmlparser, treebuilders
  parser = liberalxmlparser.XHTMLParser(tree=treebuilders.getTreeBuilder('dom'))
  doc = parser.parse(sys.stdin, encoding='utf-8')

from html5lib import treewalkers, serializer
tokens = treewalkers.getTreeWalker('dom')(doc)
serializer = serializer.HTMLSerializer(**dict(opts))
for text in serializer.serialize(tokens, encoding='utf-8'):
    sys.stdout.write(text)
