Render help.html into a text widget. The overridden handle_xyz methods handle a subset of html tags. The supplied text should have the needed tag configurations. The behavior for unsupported tags, such as table, is undefined. If the tags generated by Sphinx change, this class, espec
| 46 | ## IDLE Help ## |
| 47 | |
| 48 | class HelpParser(HTMLParser): |
| 49 | """Render help.html into a text widget. |
| 50 | |
| 51 | The overridden handle_xyz methods handle a subset of html tags. |
| 52 | The supplied text should have the needed tag configurations. |
| 53 | The behavior for unsupported tags, such as table, is undefined. |
| 54 | If the tags generated by Sphinx change, this class, especially |
| 55 | the handle_starttag and handle_endtags methods, might have to also. |
| 56 | """ |
| 57 | def __init__(self, text): |
| 58 | HTMLParser.__init__(self, convert_charrefs=True) |
| 59 | self.text = text # Text widget we're rendering into. |
| 60 | self.tags = '' # Current block level text tags to apply. |
| 61 | self.chartags = '' # Current character level text tags. |
| 62 | self.hdrlink = False # Exclude html header links. |
| 63 | self.level = 0 # Track indentation level. |
| 64 | self.pre = False # Displaying preformatted text? |
| 65 | self.hprefix = '' # Heading prefix (like '25.5'?) to remove. |
| 66 | self.nested_dl = False # In a nested <dl>? |
| 67 | self.simplelist = False # In a simple list (no double spacing)? |
| 68 | self.toc = [] # Pair headers with text indexes for toc. |
| 69 | self.header = '' # Text within header tags for toc. |
| 70 | self.prevtag = None # Previous tag info (opener?, tag). |
| 71 | |
| 72 | def indent(self, amt=1): |
| 73 | "Change indent (+1, 0, -1) and tags." |
| 74 | self.level += amt |
| 75 | self.tags = '' if self.level == 0 else 'l'+str(self.level) |
| 76 | |
| 77 | def handle_starttag(self, tag, attrs): |
| 78 | "Handle starttags in help.html." |
| 79 | class_ = '' |
| 80 | for a, v in attrs: |
| 81 | if a == 'class': |
| 82 | class_ = v |
| 83 | s = '' |
| 84 | if tag == 'p' and self.prevtag and not self.prevtag[0]: |
| 85 | # Begin a new block for <p> tags after a closed tag. |
| 86 | # Avoid extra lines, e.g. after <pre> tags. |
| 87 | lastline = self.text.get('end-1c linestart', 'end-1c') |
| 88 | s = '\n\n' if lastline and not lastline.isspace() else '\n' |
| 89 | elif tag == 'span' and class_ == 'pre': |
| 90 | self.chartags = 'pre' |
| 91 | elif tag == 'span' and class_ == 'versionmodified': |
| 92 | self.chartags = 'em' |
| 93 | elif tag == 'em': |
| 94 | self.chartags = 'em' |
| 95 | elif tag in ['ul', 'ol']: |
| 96 | if class_.find('simple') != -1: |
| 97 | s = '\n' |
| 98 | self.simplelist = True |
| 99 | else: |
| 100 | self.simplelist = False |
| 101 | self.indent() |
| 102 | elif tag == 'dl': |
| 103 | if self.level > 0: |
| 104 | self.nested_dl = True |
| 105 | elif tag == 'li': |
no outgoing calls
no test coverage detected
searching dependent graphs…