Skip to content

Commit f28ec34

Browse files
authored
gh-82927: Update files related to HTML entities. (GH-92504)
1 parent 4e08fbc commit f28ec34

File tree

6 files changed

+29
-78
lines changed

6 files changed

+29
-78
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Python/pythonrun.c @iritkatriel
5353
/Lib/html/ @ezio-melotti
5454
/Lib/_markupbase.py @ezio-melotti
5555
/Lib/test/test_html*.py @ezio-melotti
56+
/Tools/scripts/*html5* @ezio-melotti
5657

5758
# Import (including importlib).
5859
# Ignoring importlib.h so as to not get flagged on

Doc/library/html.entities.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ This module defines four dictionaries, :data:`html5`,
3434

3535
.. data:: name2codepoint
3636

37-
A dictionary that maps HTML entity names to the Unicode code points.
37+
A dictionary that maps HTML4 entity names to the Unicode code points.
3838

3939

4040
.. data:: codepoint2name
4141

42-
A dictionary that maps Unicode code points to HTML entity names.
42+
A dictionary that maps Unicode code points to HTML4 entity names.
4343

4444

4545
.. rubric:: Footnotes

Lib/html/entities.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
__all__ = ['html5', 'name2codepoint', 'codepoint2name', 'entitydefs']
44

55

6-
# maps the HTML entity name to the Unicode code point
7-
# from https://html.spec.whatwg.org/multipage/named-characters.html
6+
# maps HTML4 entity name to the Unicode code point
87
name2codepoint = {
98
'AElig': 0x00c6, # latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
109
'Aacute': 0x00c1, # latin capital letter A with acute, U+00C1 ISOlat1
@@ -261,7 +260,11 @@
261260
}
262261

263262

264-
# maps the HTML5 named character references to the equivalent Unicode character(s)
263+
# HTML5 named character references
264+
# Generated by 'Tools/scripts/parse_html5_entities.py'
265+
# from https://html.spec.whatwg.org/entities.json and
266+
# https://html.spec.whatwg.org/multipage/named-characters.html.
267+
# Map HTML5 named character references to the equivalent Unicode character(s).
265268
html5 = {
266269
'Aacute': '\xc1',
267270
'aacute': '\xe1',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``Tools/scripts/parseentities.py`` script used to parse HTML4 entities
2+
has been removed.

Tools/scripts/parse_html5_entities.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
"""
33
Utility for parsing HTML5 entity definitions available from:
44
5-
http://dev.w3.org/html5/spec/entities.json
5+
https://html.spec.whatwg.org/entities.json
6+
https://html.spec.whatwg.org/multipage/named-characters.html
67
7-
Written by Ezio Melotti and Iuliia Proskurnia.
8+
The page now contains the following note:
9+
10+
"This list is static and will not be expanded or changed in the future."
811
12+
Written by Ezio Melotti and Iuliia Proskurnia.
913
"""
1014

1115
import os
@@ -14,7 +18,9 @@
1418
from urllib.request import urlopen
1519
from html.entities import html5
1620

17-
entities_url = 'http://dev.w3.org/html5/spec/entities.json'
21+
PAGE_URL = 'https://html.spec.whatwg.org/multipage/named-characters.html'
22+
ENTITIES_URL = 'https://html.spec.whatwg.org/entities.json'
23+
HTML5_SECTION_START = '# HTML5 named character references'
1824

1925
def get_json(url):
2026
"""Download the json file from the url and returns a decoded object."""
@@ -62,29 +68,32 @@ def write_items(entities, file=sys.stdout):
6268
# be before their equivalent lowercase version.
6369
keys = sorted(entities.keys())
6470
keys = sorted(keys, key=str.lower)
71+
print(HTML5_SECTION_START, file=file)
72+
print(f'# Generated by {sys.argv[0]!r}\n'
73+
f'# from {ENTITIES_URL} and\n'
74+
f'# {PAGE_URL}.\n'
75+
f'# Map HTML5 named character references to the '
76+
f'equivalent Unicode character(s).', file=file)
6577
print('html5 = {', file=file)
6678
for name in keys:
67-
print(' {!r}: {!a},'.format(name, entities[name]), file=file)
79+
print(f' {name!r}: {entities[name]!a},', file=file)
6880
print('}', file=file)
6981

7082

7183
if __name__ == '__main__':
7284
# without args print a diff between html.entities.html5 and new_html5
7385
# with --create print the new html5 dict
7486
# with --patch patch the Lib/html/entities.py file
75-
new_html5 = create_dict(get_json(entities_url))
87+
new_html5 = create_dict(get_json(ENTITIES_URL))
7688
if '--create' in sys.argv:
77-
print('# map the HTML5 named character references to the '
78-
'equivalent Unicode character(s)')
79-
print('# Generated by {}. Do not edit manually.'.format(__file__))
8089
write_items(new_html5)
8190
elif '--patch' in sys.argv:
8291
fname = 'Lib/html/entities.py'
8392
temp_fname = fname + '.temp'
8493
with open(fname) as f1, open(temp_fname, 'w') as f2:
8594
skip = False
8695
for line in f1:
87-
if line.startswith('html5 = {'):
96+
if line.startswith(HTML5_SECTION_START):
8897
write_items(new_html5, file=f2)
8998
skip = True
9099
continue

Tools/scripts/parseentities.py

-64
This file was deleted.

0 commit comments

Comments
 (0)