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)
| 160 | self.titles = {} |
| 161 | |
| 162 | def parse_title(self, docname): |
| 163 | """Parse a document title as the first line starting in [A-Za-z0-9<] |
| 164 | or fall back to the document basename if no such line exists. |
| 165 | The cmake --help-*-list commands also depend on this convention. |
| 166 | Return the title or False if the document file does not exist. |
| 167 | """ |
| 168 | env = self.document.settings.env |
| 169 | title = self.titles.get(docname) |
| 170 | if title is None: |
| 171 | fname = os.path.join(env.srcdir, docname+'.rst') |
| 172 | try: |
| 173 | f = open(fname, 'r') |
| 174 | except IOError: |
| 175 | title = False |
| 176 | else: |
| 177 | for line in f: |
| 178 | if len(line) > 0 and (line[0].isalnum() or line[0] == '<'): |
| 179 | title = line.rstrip() |
| 180 | break |
| 181 | f.close() |
| 182 | if title is None: |
| 183 | title = os.path.basename(docname) |
| 184 | self.titles[docname] = title |
| 185 | return title |
| 186 | |
| 187 | def apply(self): |
| 188 | env = self.document.settings.env |