GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-137634: Modernizing `calendar.HTMLCalendar` for HTML Output by Wulian233 · Pull Request #137635 · python/cpython

Conversation

@Wulian233

@Wulian233 Wulian233 commented Aug 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

We don't need to worry about css overwriting the user's css in dark mode, I moved the to the bottom of style, and users can override them according to css priority

Removed cellpadding="0" cellspacing="0" they are deprecated:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/cellPadding
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/cellSpacing

CC: @hugovk

  • Issue: Modernizing calendar.HTMLCalendar for HTML Output #137634

📚 Documentation preview 📚: https://cpython-previews--137635.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Wulian233
Modernizing calendar.HTMLCalendar for HTML Output
5ce8a9a
@Wulian233
Wulian233 requested a review from AA-Turner as a code owner August 11, 2025 06:57
@bedevere-app bedevere-app Bot added the awaiting review label Aug 11, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Aug 11, 2025
Modernizing calendar.HTMLCalendar for HTML Output #137634
Closed
@serhiy-storchaka

serhiy-storchaka commented Aug 11, 2025

Copy link
Copy Markdown
Member

What problem does this solve? This PR changes the default theme to dark and hardcodes some colors -- what is the reason? Could not you just use a custom stylesheet?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Wulian233
polish
1848640
@Wulian233

Wulian233 commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

We provide basic dark mode support for the HTML generated by module. In 3.14 and 3.15 we've already added this feature for http.server and difflib

In this case, the loading order ensures that calendar.css takes precedence over the styles defined in the <style> , allowing users to override properties like background-color in their calendar.css.

Regarding @media (prefers-color-scheme: dark), this doesn't dark mode by default, the browser will automatically switch based on the system settings

The hardcoded colors could potentially be changed, but this would make the code longer

:root {
  --background-color-dark: #121212;
  --text-color-dark: #e0e0e0;
  --border-color-dark: #444;
}
@media (prefers-color-scheme: dark) {
  body { background-color: var(--background-color-dark); color: var(--text-color-dark); }
  table.year, table.month, td, th { border-color: var(--border-color-dark); }
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Aug 13, 2025

Copy link
Copy Markdown
Member

I do not think we should hardcode any colors. This will simply lead to problems in the future when custom stylesheets becomes dependent on these values and they will be changed again.

This also makes the HTML code longer.

If you need calendar in dark mode, just create a custom stylesheet.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Wulian233
remove darkmode
e365fe1
@hugovk

hugovk commented Oct 9, 2025

Copy link
Copy Markdown
Member

Thanks for the PR, it's looking better.

Before

image

Lighthouse:

image

PR

image image

More ideas

  • vertically align the months
  • add borders
table.year {
  border: solid;
}
table.year > tbody > tr > td {
  border: solid;
  vertical-align: top;
}
image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Wulian233

Wulian233 commented Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Thank you for the suggestion. I will add them this weekend. Also, do you think it should support dark mode? 👀

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Oct 9, 2025

Copy link
Copy Markdown
Member

I think dark mode would be useful, but can it be done without hardcoding colours?

Compare https://github.com/python/cpython/pull/123475/files

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Wulian233 added 2 commits October 11, 2025 20:00
@Wulian233
Merge branch 'main' into calendar-html
efa7934
@Wulian233
finish
e2d7332
hugovk
hugovk approved these changes Oct 14, 2025
View reviewed changes

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Oct 14, 2025
@hugovk
hugovk merged commit 5976432 into python:main Oct 14, 2025
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 14, 2025
@Wulian233
Wulian233 deleted the calendar-html branch October 14, 2025 10:52
@sakgoyal

sakgoyal commented Nov 5, 2025

Copy link
Copy Markdown

should light mode take precedent here?
I think most people would agree that a white flash is worse than a dark flash.

Would it be better to switch to { color-scheme: dark light; } instead of { color-scheme: light dark; }?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Nov 5, 2025

Copy link
Copy Markdown
Member

Searching GitHub:

  • color-scheme: dark light - 6.1k files - https://github.com/search?q=%22color-scheme%3A+dark+light%22&ref=opensearch&type=code
  • color-scheme: light dark - 241k files - https://github.com/search?q=%22color-scheme%3A+light+dark%22&ref=opensearch&type=code

I don't notice any flash, but it's with a local http.server.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@hugovk hugovk hugovk approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Wulian233 @serhiy-storchaka @hugovk @sakgoyal
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.