REF: io/formats/html.py (and io/formats/format.py)
- [ n/a] follow-on #24637
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ n/a] whatsnew entry

this refactor further limits responsibilities of functions/module and should allow a simpler implementation for fixes of #17004, #9690 etc.