Skip to content

Commit e2d7332

Browse files
committed
finish
1 parent efa7934 commit e2d7332

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

Doc/whatsnew/3.15.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ Improved modules
297297
calendar
298298
--------
299299

300-
* The calendar pages generated by the :class:`calendar.HTMLCalendar` class now
301-
use the HTML5 standard.
302-
(Contributed by Jiahao Li in :gh:`137634`.)
300+
* Calendar pages generated by the :class:`calendar.HTMLCalendar` class now support
301+
dark mode and have been migrated to the HTML5 standard for improved accessibility.
302+
(Contributed by Jiahao Li and Hugo van Kemenade in :gh:`137634`.)
303303

304304

305305
collections
@@ -329,7 +329,6 @@ collections.abc
329329
previously emitted if it was merely imported or accessed from the
330330
:mod:`!collections.abc` module.
331331

332-
333332
dbm
334333
---
335334

Lib/calendar.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
588588
a(f'<meta charset="{encoding}">\n')
589589
a('<meta name="viewport" content="width=device-width, initial-scale=1">\n')
590590
a(f'<title>Calendar for {theyear}</title>\n')
591+
a('<style>\n')
592+
a(':root { color-scheme: light dark; }\n')
593+
a('table.year { border: solid; }\n')
594+
a('table.year > tbody > tr > td { border: solid; vertical-align: top; }\n')
595+
a('</style>\n')
591596
if css is not None:
592597
a(f'<link rel="stylesheet" href="{css}">\n')
593598
a('</head>\n')

Lib/test/test_calendar.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,20 @@
113113

114114
default_format = dict(year="year", month="month", encoding="ascii")
115115

116+
result_2004_css = """<style>
117+
:root { color-scheme: light dark; }
118+
table.year { border: solid; }
119+
table.year > tbody > tr > td { border: solid; vertical-align: top; }
120+
</style>"""
121+
116122
result_2004_html = """\
117123
<!DOCTYPE html>
118124
<html lang="en">
119125
<head>
120126
<meta charset="{encoding}">
121127
<meta name="viewport" content="width=device-width, initial-scale=1">
122128
<title>Calendar for 2004</title>
129+
{css_styles}
123130
<link rel="stylesheet" href="calendar.css">
124131
</head>
125132
<body>
@@ -385,10 +392,12 @@ def check_htmlcalendar_encoding(self, req, res):
385392
cal = calendar.HTMLCalendar()
386393
format_ = default_format.copy()
387394
format_["encoding"] = req or 'utf-8'
395+
format_with_css = {**format_, "css_styles": result_2004_css}
396+
formatted_html = result_2004_html.format(**format_with_css)
388397
output = cal.formatyearpage(2004, encoding=req)
389398
self.assertEqual(
390399
output,
391-
result_2004_html.format(**format_).encode(res)
400+
formatted_html.encode(res)
392401
)
393402

394403
def test_output(self):
@@ -1196,7 +1205,9 @@ def test_html_output_current_year(self):
11961205
def test_html_output_year_encoding(self):
11971206
for run in self.runners:
11981207
output = run('-t', 'html', '--encoding', 'ascii', '2004')
1199-
self.assertEqual(output, result_2004_html.format(**default_format).encode('ascii'))
1208+
format_with_css = default_format.copy()
1209+
format_with_css["css_styles"] = result_2004_css
1210+
self.assertEqual(output, result_2004_html.format(**format_with_css).encode('ascii'))
12001211

12011212
def test_html_output_year_css(self):
12021213
self.assertFailure('-t', 'html', '-c')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
The calendar pages generated by the :class:`calendar.HTMLCalendar` class now
2-
use the HTML5 standard.
1+
Calendar pages generated by the :class:`calendar.HTMLCalendar` class now support
2+
dark mode and have been migrated to the HTML5 standard for improved accessibility.

0 commit comments

Comments
 (0)