summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2012-04-26 23:29:32 -0400
committerLeonard Richardson <leonard.richardson@canonical.com>2012-04-26 23:29:32 -0400
commit77fd198a9e76c7d517db189f7f9e0779394a35f6 (patch)
tree8970ea86557a731292ed612cc7ab9c9fe55c8d60 /doc
parent019d782bc435a0b9f420fb3612c7d3ecebe66751 (diff)
downloadbeautifulsoup4-77fd198a9e76c7d517db189f7f9e0779394a35f6.tar.gz
Added a new method, wrap().
Diffstat (limited to 'doc')
-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
======