Commits

Pablo Brasero  committed a031a26

replaceWith() should respect text content

  • Participants
  • Parent commits b418f6c

Comments (0)

Files changed (2)

File pyquery/pyquery.py

     def replaceWith(self, value):
         """replace nodes by value
         """
-        self.before(value)
         for tag in self:
+            self.__class__(tag).before(value + (tag.tail or ''))
             parent = tag.getparent()
             parent.remove(tag)
         return self

File pyquery/test.py

         assert val == ' My link text 2', repr(val)
 
     def test_replaceWith(self):
-        expected = '''
-    <div class="portlet">
+        expected = '''<div class="portlet">
       <a href="/toto">TestimageMy link text</a>
       <a href="/toto2">imageMy link text 2</a>
-    </div>
-        '''
+    </div>'''
         d = pq(self.html)
         d('img').replaceWith('image')
 	val = d.__html__()