summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
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()``::