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)
| 799 | return self.__str__(encoding, True) |
| 800 | |
| 801 | def renderContents(self, encoding=DEFAULT_OUTPUT_ENCODING, |
| 802 | prettyPrint=False, indentLevel=0): |
| 803 | """Renders the contents of this tag as a string in the given |
| 804 | encoding. If encoding is None, returns a Unicode string..""" |
| 805 | s=[] |
| 806 | for c in self: |
| 807 | text = None |
| 808 | if isinstance(c, NavigableString): |
| 809 | text = c.__str__(encoding) |
| 810 | elif isinstance(c, Tag): |
| 811 | s.append(c.__str__(encoding, prettyPrint, indentLevel)) |
| 812 | if text and prettyPrint: |
| 813 | text = text.strip() |
| 814 | if text: |
| 815 | if prettyPrint: |
| 816 | s.append(" " * (indentLevel-1)) |
| 817 | s.append(text) |
| 818 | if prettyPrint: |
| 819 | s.append("\n") |
| 820 | return ''.join(s) |
| 821 | |
| 822 | #Soup methods |
| 823 |