Formatter class for HTML documentation.
| 642 | repr_unicode = repr_string |
| 643 | |
| 644 | class HTMLDoc(Doc): |
| 645 | """Formatter class for HTML documentation.""" |
| 646 | |
| 647 | # ------------------------------------------- HTML formatting utilities |
| 648 | |
| 649 | _repr_instance = HTMLRepr() |
| 650 | repr = _repr_instance.repr |
| 651 | escape = _repr_instance.escape |
| 652 | |
| 653 | def page(self, title, contents): |
| 654 | """Format an HTML page.""" |
| 655 | return '''\ |
| 656 | <!DOCTYPE html> |
| 657 | <html lang="en"> |
| 658 | <head> |
| 659 | <meta charset="utf-8"> |
| 660 | <title>Python: %s</title> |
| 661 | </head><body> |
| 662 | %s |
| 663 | </body></html>''' % (title, contents) |
| 664 | |
| 665 | def heading(self, title, extras=''): |
| 666 | """Format a page heading.""" |
| 667 | return ''' |
| 668 | <table class="heading"> |
| 669 | <tr class="heading-text decor"> |
| 670 | <td class="title"> <br>%s</td> |
| 671 | <td class="extra">%s</td></tr></table> |
| 672 | ''' % (title, extras or ' ') |
| 673 | |
| 674 | def section(self, title, cls, contents, width=6, |
| 675 | prelude='', marginalia=None, gap=' '): |
| 676 | """Format a section with a heading.""" |
| 677 | if marginalia is None: |
| 678 | marginalia = '<span class="code">' + ' ' * width + '</span>' |
| 679 | result = '''<p> |
| 680 | <table class="section"> |
| 681 | <tr class="decor %s-decor heading-text"> |
| 682 | <td class="section-title" colspan=3> <br>%s</td></tr> |
| 683 | ''' % (cls, title) |
| 684 | if prelude: |
| 685 | result = result + ''' |
| 686 | <tr><td class="decor %s-decor" rowspan=2>%s</td> |
| 687 | <td class="decor %s-decor" colspan=2>%s</td></tr> |
| 688 | <tr><td>%s</td>''' % (cls, marginalia, cls, prelude, gap) |
| 689 | else: |
| 690 | result = result + ''' |
| 691 | <tr><td class="decor %s-decor">%s</td><td>%s</td>''' % (cls, marginalia, gap) |
| 692 | |
| 693 | return result + '\n<td class="singlecolumn">%s</td></tr></table>' % contents |
| 694 | |
| 695 | def bigsection(self, title, *args): |
| 696 | """Format a section with a big heading.""" |
| 697 | title = '<strong class="bigsection">%s</strong>' % title |
| 698 | return self.section(title, *args) |
| 699 | |
| 700 | def preformat(self, text): |
| 701 | """Format literal preformatted text.""" |