diff options
-rw-r--r-- | NEWS.txt | 3 | ||||
-rw-r--r-- | bs4/element.py | 5 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 8 | ||||
-rw-r--r-- | doc/source/index.rst | 10 |
4 files changed, 15 insertions, 11 deletions
@@ -1,5 +1,8 @@ = 4.0.5 (unreleased) = +* Renamed replace_with_children() to unwrap(), which is easier to + understand and also the jQuery name of the function. + * Made encoding substitution in <meta> tags completely transparent (no more %SOUP-ENCODING%). diff --git a/bs4/element.py b/bs4/element.py index c1ad992..eb7e8aa 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -150,14 +150,15 @@ class PageElement(object): return self replaceWith = replace_with # BS3 - def replace_with_children(self): + def unwrap(self): my_parent = self.parent my_index = self.parent.index(self) self.extract() for child in reversed(self.contents[:]): my_parent.insert(my_index, child) return self - replaceWithChildren = replace_with_children # BS3 + replace_with_children = unwrap + replaceWithChildren = unwrap # BS3 def extract(self): """Destructively rips this element out of the tree.""" diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 2dea886..867fdaa 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -712,11 +712,11 @@ class TestTreeModification(SoupTest): new_a = a.replace_with(soup.c) self.assertEqual(a, new_a) - def test_replace_with_children_returns_thing_that_was_replaced(self): + def test_unwrap_returns_thing_that_was_replaced(self): text = "<a><b></b><c></c></a>" soup = self.soup(text) a = soup.a - new_a = a.replace_with_children() + new_a = a.unwrap() self.assertEqual(a, new_a) def test_replace_tag_with_itself(self): @@ -918,11 +918,11 @@ class TestTreeModification(SoupTest): self.assertEqual(g_tag.previous_element, to_text) self.assertEqual(g_tag.previous_sibling, to_text) - def test_replace_with_children(self): + def test_unwrap(self): tree = self.soup(""" <p>Unneeded <em>formatting</em> is unneeded</p> """) - tree.em.replace_with_children() + tree.em.unwrap() self.assertEqual(tree.em, None) self.assertEqual(tree.p.text, "Unneeded formatting is unneeded") diff --git a/doc/source/index.rst b/doc/source/index.rst index 17d2211..ef60c24 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -1894,21 +1894,21 @@ and replaces it with the tag or string of your choice:: ``replace_with()`` returns the tag or string that was replaced, so that you can examine it or add it back to another part of the tree. -``replace_with_children()`` +``unwrap()`` --------------------------- -``Tag.replace_with_children()`` replaces a tag with whatever's inside +``Tag.unwrap()`` replaces a tag with whatever's inside that tag. It's good for stripping out markup:: markup = '<a href="http://example.com/">I linked to <i>example.com</i></a>' soup = BeautifulSoup(markup) a_tag = soup.a - a_tag.i.replace_with_children() + a_tag.i.unwrap() a_tag # <a href="http://example.com/">I linked to example.com</a> -Like ``replace_with()``, ``replace_with_children()`` returns the tag +Like ``replace_with()``, ``unwrap()`` returns the tag that was replaced. Output @@ -2696,7 +2696,7 @@ Method names * ``renderContents`` -> ``encode_contents`` * ``replaceWith`` -> ``replace_with`` -* ``replaceWithChildren`` -> ``replace_with_children`` +* ``replaceWithChildren`` -> ``unwrap`` * ``findAll`` -> ``find_all`` * ``findAllNext`` -> ``find_all_next`` * ``findAllPrevious`` -> ``find_all_previous`` |