Commits

Luke Plant committed 42fa8cb

Implemented issue #31 - remove hard spaces in clean routine.

  • Participants
  • Parent commits 3e2d71f

Comments (0)

Files changed (2)

semanticeditor/tests.py

                               '<p id="p_1">test</p><p>test 2</p>' +
                               '<ul id="ul_1">test</ul><ul>test 2</ul>')
 
+    def test_remove_hard_spaces(self):
+        # &nbsp;
+        self.assertEqualClean('<p>&nbsp;Hello&nbsp;</p>',
+                              '<p> Hello </p>')
+        # &#160;
+        self.assertEqualClean('<p>&#160;Hello&#160;</p>',
+                              '<p> Hello </p>')
+
+        # Some unicode
+        self.assertEqualClean(u'<p>&nbsp;Frappé&nbsp;</p>',
+                              u'<p> Frapp&#233; </p>')

semanticeditor/utils/presentation.py

 
     return (pres, out_html)
 
+def _clean_text(t):
+    return t.replace(u'\xa0', u' ')
+
 def _clean_elem(d):
     for x in ['style', 'class']:
         try:
             d.removeAttr(x)
         except KeyError:
             pass
+    for elem in d:
+        if elem.text is not None:
+            elem.text = _clean_text(elem.text)
+        if elem.tail is not None:
+            elem.tail = _clean_text(elem.tail)
 
 def _empty_text(x):
     return x is None or x.strip() == ""