summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2023-01-29 10:37:49 -0500
committerLeonard Richardson <leonardr@segfault.org>2023-01-29 10:37:49 -0500
commit0cdcc79fb1332d6f7ac2b085ec654adfef50ac86 (patch)
tree3ab16017e9fc88aa34a3afede5718d9f448383b3 /doc
parentbd3c7492d81440597d2a82cf6265bb68b53f1b84 (diff)
Reworded the 'multi-valued attributes' portion of the documentation to make it more clear. [bug=1970767]
Diffstat (limited to 'doc')
-rw-r--r--doc/source/index.rst13
1 files changed, 7 insertions, 6 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 7288024..007e75f 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -366,8 +366,8 @@ HTML 4 defines a few attributes that can have multiple values. HTML 5
removes a couple of them, but defines a few more. The most common
multi-valued attribute is ``class`` (that is, a tag can have more than
one CSS class). Others include ``rel``, ``rev``, ``accept-charset``,
-``headers``, and ``accesskey``. Beautiful Soup presents the value(s)
-of a multi-valued attribute as a list::
+``headers``, and ``accesskey``. By default, Beautiful Soup parses the value(s)
+of a multi-valued attribute into a list::
css_soup = BeautifulSoup('<p class="body"></p>', 'html.parser')
css_soup.p['class']
@@ -388,15 +388,16 @@ standard, Beautiful Soup will leave the attribute alone::
When you turn a tag back into a string, multiple attribute values are
consolidated::
- rel_soup = BeautifulSoup('<p>Back to the <a rel="index">homepage</a></p>', 'html.parser')
+ rel_soup = BeautifulSoup('<p>Back to the <a rel="index first">homepage</a></p>', 'html.parser')
rel_soup.a['rel']
- # ['index']
+ # ['index', 'first']
rel_soup.a['rel'] = ['index', 'contents']
print(rel_soup.p)
# <p>Back to the <a rel="index contents">homepage</a></p>
-You can disable this by passing ``multi_valued_attributes=None`` as a
-keyword argument into the ``BeautifulSoup`` constructor::
+You can force all attributes to be parsed as strings by passing
+``multi_valued_attributes=None`` as a keyword argument into the
+``BeautifulSoup`` constructor::
no_list_soup = BeautifulSoup('<p class="body strikeout"></p>', 'html.parser', multi_valued_attributes=None)
no_list_soup.p['class']