| 692 | self.elementstack[-1][2].append(text) |
| 693 | |
| 694 | def handle_entityref(self, ref): |
| 695 | # called for each entity reference, e.g. for '©', ref will be 'copy' |
| 696 | if not self.elementstack: return |
| 697 | if _debug: sys.stderr.write('entering handle_entityref with %s\n' % ref) |
| 698 | if ref in ('lt', 'gt', 'quot', 'amp', 'apos'): |
| 699 | text = '&%s;' % ref |
| 700 | elif ref in self.entities.keys(): |
| 701 | text = self.entities[ref] |
| 702 | if text.startswith('&#') and text.endswith(';'): |
| 703 | return self.handle_entityref(text) |
| 704 | else: |
| 705 | try: name2codepoint[ref] |
| 706 | except KeyError: text = '&%s;' % ref |
| 707 | else: text = unichr(name2codepoint[ref]).encode('utf-8') |
| 708 | self.elementstack[-1][2].append(text) |
| 709 | |
| 710 | def handle_data(self, text, escape=1): |
| 711 | # called for each block of plain text, i.e. outside of any tag and |