Parse a document title as the first line starting in [A-Za-z0-9<$] or fall back to the document basename if no such line exists. The cmake --help-*-list commands also depend on this convention. Return the title or False if the document file does not exist.
(self, docname)
| 245 | self.titles = {} |
| 246 | |
| 247 | def parse_title(self, docname): |
| 248 | """Parse a document title as the first line starting in [A-Za-z0-9<$] |
| 249 | or fall back to the document basename if no such line exists. |
| 250 | The cmake --help-*-list commands also depend on this convention. |
| 251 | Return the title or False if the document file does not exist. |
| 252 | """ |
| 253 | settings = self.document.settings |
| 254 | env = settings.env |
| 255 | title = self.titles.get(docname) |
| 256 | if title is None: |
| 257 | fname = os.path.join(env.srcdir, docname+'.rst') |
| 258 | try: |
| 259 | f = open(fname, 'r', encoding=settings.input_encoding) |
| 260 | except IOError: |
| 261 | title = False |
| 262 | else: |
| 263 | for line in f: |
| 264 | if len(line) > 0 and (line[0].isalnum() or |
| 265 | line[0] == '<' or line[0] == '$'): |
| 266 | title = line.rstrip() |
| 267 | break |
| 268 | f.close() |
| 269 | if title is None: |
| 270 | title = os.path.basename(docname) |
| 271 | self.titles[docname] = title |
| 272 | return title |
| 273 | |
| 274 | def apply(self): |
| 275 | env = self.document.settings.env |