Skip to content
This repository was archived by the owner on Dec 17, 2022. It is now read-only.

Commit bdd66c5

Browse files
committed
Add Tag.replaceWithChildren
1 parent 31d54c6 commit bdd66c5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

BeautifulSoup.py

+9
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ def replaceWith(self, replaceWith):
137137
self.extract()
138138
oldParent.insert(myIndex, replaceWith)
139139

140+
def replaceWithChildren(self):
141+
myParent = self.parent
142+
myIndex = self.parent.index(self)
143+
self.extract()
144+
reversedChildren = list(self.contents)
145+
reversedChildren.reverse()
146+
for child in reversedChildren:
147+
myParent.insert(myIndex, child)
148+
140149
def extract(self):
141150
"""Destructively rips this element out of the tree."""
142151
if self.parent:

0 commit comments

Comments
 (0)