diff options
author | Leonard Richardson <leonardr@segfault.org> | 2023-01-29 10:37:49 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2023-01-29 10:37:49 -0500 |
commit | 0cdcc79fb1332d6f7ac2b085ec654adfef50ac86 (patch) | |
tree | 3ab16017e9fc88aa34a3afede5718d9f448383b3 | |
parent | bd3c7492d81440597d2a82cf6265bb68b53f1b84 (diff) |
Reworded the 'multi-valued attributes' portion of the documentation to make it more clear. [bug=1970767]
-rw-r--r-- | bs4/tests/test_soup.py | 2 | ||||
-rw-r--r-- | doc/source/index.rst | 13 |
2 files changed, 8 insertions, 7 deletions
diff --git a/bs4/tests/test_soup.py b/bs4/tests/test_soup.py index 00587d4..857f1f4 100644 --- a/bs4/tests/test_soup.py +++ b/bs4/tests/test_soup.py @@ -139,7 +139,7 @@ class TestConstructor(SoupTest): assert " an id " == a['id'] assert ["a", "class"] == a['class'] - # TreeBuilder takes an argument called 'mutli_valued_attributes' which lets + # TreeBuilder takes an argument called 'multi_valued_attributes' which lets # you customize or disable this. As always, you can customize the TreeBuilder # by passing in a keyword argument to the BeautifulSoup constructor. soup = self.soup(markup, builder=default_builder, multi_valued_attributes=None) 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'] |