summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2013-05-20 10:20:40 -0400
committerLeonard Richardson <leonardr@segfault.org>2013-05-20 10:20:40 -0400
commit8645d5e6b61804a5614b65db00312863189fb198 (patch)
treed96743599b70ae29656ef6215eb824142b04a75f /doc
parent2099c8ca203772514908d148b8002d4214d11637 (diff)
downloadbeautifulsoup4-8645d5e6b61804a5614b65db00312863189fb198.tar.gz
Gave new_string() the ability to create subclasses of
NavigableString. [bug=1181986]
Diffstat (limited to 'doc')
-rw-r--r--doc/source/index.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst
index e254855..a91854c 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -1806,6 +1806,20 @@ Python string in to ``append()``, or you can call the factory method
tag.contents
# [u'Hello', u' there']
+If you want to create a comment or some other subclass of
+``NavigableString``, pass that class as the second argument to
+``new_string()``::
+
+ from bs4 import Comment
+ new_comment = soup.new_string("Nice to see you.", Comment)
+ tag.append(new_comment)
+ tag
+ # <b>Hello there<!--Nice to see you.--></b>
+ tag.contents
+ # [u'Hello', u' there', u'Nice to see you.']
+
+(This is a new feature in Beautiful Soup 4.2.1.)
+
What if you need to create a whole new tag? The best solution is to
call the factory method ``BeautifulSoup.new_tag()``::