Algorithm to identify particular text that should be considered headings in an RST file. See <https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html> for details on what constitutes a string as a heading in RST. Parameters ---------- rst_file : str RST
(rst_file: str)
| 213 | |
| 214 | |
| 215 | def find_titles(rst_file: str) -> Iterable[tuple[str, int]]: |
| 216 | """ |
| 217 | Algorithm to identify particular text that should be considered headings in an |
| 218 | RST file. |
| 219 | |
| 220 | See <https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html> for details |
| 221 | on what constitutes a string as a heading in RST. |
| 222 | |
| 223 | Parameters |
| 224 | ---------- |
| 225 | rst_file : str |
| 226 | RST file to scan through for headings. |
| 227 | |
| 228 | Yields |
| 229 | ------- |
| 230 | title : str |
| 231 | A heading found in the rst file. |
| 232 | |
| 233 | line_number : int |
| 234 | The corresponding line number of the heading. |
| 235 | """ |
| 236 | |
| 237 | with open(rst_file, encoding="utf-8") as fd: |
| 238 | previous_line = "" |
| 239 | for i, line in enumerate(fd): |
| 240 | line_no_last_elem = line[:-1] |
| 241 | line_chars = set(line_no_last_elem) |
| 242 | if ( |
| 243 | len(line_chars) == 1 |
| 244 | and line_chars.pop() in symbols |
| 245 | and len(line_no_last_elem) == len(previous_line) |
| 246 | ): |
| 247 | yield re.sub(r"[`\*_]", "", previous_line), i |
| 248 | previous_line = line_no_last_elem |
| 249 | |
| 250 | |
| 251 | def main(source_paths: list[str]) -> int: |