| 21 | |
| 22 | |
| 23 | class ReSTDocument: |
| 24 | def __init__(self, target='man'): |
| 25 | self.style = ReSTStyle(self) |
| 26 | self.target = target |
| 27 | self.parser = DocStringParser(self) |
| 28 | self.keep_data = True |
| 29 | self.do_translation = False |
| 30 | self.translation_map = {} |
| 31 | self.hrefs = {} |
| 32 | self._writes = [] |
| 33 | self._last_doc_string = None |
| 34 | |
| 35 | def _write(self, s): |
| 36 | if self.keep_data and s is not None: |
| 37 | self._writes.append(s) |
| 38 | |
| 39 | def write(self, content): |
| 40 | """ |
| 41 | Write content into the document. |
| 42 | """ |
| 43 | self._write(content) |
| 44 | |
| 45 | def writeln(self, content): |
| 46 | """ |
| 47 | Write content on a newline. |
| 48 | """ |
| 49 | self._write('%s%s\n' % (self.style.spaces(), content)) |
| 50 | |
| 51 | def peek_write(self): |
| 52 | """ |
| 53 | Returns the last content written to the document without |
| 54 | removing it from the stack. |
| 55 | """ |
| 56 | return self._writes[-1] |
| 57 | |
| 58 | def pop_write(self): |
| 59 | """ |
| 60 | Removes and returns the last content written to the stack. |
| 61 | """ |
| 62 | return self._writes.pop() |
| 63 | |
| 64 | def push_write(self, s): |
| 65 | """ |
| 66 | Places new content on the stack. |
| 67 | """ |
| 68 | self._writes.append(s) |
| 69 | |
| 70 | def find_last_write(self, content): |
| 71 | """ |
| 72 | Returns the index of the last occurrence of the content argument |
| 73 | in the stack, or returns None if content is not on the stack. |
| 74 | """ |
| 75 | try: |
| 76 | return len(self._writes) - self._writes[::-1].index(content) - 1 |
| 77 | except ValueError: |
| 78 | return None |
| 79 | |
| 80 | def insert_write(self, index, content): |
no outgoing calls