From 7201eecc09b51df5a0fb704670aa66bcc9d8e635 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 14 Feb 2021 15:34:04 -0500 Subject: 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] --- bs4/formatter.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'bs4/formatter.py') diff --git a/bs4/formatter.py b/bs4/formatter.py index 9a692ec..82d4689 100644 --- a/bs4/formatter.py +++ b/bs4/formatter.py @@ -14,7 +14,8 @@ class Formatter(EntitySubstitution): For HTML documents: * 'html' - HTML entity substitution for generic HTML documents. (default) - * 'html5' - HTML entity substitution for HTML5 documents. + * 'html5' - HTML entity substitution for HTML5 documents, as + well as some optimizations in the way tags are rendered. * 'minimal' - Only make the substitutions necessary to guarantee valid HTML. * None - Do not perform any substitution. This will be faster @@ -48,6 +49,7 @@ class Formatter(EntitySubstitution): def __init__( self, language=None, entity_substitution=None, void_element_close_prefix='/', cdata_containing_tags=None, + empty_attributes_are_booleans=False, ): """Constructor. @@ -64,6 +66,9 @@ class Formatter(EntitySubstitution): as containing CDATA in this dialect. For example, in HTML,