Formatter class for HTML documentation.
| 597 | repr_unicode = repr_string |
| 598 | |
| 599 | class HTMLDoc(Doc): |
| 600 | """Formatter class for HTML documentation.""" |
| 601 | |
| 602 | # ------------------------------------------- HTML formatting utilities |
| 603 | |
| 604 | _repr_instance = HTMLRepr() |
| 605 | repr = _repr_instance.repr |
| 606 | escape = _repr_instance.escape |
| 607 | |
| 608 | def page(self, title, contents): |
| 609 | """Format an HTML page.""" |
| 610 | return '''\ |
| 611 | <!DOCTYPE html> |
| 612 | <html lang="en"> |
| 613 | <head> |
| 614 | <meta charset="utf-8"> |
| 615 | <title>Python: %s</title> |
| 616 | </head><body> |
| 617 | %s |
| 618 | </body></html>''' % (title, contents) |
| 619 | |
| 620 | def heading(self, title, extras=''): |
| 621 | """Format a page heading.""" |
| 622 | return ''' |
| 623 | <table class="heading"> |
| 624 | <tr class="heading-text decor"> |
| 625 | <td class="title"> <br>%s</td> |
| 626 | <td class="extra">%s</td></tr></table> |
| 627 | ''' % (title, extras or ' ') |
| 628 | |
| 629 | def section(self, title, cls, contents, width=6, |
| 630 | prelude='', marginalia=None, gap=' '): |
| 631 | """Format a section with a heading.""" |
| 632 | if marginalia is None: |
| 633 | marginalia = '<span class="code">' + ' ' * width + '</span>' |
| 634 | result = '''<p> |
| 635 | <table class="section"> |
| 636 | <tr class="decor %s-decor heading-text"> |
| 637 | <td class="section-title" colspan=3> <br>%s</td></tr> |
| 638 | ''' % (cls, title) |
| 639 | if prelude: |
| 640 | result = result + ''' |
| 641 | <tr><td class="decor %s-decor" rowspan=2>%s</td> |
| 642 | <td class="decor %s-decor" colspan=2>%s</td></tr> |
| 643 | <tr><td>%s</td>''' % (cls, marginalia, cls, prelude, gap) |
| 644 | else: |
| 645 | result = result + ''' |
| 646 | <tr><td class="decor %s-decor">%s</td><td>%s</td>''' % (cls, marginalia, gap) |
| 647 | |
| 648 | return result + '\n<td class="singlecolumn">%s</td></tr></table>' % contents |
| 649 | |
| 650 | def bigsection(self, title, *args): |
| 651 | """Format a section with a big heading.""" |
| 652 | title = '<strong class="bigsection">%s</strong>' % title |
| 653 | return self.section(title, *args) |
| 654 | |
| 655 | def preformat(self, text): |
| 656 | """Format literal preformatted text.""" |