diff options
author | Leonard Richardson <leonardr@segfault.org> | 2021-02-14 15:34:04 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2021-02-14 15:34:04 -0500 |
commit | 7201eecc09b51df5a0fb704670aa66bcc9d8e635 (patch) | |
tree | 30dd9d9df4d81eff431a53f5c47093934b06dfd1 /doc | |
parent | c876fbf402f15d924b7c0d9a9be5ba80769444a3 (diff) |
The 'html5' formatter now treats attributes whose values are the
empty string as HTML boolean attributes. Previously (and in other
formatters), an attribute value must be set as None to be treated as
a boolean attribute. In a future release, I plan to also give this
behavior to the 'html' formatter. Patch by Isaac Muse. [bug=1915424]
Diffstat (limited to 'doc')
-rw-r--r-- | doc/source/index.rst | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst index 8a1a2d5..2b5843d 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -2299,7 +2299,7 @@ Unicode characters to HTML entities whenever possible:: # Il a dit <<Sacré bleu!>> # </p> -If you pass in ``formatter="html5"``, it's the same as +If you pass in ``formatter="html5"``, it's similar to ``formatter="html"``, but Beautiful Soup will omit the closing slash in HTML void tags like "br":: @@ -2310,7 +2310,17 @@ omit the closing slash in HTML void tags like "br":: print(br.encode(formatter="html5")) # b'<br>' + +In addition, any attributes whose values are the empty string +will become HTML-style boolean attributes: + + option = BeautifulSoup('<option selected=""></option>').option + print(option.encode(formatter="html")) + # b'<option selected=""></option>' + print(option.encode(formatter="html5")) + # b'<option selected></option>' + If you pass in ``formatter=None``, Beautiful Soup will not modify strings at all on output. This is the fastest option, but it may lead to Beautiful Soup generating invalid HTML/XML, as in these examples:: |