(data: str)
| 102 | |
| 103 | |
| 104 | def tokenize(data: str) -> Iterable[Token]: |
| 105 | token: Token = Text("") |
| 106 | |
| 107 | i = 0 |
| 108 | |
| 109 | def readuntil(char, start, include=1): |
| 110 | nonlocal i |
| 111 | end = data.find(char, start) |
| 112 | if end == -1: |
| 113 | end = len(data) |
| 114 | ret = data[i : end + include] |
| 115 | i = end + include |
| 116 | return ret |
| 117 | |
| 118 | while i < len(data): |
| 119 | if isinstance(token, Text): |
| 120 | token.data = readuntil("<", i, 0) |
| 121 | if token.text: |
| 122 | yield token |
| 123 | token = Tag("") |
| 124 | elif isinstance(token, Tag): |
| 125 | token.data += readuntil(">", i, 1) |
| 126 | if token.done: |
| 127 | yield token |
| 128 | token = Text("") |
| 129 | if token.data.strip(): |
| 130 | yield token |
| 131 | |
| 132 | |
| 133 | def indent_text(data: str, prefix: str) -> str: |
searching dependent graphs…