From c100eb5bd54ea86c0c4ba3cc6e8978538e0a2fb4 Mon Sep 17 00:00:00 2001 From: Fearless-Badger Date: Tue, 20 May 2025 10:11:08 -0400 Subject: [PATCH] Specify bool attribute behavior in HTML parser --- Doc/library/html.parser.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index dd67fc34e856f1..c814c1627a13f0 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -134,7 +134,8 @@ implementations do nothing (except for :meth:`~HTMLParser.handle_startendtag`): argument is a list of ``(name, value)`` pairs containing the attributes found inside the tag's ``<>`` brackets. The *name* will be translated to lower case, and quotes in the *value* have been removed, and character and entity references - have been replaced. + have been replaced. If a boolean attribute is encountered, the *value* for the + ``(name, value)`` attribute pair will be ``None``. For instance, for the tag ````, this method would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``. @@ -310,6 +311,16 @@ further parsing: Data : alert("hello!"); End tag : script +Boolean attributes have a *value* of ``None``: + +.. doctest:: + + >>> parser.feed("") + Start tag: script + attr: ('src', '/script.js') + attr: ('defer', None) + End tag : script + Parsing comments: .. doctest::