Skip to content

gh-63866: Add the "htmlcharrefreplace" error handler - #155223

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-63866-htmlcharrefreplace
Open

gh-63866: Add the "htmlcharrefreplace" error handler#155223
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-63866-htmlcharrefreplace

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Add html.htmlcharrefreplace_errors() which implements the htmlcharrefreplace error handler: an unencodable character is replaced with the corresponding HTML named character reference, or with a numeric character reference if there is no name for it. It is almost the same as the xmlcharrefreplace error handler, but the result is more human-readable.

It is not registered as an error handler by default, you should register it with codecs.register_error().

There are several third-party implementations of this, and some of them are buggy, so a standard implementation will help users.

Add html.htmlcharrefreplace_errors() which replaces an unencodable
character with the corresponding HTML named character reference, or with
a numeric character reference if there is no name for it.  It is not
registered as an error handler by default.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@serhiy-storchaka serhiy-storchaka added stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement labels Aug 5, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33922329 | 📁 Comparing 821dffc against main (7aec160)

  🔍 Preview build  

2 files changed
± library/html.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant