Renders the contents of this tag as a string in the given encoding. If encoding is None, returns a Unicode string..
(self, encoding=DEFAULT_OUTPUT_ENCODING,
prettyPrint=False, indentLevel=0)
| 816 | return self.__str__(encoding, True) |
| 817 | |
| 818 | def renderContents(self, encoding=DEFAULT_OUTPUT_ENCODING, |
| 819 | prettyPrint=False, indentLevel=0): |
| 820 | """Renders the contents of this tag as a string in the given |
| 821 | encoding. If encoding is None, returns a Unicode string..""" |
| 822 | s=[] |
| 823 | for c in self: |
| 824 | text = None |
| 825 | if isinstance(c, NavigableString): |
| 826 | text = c.__str__(encoding) |
| 827 | elif isinstance(c, Tag): |
| 828 | s.append(c.__str__(encoding, prettyPrint, indentLevel)) |
| 829 | if text and prettyPrint: |
| 830 | text = text.strip() |
| 831 | if text: |
| 832 | if prettyPrint: |
| 833 | s.append(" " * (indentLevel-1)) |
| 834 | s.append(text) |
| 835 | if prettyPrint: |
| 836 | s.append("\n") |
| 837 | |
| 838 | return ''.join(s) |
| 839 | |
| 840 | #Soup methods |
| 841 |