diff -r 67e542fc0f81 MoinMoin/converter/text_html_text_moin_wiki.py
--- a/MoinMoin/converter/text_html_text_moin_wiki.py	Tue Mar 02 21:17:25 2010 +0300
+++ b/MoinMoin/converter/text_html_text_moin_wiki.py	Tue Mar 02 20:36:13 2010 +0100
@@ -17,7 +17,10 @@
 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
 interwiki_re = re.compile(WikiParser.interwiki_rule, re.VERBOSE|re.UNICODE)
 
-
+try:
+    import tidylib
+except ImportError:
+    tidylib = None
 # Portions (C) International Organization for Standardization 1986
 # Permission to copy in any form is granted for use with
 # conforming SGML systems and applications as defined in
@@ -1435,6 +1438,13 @@
     # Due to expat needing explicitly set namespaces, we set these here to allow pasting
     # from Word / Excel without issues.
     # If you encounter 'ExpatError: unbound prefix', try adding the namespace to the list.
+    if tidylib:
+        text, errors = tidylib.tidy_fragment(text,
+                                             options={'numeric-entities': 1,
+                                             'indent': 0,
+                                             'wrap': 0,
+                                             'output-xhtml': 1})
+
     namespace = [u'xmlns:o="urn:schemas-microsoft-com:office:office"',
                  u'xmlns:x="urn:schemas-microsoft-com:office:excel"',
                  u'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"',
