@@ -382,12 +382,31 @@ class HTMLCalendar(Calendar):
382382 # CSS classes for the day <td>s
383383 cssclasses = ["mon" , "tue" , "wed" , "thu" , "fri" , "sat" , "sun" ]
384384
385+ # CSS classes for the day <th>s
386+ cssclasses_weekday_head = cssclasses
387+
388+ # CSS class for the days before and after current month
389+ cssclass_noday = "noday"
390+
391+ # CSS class for the month's head
392+ cssclass_month_head = "month"
393+
394+ # CSS class for the month
395+ cssclass_month = "month"
396+
397+ # CSS class for the year's table head
398+ cssclass_year_head = "year"
399+
400+ # CSS class for the whole year table
401+ cssclass_year = "year"
402+
385403 def formatday (self , day , weekday ):
386404 """
387405 Return a day as a table cell.
388406 """
389407 if day == 0 :
390- return '<td class="noday"> </td>' # day outside month
408+ # day outside month
409+ return '<td class="%s"> </td>' % self .cssclass_noday
391410 else :
392411 return '<td class="%s">%d</td>' % (self .cssclasses [weekday ], day )
393412
@@ -402,7 +421,8 @@ def formatweekday(self, day):
402421 """
403422 Return a weekday name as a table header.
404423 """
405- return '<th class="%s">%s</th>' % (self .cssclasses [day ], day_abbr [day ])
424+ return '<th class="%s">%s</th>' % (
425+ self .cssclasses_weekday_head [day ], day_abbr [day ])
406426
407427 def formatweekheader (self ):
408428 """
@@ -419,15 +439,17 @@ def formatmonthname(self, theyear, themonth, withyear=True):
419439 s = '%s %s' % (month_name [themonth ], theyear )
420440 else :
421441 s = '%s' % month_name [themonth ]
422- return '<tr><th colspan="7" class="month">%s</th></tr>' % s
442+ return '<tr><th colspan="7" class="%s">%s</th></tr>' % (
443+ self .cssclass_month_head , s )
423444
424445 def formatmonth (self , theyear , themonth , withyear = True ):
425446 """
426447 Return a formatted month as a table.
427448 """
428449 v = []
429450 a = v .append
430- a ('<table border="0" cellpadding="0" cellspacing="0" class="month">' )
451+ a ('<table border="0" cellpadding="0" cellspacing="0" class="%s">' % (
452+ self .cssclass_month ))
431453 a ('\n ' )
432454 a (self .formatmonthname (theyear , themonth , withyear = withyear ))
433455 a ('\n ' )
@@ -447,9 +469,11 @@ def formatyear(self, theyear, width=3):
447469 v = []
448470 a = v .append
449471 width = max (width , 1 )
450- a ('<table border="0" cellpadding="0" cellspacing="0" class="year">' )
472+ a ('<table border="0" cellpadding="0" cellspacing="0" class="%s">' %
473+ self .cssclass_year )
451474 a ('\n ' )
452- a ('<tr><th colspan="%d" class="year">%s</th></tr>' % (width , theyear ))
475+ a ('<tr><th colspan="%d" class="%s">%s</th></tr>' % (
476+ width , self .cssclass_year_head , theyear ))
453477 for i in range (January , January + 12 , width ):
454478 # months in this row
455479 months = range (i , min (i + width , 13 ))
0 commit comments