summaryrefslogtreecommitdiff
path: root/doc/source/index.rst
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source/index.rst')
-rw-r--r--doc/source/index.rst18
1 files changed, 16 insertions, 2 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst
index ef60c24..0e049d1 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1894,11 +1894,24 @@ 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.
+``wrap()``
+----------
+
+``PageElement.wrap()`` wraps an element in the tag you specify. It
+returns the new wrapper. (New in Beautiful Soup 4.0.5.)
+
+ soup = BeautifulSoup("<p>I wish I was bold.</p>")
+ soup.p.string.wrap(soup.new_tag("b"))
+ # <b>I wish I was bold.</b>
+
+ soup.p.wrap(soup.new_tag("div")
+ # <div><p><b>I wish I was bold.</b></p></div>
+
``unwrap()``
---------------------------
-``Tag.unwrap()`` replaces a tag with whatever's inside
-that tag. It's good for stripping out markup::
+``Tag.unwrap()`` is the opposite of ``wrap()``. It 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)
@@ -1911,6 +1924,7 @@ that tag. It's good for stripping out markup::
Like ``replace_with()``, ``unwrap()`` returns the tag
that was replaced.
+
Output
======