Parse a Markdown document into an `ElementTree`. Given a list of lines, an `ElementTree` object (not just a parent `Element`) is created and the root element is passed to the parser as the parent. The `ElementTree` object is returned. This should only be called on
(self, lines: Iterable[str])
| 98 | self.md = md |
| 99 | |
| 100 | def parseDocument(self, lines: Iterable[str]) -> etree.ElementTree: |
| 101 | """ Parse a Markdown document into an `ElementTree`. |
| 102 | |
| 103 | Given a list of lines, an `ElementTree` object (not just a parent |
| 104 | `Element`) is created and the root element is passed to the parser |
| 105 | as the parent. The `ElementTree` object is returned. |
| 106 | |
| 107 | This should only be called on an entire document, not pieces. |
| 108 | |
| 109 | Arguments: |
| 110 | lines: A list of lines (strings). |
| 111 | |
| 112 | Returns: |
| 113 | An element tree. |
| 114 | """ |
| 115 | # Create an `ElementTree` from the lines |
| 116 | self.root = etree.Element(self.md.doc_tag) |
| 117 | self.parseChunk(self.root, '\n'.join(lines)) |
| 118 | return etree.ElementTree(self.root) |
| 119 | |
| 120 | def parseChunk(self, parent: etree.Element, text: str) -> None: |
| 121 | """ Parse a chunk of Markdown text and attach to given `etree` node. |