Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Doc/library/html.parser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Comment on lines +137 to +138
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean attributes can also be written as disabled=disabled or even disabled="". When the value is absent, this is called empty attribute. This is syntax, not semantic.

Suggested change
have been replaced. If a boolean attribute is encountered, the *value* for the
``(name, value)`` attribute pair will be ``None``.
have been replaced. For empty attributes, *value* is ``None``.


For instance, for the tag ``<A HREF="https://www.cwi.nl/">``, this method
would be called as ``handle_starttag('a', [('href', 'https://www.cwi.nl/')])``.
Expand Down Expand Up @@ -310,6 +311,16 @@ further parsing:
Data : alert("<strong>hello!</strong>");
End tag : script

Boolean attributes have a *value* of ``None``:

.. doctest::

>>> parser.feed("<script src='/script.js' defer></script>")
Start tag: script
attr: ('src', '/script.js')
attr: ('defer', None)
End tag : script

Parsing comments:

.. doctest::
Expand Down
Loading